diff options
| author | Javier <dev.git@javispedro.com> | 2014-11-30 17:27:08 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-11-30 17:37:19 +0100 |
| commit | 49f1261bf9d635d5e3d881e87a93ed4e76abfe90 (patch) | |
| tree | 4432ecd771a3aca533914d02f9947cb497493395 /daemon/watchconnector.h | |
| parent | d55d1d472d5876f90dd95301d9f3b6bef6f4c494 (diff) | |
allow receiving responses to commands in watchconnector
* the skeleton is in place for watchconnector to allow query->response
messages. I've used call/cc style because it is impossible to make
QBluetoothSocket synchronous (waitForReadyRead() is a no-op)
* remove watchcommands, instead create musicmanager to listen for the
music endpoint. The other (simpler) endpoints are now listened in
watchconnector itself. hangupAll() slot is moved to voicecallmanager.
* instead of emitting signals for each received message, listeners
can now register for receiving messages targeted towards a given
endpoint
* when reading from bluetoothsocket, properly handle short reads
* remove useless 'watch' namespace
* create appmanager, which mantains a database of installed apps
(installed on the phone, that is; watch installed apps will come
later)
* all the *Managers are now instantiated by the main Manager itself
* introduce Unpacker helper class for decoding watch messages
* implement getAppbankStatus and getAppbankUuids messages and response
parsers
* remove file logging for now (20MB is bad for eMMC!)
* use dbus object path /org/pebbled instead of /
Diffstat (limited to 'daemon/watchconnector.h')
| -rw-r--r-- | daemon/watchconnector.h | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index b64e31b..01c3dac 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -30,6 +30,7 @@ #ifndef WATCHCONNECTOR_H #define WATCHCONNECTOR_H +#include <functional> #include <QObject> #include <QPointer> #include <QStringList> @@ -39,25 +40,18 @@ #include <QBluetoothServiceInfo> #include <Log4Qt/Logger> -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) -using namespace QtBluetooth; -#endif - -namespace watch -{ - class WatchConnector : public QObject { Q_OBJECT LOG4QT_DECLARE_QCLASS_LOGGER - Q_ENUMS(Endpoints) + Q_ENUMS(Endpoint) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString connected READ isConnected NOTIFY connectedChanged) public: - enum Endpoints { + enum Endpoint { watchTIME = 11, watchVERSION = 16, watchPHONE_VERSION = 17, @@ -111,6 +105,11 @@ public: systemBLUETOOTH_START_DISCOVERABLE = 6, systemBLUETOOTH_END_DISCOVERABLE = 7 }; + enum AppManager { + appmgrGET_APPBANK_STATUS = 1, + appmgrGET_APPBANK_UUIDS = 5 + }; + enum { leadEMAIL = 0, leadSMS = 1, @@ -139,27 +138,41 @@ public: osLINUX = 4, osWINDOWS = 5 }; + enum { + DEFAULT_TIMEOUT_MSECS = 100 + }; + typedef std::function<bool(const QByteArray &)> EndpointHandlerFunc; explicit WatchConnector(QObject *parent = 0); virtual ~WatchConnector(); - bool isConnected() const { return is_connected; } - QString name() const { return socket != nullptr ? socket->peerName() : ""; } - QString timeStamp(); - QString decodeEndpoint(uint val); + inline bool isConnected() const { return is_connected; } + inline QString name() const { return socket != nullptr ? socket->peerName() : ""; } + + void setEndpointHandler(uint endpoint, EndpointHandlerFunc func); + void clearEndpointHandler(uint endpoint); + + static QString timeStamp(); + static QString decodeEndpoint(uint val); + + void getAppbankStatus(const std::function<void(const QString &s)>& callback); + void getAppbankUuids(const std::function<void(const QList<QUuid> &uuids)>& callback); signals: - void messageReceived(QString peer, QString msg); - void messageDecoded(uint endpoint, QByteArray data); + void messageReceived(uint endpoint, const QByteArray &data); void nameChanged(); void connectedChanged(); public slots: - void sendData(const QByteArray &data); - void sendMessage(uint endpoint, QByteArray data); + void deviceConnect(const QString &name, const QString &address); + void disconnect(); + void reconnect(); + + void sendMessage(uint endpoint, const QByteArray &data); void ping(uint val); void time(); + void sendNotification(uint lead, QString sender, QString data, QString subject); void sendSMSNotification(QString sender, QString data); void sendEmailNotification(QString sender, QString data, QString subject); @@ -176,8 +189,7 @@ public slots: void startPhoneCall(uint cookie=0); void endPhoneCall(uint cookie=0); - void deviceConnect(const QString &name, const QString &address); - void disconnect(); +private slots: void deviceDiscovered(const QBluetoothDeviceInfo&); void handleWatch(const QString &name, const QString &address); void onReadSocket(); @@ -185,18 +197,19 @@ public slots: void onConnected(); void onDisconnected(); void onError(QBluetoothSocket::SocketError error); - void reconnect(); private: - void decodeMsg(QByteArray data); + void sendData(const QByteArray &data); + bool dispatchMessage(uint endpoint, const QByteArray &data); QPointer<QBluetoothSocket> socket; + QHash<uint, QList<EndpointHandlerFunc>> tmpHandlers; + QHash<uint, EndpointHandlerFunc> handlers; bool is_connected; QByteArray writeData; QTimer reconnectTimer; QString _last_name; QString _last_address; }; -} #endif // WATCHCONNECTOR_H |
