sensorfw: qt-api/abstractsensor_i.h Source File

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
67 virtual ~AbstractSensorChannelInterface();
68
75 bool release();
76
82 int sessionId() const;
83
89 SensorError errorCode();
90
96 QString errorString();
97
103 QString description();
104
110 QString id();
111
119 int interval();
120
128 void setInterval(int value);
129
137 bool standbyOverride();
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
191 IntegerRangeList getAvailableBufferIntervals();
192
199 unsigned int bufferSize();
200
207 void setBufferSize(unsigned int value);
208
215 IntegerRangeList getAvailableBufferSizes();
216
222 QString type();
223
230 virtual QDBusReply<void> start();
231
237 virtual QDBusReply<void> stop();
238
244 DataRangeList getAvailableIntervals();
245
251 DataRangeList getAvailableDataRanges();
252
258 DataRange getCurrentDataRange();
259
266 void requestDataRange(DataRange range);
267
271 void removeDataRangeRequest();
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>
495 T AbstractSensorChannelInterface::getAccessor(const char* name)
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
Base-class for client facades of different sensor types.
Definition: abstractsensor_i.h:46
AbstractSensorChannelInterface::setBufferIntervalFinished
void setBufferIntervalFinished(QDBusPendingCallWatcher *watch)
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::getAvailableDataRanges
DataRangeList getAvailableDataRanges()
Get the list of available data ranges for the sensor.
AbstractSensorChannelInterface::description
QString description
Definition: abstractsensor_i.h:52
AbstractSensorChannelInterface::read
bool read(void *buffer, int size)
Read data from socket into buffer.
AbstractSensorChannelInterface::startFinished
void startFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::isValid
bool isValid() const
Does the current instance have valid connection established to sensor daemon.
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::description
QString description()
Get description of the sensor.
AbstractSensorChannelInterface::standbyOverride
bool standbyOverride
Definition: abstractsensor_i.h:55
AbstractSensorChannelInterface::getAvailableBufferSizes
IntegerRangeList getAvailableBufferSizes()
Returns list of available buffer sizes.
AbstractSensorChannelInterface::standbyOverride
bool standbyOverride()
Is standby-override enabled or not.
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
AbstractSensorChannelInterface::interval
int interval()
Get used sensor sampling interval (in millisecs).
AbstractSensorChannelInterface::setBufferSizeFinished
void setBufferSizeFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::start
virtual QDBusReply< void > start()
Start sensor.
AbstractSensorChannelInterface::setIntervalFinished
void setIntervalFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::bufferSize
unsigned int bufferSize()
Get used buffer size.
AbstractSensorChannelInterface::errorString
QString errorString()
Get error description of occured local or remote error.
AbstractSensorChannelInterface::setBufferInterval
void setBufferInterval(unsigned int value)
Set buffer interval.
AbstractSensorChannelInterface::setBufferSize
void setBufferSize(unsigned int value)
Set buffer size.
AbstractSensorChannelInterface::type
QString type()
Textual description about sensor type.
AbstractSensorChannelInterface::dbusConnectNotify
void dbusConnectNotify(const QMetaMethod &signal)
Wrapper for function of QDBusAbstractInterface.
AbstractSensorChannelInterface::hwBuffering
bool hwBuffering()
Does the sensor driver support buffering or not.
AbstractSensorChannelInterface::downsampling
bool downsampling
Definition: abstractsensor_i.h:60
AbstractSensorChannelInterface::setDownsampling
bool setDownsampling(bool value)
Enable or disable downsampling.
AbstractSensorChannelInterface::getAvailableIntervals
DataRangeList getAvailableIntervals()
Get the list of available intervals ranges for the sensor.
AbstractSensorChannelInterface::~AbstractSensorChannelInterface
virtual ~AbstractSensorChannelInterface()
Destructor.
AbstractSensorChannelInterface::downsampling
bool downsampling()
Is downsampling enabled or not.
AbstractSensorChannelInterface::setDataRangeIndexFinished
void setDataRangeIndexFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::requestDataRange
void requestDataRange(DataRange range)
Request data range.
AbstractSensorChannelInterface::removeDataRangeRequest
void removeDataRangeRequest()
Remove set data range request.
AbstractSensorChannelInterface::bufferInterval
unsigned int bufferInterval()
Used buffer interval.
AbstractSensorChannelInterface::setStandbyOverride
bool setStandbyOverride(bool override)
Enable or disable standby-override.
AbstractSensorChannelInterface::release
bool release()
Release the sensor instance.
AbstractSensorChannelInterface::bufferInterval
unsigned int bufferInterval
Definition: abstractsensor_i.h:57
AbstractSensorChannelInterface::errorString
QString errorString
Definition: abstractsensor_i.h:51
AbstractSensorChannelInterface::getCurrentDataRange
DataRange getCurrentDataRange()
Get current used data range.
AbstractSensorChannelInterface::id
QString id()
Get ID of the sensor.
AbstractSensorChannelInterface::setDataRangeIndex
bool setDataRangeIndex(int dataRangeIndex)
Request data range by using index which points to the list returned by getAvailableDataRanges().
AbstractSensorChannelInterface::stopFinished
void stopFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::bufferSize
unsigned int bufferSize
Definition: abstractsensor_i.h:58
AbstractSensorChannelInterface::sessionId
int sessionId
Definition: abstractsensor_i.h:49
AbstractSensorChannelInterface::sessionId
int sessionId() const
Get ID of the current session.
AbstractSensorChannelInterface::setStandbyOverrideFinished
void setStandbyOverrideFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::getAvailableBufferIntervals
IntegerRangeList getAvailableBufferIntervals()
Returns list of available buffer interval ranges.
AbstractSensorChannelInterface::interval
int interval
Definition: abstractsensor_i.h:54
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::type
QString type
Definition: abstractsensor_i.h:56
AbstractSensorChannelInterface::stop
virtual QDBusReply< void > stop()
Stop sensor.
AbstractSensorChannelInterface::errorCode
SensorError errorCode()
Get error code of occured local or remote error.
AbstractSensorChannelInterface::AbstractSensorChannelInterface
AbstractSensorChannelInterface(const QString &path, const char *interfaceName, int sessionId)
Constructor.
AbstractSensorChannelInterface::setInterval
void setInterval(int value)
Set sensor sampling interval (in millisecs).
AbstractSensorChannelInterface::errorCode
SensorError errorCode
Definition: abstractsensor_i.h:50
AbstractSensorChannelInterface::setDownsamplingFinished
void setDownsamplingFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::dataReceivedImpl
virtual bool dataReceivedImpl()=0
Callback for subclasses in which they must read their expected data from socket.
DataRange
Datatype for storing sensor data range information.
Definition: datarange.h:46
SocketReader
Helper class for reading socket datachannel from sensord.
Definition: socketreader.h:42
SocketReader::read
bool read(void *buffer, int size)
Attempt to read given number of bytes from the socket.
datarange.h
Datatype containing sensor data range and resolution.
IntegerRangeList
QList< IntegerRange > IntegerRangeList
Definition: datarange.h:38
DataRangeList
QList< DataRange > DataRangeList
Definition: datarange.h:105
local
Definition: abstractsensor_i.h:516
local::AbstractSensor
::AbstractSensorChannelInterface AbstractSensor
Definition: abstractsensor_i.h:517
serviceinfo.h
Sensor service information.
sfwerror.h
Error definitions.
SensorError
SensorError
Enumeration about sensor error states.
Definition: sfwerror.h:54
socketreader.h
SocketReader helper class for sensor interface.