sensorfw
abstractsensor_i.h
Go to the documentation of this file.
1 
29 #ifndef ABSTRACTSENSOR_I_H
30 #define ABSTRACTSENSOR_I_H
31 
32 #include <QtDBus/QtDBus>
33 #include <QList>
34 #include <QVector>
35 #include <QString>
36 
37 #include "sfwerror.h"
38 #include "serviceinfo.h"
39 #include "socketreader.h"
40 #include "datatypes/datarange.h"
41 
45 class AbstractSensorChannelInterface : public QObject
46 {
47  Q_OBJECT
48  Q_DISABLE_COPY(AbstractSensorChannelInterface)
49  Q_PROPERTY(int sessionId READ sessionId)
50  Q_PROPERTY(SensorError errorCode READ errorCode)
51  Q_PROPERTY(QString errorString READ errorString)
52  Q_PROPERTY(QString description READ description)
53  Q_PROPERTY(QString id READ id)
54  Q_PROPERTY(int interval READ interval WRITE setInterval)
55  Q_PROPERTY(bool standbyOverride READ standbyOverride WRITE setStandbyOverride)
56  Q_PROPERTY(QString type READ type)
57  Q_PROPERTY(unsigned int bufferInterval READ bufferInterval WRITE setBufferInterval)
58  Q_PROPERTY(unsigned int bufferSize READ bufferSize WRITE setBufferSize)
59  Q_PROPERTY(bool hwBuffering READ hwBuffering)
60  Q_PROPERTY(bool downsampling READ downsampling WRITE setDownsampling)
61 
62 public:
63 
68 
75  bool release();
76 
82  int sessionId() const;
83 
90 
96  QString errorString();
97 
103  QString description();
104 
110  QString id();
111 
119  int interval();
120 
128  void setInterval(int value);
129 
138 
147  bool setStandbyOverride(bool override);
148 
155  unsigned int bufferInterval();
156 
164  void setBufferInterval(unsigned int value);
165 
173  bool downsampling();
174 
184  bool setDownsampling(bool value);
185 
192 
199  unsigned int bufferSize();
200 
207  void setBufferSize(unsigned int value);
208 
216 
222  QString type();
223 
230  virtual QDBusReply<void> start();
231 
237  virtual QDBusReply<void> stop();
238 
245 
252 
259 
267 
272 
280  bool setDataRangeIndex(int dataRangeIndex);
281 
287  bool hwBuffering();
288 
295  bool isValid() const;
296 
297 private:
304  void setError(SensorError errorCode, const QString& errorString);
305 
309  void clearError();
310 
314  SocketReader& getSocketReader() const;
315 
316 private Q_SLOTS: // METHODS
317 
318  void displayStateChanged(bool displayState);
319 
327  QDBusReply<void> setInterval(int sessionId, int value);
328 
336  QDBusReply<bool> setStandbyOverride(int sessionId, bool value);
337 
345  QDBusReply<void> setBufferInterval(int sessionId, unsigned int value);
346 
354  QDBusReply<void> setBufferSize(int sessionId, unsigned int value);
355 
363  QDBusReply<void> setDownsampling(int sessionId, bool value);
364 
371  QDBusReply<void> start(int sessionId);
372 
379  QDBusReply<void> stop(int sessionId);
380 
384  void dataReceived();
385 
386 protected:
394  AbstractSensorChannelInterface(const QString& path, const char* interfaceName, int sessionId);
395 
402  bool read(void* buffer, int size);
403 
411  template<typename T>
412  bool read(QVector<T>& values);
413 
420  virtual bool dataReceivedImpl() = 0;
421 
430  template<typename T>
431  T getAccessor(const char* name);
432 
441  template<typename T>
442  void setAccessor(const char* name, const T& value);
443 
448  QDBusMessage call(QDBus::CallMode mode,
449  const QString& method,
450  const QVariant& arg1 = QVariant(),
451  const QVariant& arg2 = QVariant(),
452  const QVariant& arg3 = QVariant(),
453  const QVariant& arg4 = QVariant(),
454  const QVariant& arg5 = QVariant(),
455  const QVariant& arg6 = QVariant(),
456  const QVariant& arg7 = QVariant(),
457  const QVariant& arg8 = QVariant());
458 
463  QDBusMessage callWithArgumentList(QDBus::CallMode mode, const QString& method, const QList<QVariant>& args);
464 
469  void dbusConnectNotify(const QMetaMethod& signal);
470 protected slots:
471  void startFinished(QDBusPendingCallWatcher *watch);
472  void stopFinished(QDBusPendingCallWatcher *watch);
473 
474  void setIntervalFinished(QDBusPendingCallWatcher *watch);
475  void setBufferIntervalFinished(QDBusPendingCallWatcher *watch);
476  void setBufferSizeFinished(QDBusPendingCallWatcher *watch);
477  void setStandbyOverrideFinished(QDBusPendingCallWatcher *watch);
478  void setDownsamplingFinished(QDBusPendingCallWatcher *watch);
479  void setDataRangeIndexFinished(QDBusPendingCallWatcher *watch);
480 
481 
482 private:
483  struct AbstractSensorChannelInterfaceImpl;
484 
485  AbstractSensorChannelInterfaceImpl* pimpl_;
486 };
487 
488 template<typename T>
489 bool AbstractSensorChannelInterface::read(QVector<T>& values)
490 {
491  return getSocketReader().read(values);
492 }
493 
494 template<typename T>
496 {
497  QDBusReply<T> reply(call(QDBus::Block, QLatin1String(name)));
498  if(!reply.isValid())
499  {
500  qDebug() << "Failed to get '" << name << "' from sensord: " << reply.error().message();
501  return T();
502  }
503  return reply.value();
504 }
505 
506 template<typename T>
507 void AbstractSensorChannelInterface::setAccessor(const char* name, const T& value)
508 {
509  QDBusReply<void> reply(call(QDBus::NoBlock, QLatin1String(name), qVariantFromValue(value)));
510  if(!reply.isValid())
511  {
512  qDebug() << "Failed to set '" << name << " = " << value << "' to sensord: " << reply.error().message();
513  }
514 }
515 
516 namespace local {
517  typedef ::AbstractSensorChannelInterface AbstractSensor;
518 }
519 
520 #endif
AbstractSensorChannelInterface::release
bool release()
Release the sensor instance.
AbstractSensorChannelInterface::getAvailableBufferSizes
IntegerRangeList getAvailableBufferSizes()
Returns list of available buffer sizes.
AbstractSensorChannelInterface::callWithArgumentList
QDBusMessage callWithArgumentList(QDBus::CallMode mode, const QString &method, const QList< QVariant > &args)
Wrapper for function of QDBusAbstractInterface.
AbstractSensorChannelInterface::hwBuffering
bool hwBuffering
Definition: abstractsensor_i.h:59
AbstractSensorChannelInterface::bufferSize
unsigned int bufferSize
Definition: abstractsensor_i.h:58
AbstractSensorChannelInterface::setAccessor
void setAccessor(const char *name, const T &value)
Utility for calling DBus methods from current connection which return nothing and take one arg.
Definition: abstractsensor_i.h:507
AbstractSensorChannelInterface::getCurrentDataRange
DataRange getCurrentDataRange()
Get current used data range.
AbstractSensorChannelInterface::type
QString type
Definition: abstractsensor_i.h:56
AbstractSensorChannelInterface::setBufferInterval
void setBufferInterval(unsigned int value)
Set buffer interval.
DataRangeList
QList< DataRange > DataRangeList
Definition: datarange.h:105
AbstractSensorChannelInterface::dataReceivedImpl
virtual bool dataReceivedImpl()=0
Callback for subclasses in which they must read their expected data from socket.
AbstractSensorChannelInterface::id
QString id()
Get ID of the sensor.
AbstractSensorChannelInterface::setStandbyOverrideFinished
void setStandbyOverrideFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::getAccessor
T getAccessor(const char *name)
Utility for calling DBus methods from current connection which return value and take no args.
Definition: abstractsensor_i.h:495
local
Definition: abstractsensor_i.h:516
SocketReader::read
bool read(void *buffer, int size)
Attempt to read given number of bytes from the socket.
AbstractSensorChannelInterface::errorCode
SensorError errorCode
Definition: abstractsensor_i.h:50
AbstractSensorChannelInterface::interval
int interval()
Get used sensor sampling interval (in millisecs).
DataRange
Datatype for storing sensor data range information.
Definition: datarange.h:46
AbstractSensorChannelInterface::sessionId
int sessionId
Definition: abstractsensor_i.h:49
AbstractSensorChannelInterface::getAvailableIntervals
DataRangeList getAvailableIntervals()
Get the list of available intervals ranges for the sensor.
AbstractSensorChannelInterface
Base-class for client facades of different sensor types.
Definition: abstractsensor_i.h:46
AbstractSensorChannelInterface::interval
int interval
Definition: abstractsensor_i.h:54
AbstractSensorChannelInterface::setDownsampling
bool setDownsampling(bool value)
Enable or disable downsampling.
AbstractSensorChannelInterface::startFinished
void startFinished(QDBusPendingCallWatcher *watch)
SensorError
SensorError
Enumeration about sensor error states.
Definition: sfwerror.h:54
AbstractSensorChannelInterface::setBufferIntervalFinished
void setBufferIntervalFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::~AbstractSensorChannelInterface
virtual ~AbstractSensorChannelInterface()
Destructor.
AbstractSensorChannelInterface::hwBuffering
bool hwBuffering()
Does the sensor driver support buffering or not.
AbstractSensorChannelInterface::downsampling
bool downsampling()
Is downsampling enabled or not.
AbstractSensorChannelInterface::start
virtual QDBusReply< void > start()
Start sensor.
AbstractSensorChannelInterface::bufferInterval
unsigned int bufferInterval
Definition: abstractsensor_i.h:57
AbstractSensorChannelInterface::setDataRangeIndex
bool setDataRangeIndex(int dataRangeIndex)
Request data range by using index which points to the list returned by getAvailableDataRanges().
AbstractSensorChannelInterface::stop
virtual QDBusReply< void > stop()
Stop sensor.
AbstractSensorChannelInterface::errorString
QString errorString
Definition: abstractsensor_i.h:51
AbstractSensorChannelInterface::dbusConnectNotify
void dbusConnectNotify(const QMetaMethod &signal)
Wrapper for function of QDBusAbstractInterface.
AbstractSensorChannelInterface::getAvailableDataRanges
DataRangeList getAvailableDataRanges()
Get the list of available data ranges for the sensor.
socketreader.h
SocketReader helper class for sensor interface.
AbstractSensorChannelInterface::setInterval
void setInterval(int value)
Set sensor sampling interval (in millisecs).
AbstractSensorChannelInterface::setBufferSize
void setBufferSize(unsigned int value)
Set buffer size.
IntegerRangeList
QList< IntegerRange > IntegerRangeList
Definition: datarange.h:38
AbstractSensorChannelInterface::standbyOverride
bool standbyOverride
Definition: abstractsensor_i.h:55
datarange.h
Datatype containing sensor data range and resolution.
AbstractSensorChannelInterface::sessionId
int sessionId() const
Get ID of the current session.
serviceinfo.h
Sensor service information.
AbstractSensorChannelInterface::requestDataRange
void requestDataRange(DataRange range)
Request data range.
AbstractSensorChannelInterface::isValid
bool isValid() const
Does the current instance have valid connection established to sensor daemon.
sfwerror.h
Error definitions.
AbstractSensorChannelInterface::downsampling
bool downsampling
Definition: abstractsensor_i.h:60
local::AbstractSensor
::AbstractSensorChannelInterface AbstractSensor
Definition: abstractsensor_i.h:517
AbstractSensorChannelInterface::setIntervalFinished
void setIntervalFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::type
QString type()
Textual description about sensor type.
AbstractSensorChannelInterface::read
bool read(void *buffer, int size)
Read data from socket into buffer.
AbstractSensorChannelInterface::call
QDBusMessage call(QDBus::CallMode mode, const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
Wrapper for function of QDBusAbstractInterface.
AbstractSensorChannelInterface::setBufferSizeFinished
void setBufferSizeFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::bufferInterval
unsigned int bufferInterval()
Used buffer interval.
AbstractSensorChannelInterface::description
QString description
Definition: abstractsensor_i.h:52
AbstractSensorChannelInterface::errorCode
SensorError errorCode()
Get error code of occured local or remote error.
AbstractSensorChannelInterface::stopFinished
void stopFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::bufferSize
unsigned int bufferSize()
Get used buffer size.
AbstractSensorChannelInterface::getAvailableBufferIntervals
IntegerRangeList getAvailableBufferIntervals()
Returns list of available buffer interval ranges.
AbstractSensorChannelInterface::description
QString description()
Get description of the sensor.
AbstractSensorChannelInterface::setDownsamplingFinished
void setDownsamplingFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::AbstractSensorChannelInterface
AbstractSensorChannelInterface(const QString &path, const char *interfaceName, int sessionId)
Constructor.
SocketReader
Helper class for reading socket datachannel from sensord.
Definition: socketreader.h:42
AbstractSensorChannelInterface::setStandbyOverride
bool setStandbyOverride(bool override)
Enable or disable standby-override.
AbstractSensorChannelInterface::removeDataRangeRequest
void removeDataRangeRequest()
Remove set data range request.
AbstractSensorChannelInterface::standbyOverride
bool standbyOverride()
Is standby-override enabled or not.
AbstractSensorChannelInterface::setDataRangeIndexFinished
void setDataRangeIndexFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::errorString
QString errorString()
Get error description of occured local or remote error.