From 29aaea2d80a9eb1715b6cddfac2d2aacf76358bd Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 11 Feb 2016 23:55:16 +0100 Subject: launchpad ~mzanetti/rockwork/trunk r87 --- rockworkd/libpebble/appmsgmanager.h | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 rockworkd/libpebble/appmsgmanager.h (limited to 'rockworkd/libpebble/appmsgmanager.h') diff --git a/rockworkd/libpebble/appmsgmanager.h b/rockworkd/libpebble/appmsgmanager.h new file mode 100644 index 0000000..77ee480 --- /dev/null +++ b/rockworkd/libpebble/appmsgmanager.h @@ -0,0 +1,94 @@ +#ifndef APPMSGMANAGER_H +#define APPMSGMANAGER_H + +#include +#include +#include + +#include "watchconnection.h" +#include "appmanager.h" + +class AppMsgManager : public QObject +{ + Q_OBJECT + +public: + enum AppMessage { + AppMessagePush = 1, + AppMessageRequest = 2, + AppMessageAck = 0xFF, + AppMessageNack = 0x7F + }; + enum LauncherMessage { + LauncherActionStart = 1, + LauncherActionStop = 0 + }; + + explicit AppMsgManager(Pebble *pebble, AppManager *apps, WatchConnection *connection); + + void send(const QUuid &uuid, const QVariantMap &data, + const std::function &ackCallback, + const std::function &nackCallback); + + typedef std::function MessageHandlerFunc; + void setMessageHandler(const QUuid &uuid, MessageHandlerFunc func); + void clearMessageHandler(const QUuid &uuid); + + uint lastTransactionId() const; + uint nextTransactionId() const; + +public slots: + void send(const QUuid &uuid, const QVariantMap &data); + void launchApp(const QUuid &uuid); + void closeApp(const QUuid &uuid); + +signals: + void appStarted(const QUuid &uuid); + void appStopped(const QUuid &uuid); + +private: + WatchConnection::Dict mapAppKeys(const QUuid &uuid, const QVariantMap &data); + QVariantMap mapAppKeys(const QUuid &uuid, const WatchConnection::Dict &dict); + + static bool unpackAppLaunchMessage(const QByteArray &msg, QUuid *uuid); + static bool unpackPushMessage(const QByteArray &msg, quint8 *transaction, QUuid *uuid, WatchConnection::Dict *dict); + + static QByteArray buildPushMessage(quint8 transaction, const QUuid &uuid, const WatchConnection::Dict &dict); + static QByteArray buildLaunchMessage(quint8 messageType, const QUuid &uuid); + static QByteArray buildAckMessage(quint8 transaction); + static QByteArray buildNackMessage(quint8 transaction); + + void handleLauncherPushMessage(const QByteArray &data); + void handlePushMessage(const QByteArray &data); + void handleAckMessage(const QByteArray &data, bool ack); + + void transmitNextPendingTransaction(); + void abortPendingTransactions(); + +private slots: + void handleWatchConnectedChanged(); + void handleTimeout(); + + void handleAppLaunchMessage(const QByteArray &data); + void handleLauncherMessage(const QByteArray &data); + void handleApplicationMessage(const QByteArray &data); + +private: + Pebble *m_pebble; + AppManager *apps; + WatchConnection *m_connection; + QHash _handlers; + quint8 _lastTransactionId; + + struct PendingTransaction { + quint8 transactionId; + QUuid uuid; + WatchConnection::Dict dict; + std::function ackCallback; + std::function nackCallback; + }; + QQueue _pending; + QTimer *_timeout; +}; + +#endif // APPMSGMANAGER_H -- cgit v1.2.3