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/watchcommands.cpp | |
| 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/watchcommands.cpp')
| -rw-r--r-- | daemon/watchcommands.cpp | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/daemon/watchcommands.cpp b/daemon/watchcommands.cpp deleted file mode 100644 index b16efb5..0000000 --- a/daemon/watchcommands.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "watchcommands.h" - -#include <QDBusConnection> -#include <QDBusMessage> -#include <QDBusReply> - -using namespace watch; - -WatchCommands::WatchCommands(WatchConnector *watch, QObject *parent) : - QObject(parent), watch(watch) -{} - -void WatchCommands::processMessage(uint endpoint, QByteArray data) -{ - logger()->debug() << __FUNCTION__ << endpoint << "/" << data.toHex() << data.length(); - switch (endpoint) { - case WatchConnector::watchPHONE_VERSION: - watch->sendPhoneVersion(); - break; - case WatchConnector::watchPHONE_CONTROL: - if (data.at(0) == WatchConnector::callHANGUP) { - emit hangup(); - } - break; - case WatchConnector::watchMUSIC_CONTROL: - musicControl(WatchConnector::MusicControl(data.at(0))); - break; - case WatchConnector::watchSYSTEM_MESSAGE: - logger()->info() << "Got SYSTEM_MESSAGE" << WatchConnector::SystemMessage(data.at(0)); - // TODO: handle systemBLUETOOTH_START_DISCOVERABLE/systemBLUETOOTH_END_DISCOVERABLE - break; - - default: - logger()->info() << __FUNCTION__ << "endpoint" << endpoint << "not supported yet"; - } -} - -void WatchCommands::onMprisMetadataChanged(QVariantMap metadata) -{ - QString track = metadata.value("xesam:title").toString(); - QString album = metadata.value("xesam:album").toString(); - QString artist = metadata.value("xesam:artist").toString(); - logger()->debug() << __FUNCTION__ << track << album << artist; - watch->sendMusicNowPlaying(track, album, artist); -} - -void WatchCommands::musicControl(WatchConnector::MusicControl operation) -{ - logger()->debug() << "Operation:" << operation; - - QString mpris = parent()->property("mpris").toString(); - if (mpris.isEmpty()) { - logger()->debug() << "No mpris interface active"; - return; - } - - QString method; - - switch(operation) { - case WatchConnector::musicPLAY_PAUSE: - method = "PlayPause"; - break; - case WatchConnector::musicPAUSE: - method = "Pause"; - break; - case WatchConnector::musicPLAY: - method = "Play"; - break; - case WatchConnector::musicNEXT: - method = "Next"; - break; - case WatchConnector::musicPREVIOUS: - method = "Previous"; - break; - case WatchConnector::musicVOLUME_UP: - case WatchConnector::musicVOLUME_DOWN: { - QDBusReply<QDBusVariant> VolumeReply = QDBusConnection::sessionBus().call( - QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get") - << "org.mpris.MediaPlayer2.Player" << "Volume"); - if (VolumeReply.isValid()) { - double volume = VolumeReply.value().variant().toDouble(); - if (operation == WatchConnector::musicVOLUME_UP) { - volume += 0.1; - } - else { - volume -= 0.1; - } - logger()->debug() << "Setting volume" << volume; - QDBusError err = QDBusConnection::sessionBus().call( - QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Set") - << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(volume))); - if (err.isValid()) { - logger()->error() << err.message(); - } - } - else { - logger()->error() << VolumeReply.error().message(); - } - } - return; - case WatchConnector::musicGET_NOW_PLAYING: - onMprisMetadataChanged(parent()->property("mprisMetadata").toMap()); - return; - - case WatchConnector::musicSEND_NOW_PLAYING: - logger()->warn() << "Operation" << operation << "not supported"; - return; - } - - if (method.isEmpty()) { - logger()->error() << "Requested unsupported operation" << operation; - return; - } - - logger()->debug() << operation << "->" << method; - - QDBusError err = QDBusConnection::sessionBus().call( - QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", method)); - if (err.isValid()) { - logger()->error() << err.message(); - } -} |
