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 dataRate READ dataRate WRITE setDataRate)
55 Q_PROPERTY(int interval READ interval WRITE setInterval)
56 Q_PROPERTY(bool standbyOverride READ standbyOverride WRITE setStandbyOverride)
57 Q_PROPERTY(QString type READ type)
58 Q_PROPERTY(unsigned int bufferInterval READ bufferInterval WRITE setBufferInterval)
59 Q_PROPERTY(unsigned int bufferSize READ bufferSize WRITE setBufferSize)
60 Q_PROPERTY(bool hwBuffering READ hwBuffering)
61 Q_PROPERTY(bool downsampling READ downsampling WRITE setDownsampling)
62
63public:
64
68 virtual ~AbstractSensorChannelInterface();
69
76 bool release();
77
83 int sessionId() const;
84
90 SensorError errorCode();
91
97 QString errorString();
98
104 QString description();
105
111 QString id();
112
120 int interval();
121 double dataRate();
122
130 void setInterval(int interval_ms);
131
139 void setDataRate(double dataRate_Hz);
140
148 bool standbyOverride();
149
158 bool setStandbyOverride(bool override);
159
166 unsigned int bufferInterval();
167
175 void setBufferInterval(unsigned int interval_ms);
176
184 bool downsampling();
185
195 bool setDownsampling(bool value);
196
202 IntegerRangeList getAvailableBufferIntervals();
203
210 unsigned int bufferSize();
211
218 void setBufferSize(unsigned int value);
219
226 IntegerRangeList getAvailableBufferSizes();
227
233 QString type();
234
241 virtual QDBusReply<void> start();
242
248 virtual QDBusReply<void> stop();
249
255 DataRangeList getAvailableIntervals();
256
262 DataRangeList getAvailableDataRanges();
263
269 DataRange getCurrentDataRange();
270
277 void requestDataRange(DataRange range);
278
282 void removeDataRangeRequest();
283
291 bool setDataRangeIndex(int dataRangeIndex);
292
298 bool hwBuffering();
299
306 bool isValid() const;
307
308private:
315 void setError(SensorError errorCode, const QString& errorString);
316
320 void clearError();
321
325 SocketReader& getSocketReader() const;
326
327private Q_SLOTS: // METHODS
328
329 void displayStateChanged(bool displayState);
330
338 QDBusReply<void> setInterval(int sessionId, int interval_ms);
339
347 QDBusReply<void> setDataRate(int sessionId, double dataRate_Hz);
348
356 QDBusReply<bool> setStandbyOverride(int sessionId, bool value);
357
365 QDBusReply<void> setBufferInterval(int sessionId, unsigned int interval_ms);
366
374 QDBusReply<void> setBufferSize(int sessionId, unsigned int value);
375
383 QDBusReply<void> setDownsampling(int sessionId, bool value);
384
391 QDBusReply<void> start(int sessionId);
392
399 QDBusReply<void> stop(int sessionId);
400
404 void dataReceived();
405
406protected:
414 AbstractSensorChannelInterface(const QString& path, const char* interfaceName, int sessionId);
415
422 bool read(void* buffer, int size);
423
431 template<typename T>
432 bool read(QVector<T>& values);
433
440 virtual bool dataReceivedImpl() = 0;
441
450 template<typename T>
451 T getAccessor(const char* name);
452
461 template<typename T>
462 void setAccessor(const char* name, const T& value);
463
468 QDBusMessage call(QDBus::CallMode mode,
469 const QString& method,
470 const QVariant& arg1 = QVariant(),
471 const QVariant& arg2 = QVariant(),
472 const QVariant& arg3 = QVariant(),
473 const QVariant& arg4 = QVariant(),
474 const QVariant& arg5 = QVariant(),
475 const QVariant& arg6 = QVariant(),
476 const QVariant& arg7 = QVariant(),
477 const QVariant& arg8 = QVariant());
478
483 QDBusMessage callWithArgumentList(QDBus::CallMode mode, const QString& method, const QList<QVariant>& args);
484
489 void dbusConnectNotify(const QMetaMethod& signal);
490protected slots:
491 void startFinished(QDBusPendingCallWatcher *watch);
492 void stopFinished(QDBusPendingCallWatcher *watch);
493
494 void setIntervalFinished(QDBusPendingCallWatcher *watch);
495 void setDataRateFinished(QDBusPendingCallWatcher *watch);
496 void setBufferIntervalFinished(QDBusPendingCallWatcher *watch);
497 void setBufferSizeFinished(QDBusPendingCallWatcher *watch);
498 void setStandbyOverrideFinished(QDBusPendingCallWatcher *watch);
499 void setDownsamplingFinished(QDBusPendingCallWatcher *watch);
500 void setDataRangeIndexFinished(QDBusPendingCallWatcher *watch);
501
502
503private:
504 struct AbstractSensorChannelInterfaceImpl;
505
506 AbstractSensorChannelInterfaceImpl* pimpl_;
507};
508
509template<typename T>
510 bool AbstractSensorChannelInterface::read(QVector<T>& values)
511{
512 return getSocketReader().read(values);
513}
514
515template<typename T>
516T AbstractSensorChannelInterface::getAccessor(const char* name)
517{
518 QDBusReply<T> reply(call(QDBus::Block, QLatin1String(name)));
519 if(!reply.isValid())
520 {
521 qDebug() << "Failed to get '" << name << "' from sensord: " << reply.error().message();
522 return T();
523 }
524 return reply.value();
525}
526
527template<typename T>
528 void AbstractSensorChannelInterface::setAccessor(const char* name, const T& value)
529{
530 QDBusReply<void> reply(call(QDBus::NoBlock, QLatin1String(name), QVariant::fromValue(value)));
531 if(!reply.isValid())
532 {
533 qDebug() << "Failed to set '" << name << " = " << value << "' to sensord: " << reply.error().message();
534 }
535}
536
537 namespace local {
538 typedef ::AbstractSensorChannelInterface AbstractSensor;
539}
540
541#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:528
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::start
virtual QDBusReply< void > start()
Start sensor.
AbstractSensorChannelInterface::startFinished
void startFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::isValid
bool isValid() const
Does the current instance have valid connection established to sensor daemon.
AbstractSensorChannelInterface::stop
virtual QDBusReply< void > stop()
Stop sensor.
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::dataRate
int dataRate
Definition abstractsensor_i.h:54
AbstractSensorChannelInterface::standbyOverride
bool standbyOverride
Definition abstractsensor_i.h:56
AbstractSensorChannelInterface::getAvailableBufferSizes
IntegerRangeList getAvailableBufferSizes()
Returns list of available buffer sizes.
AbstractSensorChannelInterface::setInterval
void setInterval(int interval_ms)
Set sensor sampling interval (in millisecs).
AbstractSensorChannelInterface::setBufferInterval
void setBufferInterval(unsigned int interval_ms)
Set buffer interval.
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:516
AbstractSensorChannelInterface::setBufferSizeFinished
void setBufferSizeFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::setIntervalFinished
void setIntervalFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::setBufferSize
void setBufferSize(unsigned int value)
Set buffer size.
AbstractSensorChannelInterface::dbusConnectNotify
void dbusConnectNotify(const QMetaMethod &signal)
Wrapper for function of QDBusAbstractInterface.
AbstractSensorChannelInterface::setDataRateFinished
void setDataRateFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::downsampling
bool downsampling
Definition abstractsensor_i.h:61
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::setDataRangeIndexFinished
void setDataRangeIndexFinished(QDBusPendingCallWatcher *watch)
AbstractSensorChannelInterface::requestDataRange
void requestDataRange(DataRange range)
Request data range.
AbstractSensorChannelInterface::removeDataRangeRequest
void removeDataRangeRequest()
Remove set data range request.
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:58
AbstractSensorChannelInterface::errorString
QString errorString
Definition abstractsensor_i.h:51
AbstractSensorChannelInterface::getCurrentDataRange
DataRange getCurrentDataRange()
Get current used data range.
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:59
AbstractSensorChannelInterface::sessionId
int sessionId
Definition abstractsensor_i.h:49
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:55
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:60
AbstractSensorChannelInterface::type
QString type
Definition abstractsensor_i.h:57
AbstractSensorChannelInterface::setDataRate
void setDataRate(double dataRate_Hz)
Set sensor sampling frequency (in Hertz).
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:537
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.