summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/bankmanager.cpp233
-rw-r--r--daemon/bankmanager.h51
-rw-r--r--daemon/daemon.pro6
-rw-r--r--daemon/manager.cpp12
-rw-r--r--daemon/manager.h4
-rw-r--r--daemon/watchconnector.cpp90
-rw-r--r--daemon/watchconnector.h4
7 files changed, 305 insertions, 95 deletions
diff --git a/daemon/bankmanager.cpp b/daemon/bankmanager.cpp
new file mode 100644
index 0000000..194ec77
--- /dev/null
+++ b/daemon/bankmanager.cpp
@@ -0,0 +1,233 @@
+#include "unpacker.h"
+#include "packer.h"
+#include "bankmanager.h"
+
+BankManager::BankManager(WatchConnector *watch, AppManager *apps, QObject *parent) :
+ QObject(parent), watch(watch), apps(apps)
+{
+ connect(watch, &WatchConnector::connectedChanged, this, &BankManager::handleWatchConnected);
+}
+
+int BankManager::numSlots() const
+{
+ return _slots.size();
+}
+
+bool BankManager::uploadApp(const QUuid &uuid, int slot)
+{
+ AppInfo info = apps->info(uuid);
+ if (info.uuid() != uuid) {
+ logger()->warn() << "uuid" << uuid << "is not installed";
+ return false;
+ }
+ if (slot == -1) {
+ slot = findUnusedSlot();
+ if (slot == -1) {
+ logger()->warn() << "no free slots!";
+ return false;
+ }
+ }
+ if (slot < 0 || slot > _slots.size()) {
+ logger()->warn() << "invalid slot index";
+ return false;
+ }
+
+ // TODO
+
+ return false;
+}
+
+bool BankManager::unloadApp(int slot)
+{
+ if (slot < 0 || slot > _slots.size()) {
+ logger()->warn() << "invalid slot index";
+ return false;
+ }
+ if (!_slots[slot].used) {
+ logger()->warn() << "slot is empty";
+ return false;
+ }
+
+ logger()->debug() << "going to unload app" << _slots[slot].name << "in slot" << slot;
+
+ int installId = _slots[slot].id;
+
+ QByteArray msg;
+ msg.reserve(2 * sizeof(quint32));
+ Packer p(&msg);
+ p.write<quint8>(WatchConnector::appmgrREMOVE_APP);
+ p.write<quint32>(installId);
+ p.write<quint32>(slot);
+
+ watch->sendMessage(WatchConnector::watchAPP_MANAGER, msg,
+ [this](const QByteArray &data) {
+ Unpacker u(data);
+ if (u.read<quint8>() != WatchConnector::appmgrREMOVE_APP) {
+ return false;
+ }
+
+ uint result = u.read<quint32>();
+ switch (result) {
+ case 1: /* Success */
+ logger()->debug() << "sucessfully unloaded app";
+ break;
+ default:
+ logger()->warn() << "could not unload app. result code:" << result;
+ break;
+ }
+
+ QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
+
+ return true;
+ });
+
+ return true; // Operation in progress
+}
+
+void BankManager::refresh()
+{
+ logger()->debug() << "refreshing bank status";
+
+ watch->sendMessage(WatchConnector::watchAPP_MANAGER,
+ QByteArray(1, WatchConnector::appmgrGET_APPBANK_STATUS),
+ [this](const QByteArray &data) {
+ if (data.at(0) != WatchConnector::appmgrGET_APPBANK_STATUS) {
+ return false;
+ }
+
+ if (data.size() < 9) {
+ logger()->warn() << "invalid getAppbankStatus response";
+ return true;
+ }
+
+ Unpacker u(data);
+
+ u.skip(sizeof(quint8));
+
+ unsigned int num_banks = u.read<quint32>();
+ unsigned int apps_installed = u.read<quint32>();
+
+ logger()->debug() << "Bank status:" << apps_installed << "/" << num_banks;
+
+ _slots.resize(num_banks);
+ for (unsigned int i = 0; i < num_banks; i++) {
+ _slots[i].used = false;
+ _slots[i].id = 0;
+ _slots[i].name.clear();
+ _slots[i].company.clear();
+ _slots[i].flags = 0;
+ _slots[i].version = 0;
+ _slots[i].uuid = QUuid();
+ }
+
+ for (unsigned int i = 0; i < apps_installed; i++) {
+ unsigned int id = u.read<quint32>();
+ int index = u.read<quint32>();
+ QString name = u.readFixedString(32);
+ QString company = u.readFixedString(32);
+ unsigned int flags = u.read<quint32>();
+ unsigned short version = u.read<quint16>();
+
+ if (index < 0 || index >= _slots.size()) {
+ logger()->warn() << "Invalid slot index" << index;
+ continue;
+ }
+
+ if (u.bad()) {
+ logger()->warn() << "short read";
+ return true;
+ }
+
+ _slots[index].used = true;
+ _slots[index].id = id;
+ _slots[index].name = name;
+ _slots[index].company = company;
+ _slots[index].flags = flags;
+ _slots[index].version = version;
+
+ AppInfo info = apps->info(name);
+ QUuid uuid = info.uuid();
+ _slots[index].uuid = uuid;
+
+ logger()->debug() << index << id << name << company << flags << version << uuid;
+ }
+
+ emit this->slotsChanged();
+
+ return true;
+ });
+}
+
+int BankManager::findUnusedSlot() const
+{
+ for (int i = 0; i < _slots.size(); ++i) {
+ if (!_slots[i].used) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+void BankManager::handleWatchConnected()
+{
+ if (watch->isConnected()) {
+ refresh();
+ }
+}
+
+#if 0
+
+void WatchConnector::getAppbankStatus(const std::function<void(const QString &s)>& callback)
+{
+ sendMessage(watchAPP_MANAGER, QByteArray(1, appmgrGET_APPBANK_STATUS),
+ [this, callback](const QByteArray &data) {
+
+ });
+}
+
+void WatchConnector::getAppbankUuids(const function<void(const QList<QUuid> &)>& callback)
+{
+ sendMessage(watchAPP_MANAGER, QByteArray(1, appmgrGET_APPBANK_UUIDS),
+ [this, callback](const QByteArray &data) {
+ if (data.at(0) != appmgrGET_APPBANK_UUIDS) {
+ return false;
+ }
+ logger()->debug() << "getAppbankUuids response" << data.toHex();
+
+ if (data.size() < 5) {
+ logger()->warn() << "invalid getAppbankUuids response";
+ return true;
+ }
+
+ Unpacker u(data);
+
+ u.skip(sizeof(quint8));
+
+ unsigned int apps_installed = u.read<quint32>();
+
+ logger()->debug() << apps_installed;
+
+ QList<QUuid> uuids;
+
+ for (unsigned int i = 0; i < apps_installed; i++) {
+ QUuid uuid = u.readUuid();
+
+ logger()->debug() << uuid.toString();
+
+ if (u.bad()) {
+ logger()->warn() << "short read";
+ return true;
+ }
+
+ uuids.push_back(uuid);
+ }
+
+ logger()->debug() << "finished";
+
+ callback(uuids);
+
+ return true;
+ });
+}
+#endif
diff --git a/daemon/bankmanager.h b/daemon/bankmanager.h
new file mode 100644
index 0000000..28729b9
--- /dev/null
+++ b/daemon/bankmanager.h
@@ -0,0 +1,51 @@
+#ifndef BANKMANAGER_H
+#define BANKMANAGER_H
+
+#include "watchconnector.h"
+#include "appmanager.h"
+
+class BankManager : public QObject
+{
+ Q_OBJECT
+ LOG4QT_DECLARE_QCLASS_LOGGER
+
+public:
+ explicit BankManager(WatchConnector *watch, AppManager *apps, QObject *parent = 0);
+
+ int numSlots() const;
+
+
+signals:
+ void slotsChanged();
+
+public slots:
+ bool uploadApp(const QUuid &uuid, int slot = -1);
+ bool unloadApp(int slot);
+
+ void refresh();
+
+private:
+ int findUnusedSlot() const;
+
+
+private slots:
+ void handleWatchConnected();
+
+private:
+ WatchConnector *watch;
+ AppManager *apps;
+
+ struct SlotInfo {
+ bool used;
+ quint32 id;
+ QString name;
+ QString company;
+ quint32 flags;
+ quint16 version;
+ QUuid uuid;
+ };
+
+ QVector<SlotInfo> _slots;
+};
+
+#endif // BANKMANAGER_H
diff --git a/daemon/daemon.pro b/daemon/daemon.pro
index 81570c7..21ebffa 100644
--- a/daemon/daemon.pro
+++ b/daemon/daemon.pro
@@ -28,7 +28,8 @@ SOURCES += \
jskitmanager.cpp \
appinfo.cpp \
jskitobjects.cpp \
- packer.cpp
+ packer.cpp \
+ bankmanager.cpp
HEADERS += \
manager.h \
@@ -46,7 +47,8 @@ HEADERS += \
jskitmanager.h \
appinfo.h \
jskitobjects.h \
- packer.h
+ packer.h \
+ bankmanager.h
OTHER_FILES += \
../log4qt-debug.conf \
diff --git a/daemon/manager.cpp b/daemon/manager.cpp
index 8a00373..27bb870 100644
--- a/daemon/manager.cpp
+++ b/daemon/manager.cpp
@@ -11,6 +11,7 @@ Manager::Manager(Settings *settings, QObject *parent) :
watch(new WatchConnector(this)),
dbus(new DBusConnector(this)),
apps(new AppManager(this)),
+ bank(new BankManager(watch, apps, this)),
voice(new VoiceCallManager(settings, this)),
notifications(new NotificationManager(settings, this)),
music(new MusicManager(watch, this)),
@@ -498,3 +499,14 @@ void PebbledProxy::SendAppConfigurationData(const QString &uuid, const QString &
manager()->js->handleWebviewClosed(data);
}
+
+void PebbledProxy::UnloadApp(uint slot)
+{
+ Q_ASSERT(calledFromDBus());
+ const QDBusMessage msg = message();
+
+ if (!manager()->bank->unloadApp(slot)) {
+ sendErrorReply(msg.interface() + ".Error.CannotUnload",
+ "Cannot unload application");
+ }
+}
diff --git a/daemon/manager.h b/daemon/manager.h
index 9347289..0e55190 100644
--- a/daemon/manager.h
+++ b/daemon/manager.h
@@ -10,6 +10,7 @@
#include "appmsgmanager.h"
#include "jskitmanager.h"
#include "appmanager.h"
+#include "bankmanager.h"
#include "settings.h"
#include <QObject>
@@ -45,6 +46,7 @@ class Manager : public QObject, protected QDBusContext
WatchConnector *watch;
DBusConnector *dbus;
AppManager *apps;
+ BankManager *bank;
VoiceCallManager *voice;
NotificationManager *notifications;
MusicManager *music;
@@ -143,6 +145,8 @@ public slots:
QString StartAppConfiguration(const QString &uuid);
void SendAppConfigurationData(const QString &uuid, const QString &data);
+ void UnloadApp(uint slot);
+
signals:
void NameChanged();
void AddressChanged();
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp
index baec52c..21f5ad5 100644
--- a/daemon/watchconnector.cpp
+++ b/daemon/watchconnector.cpp
@@ -451,93 +451,3 @@ void WatchConnector::endPhoneCall(uint cookie)
{
phoneControl(callEND, cookie, QStringList());
}
-
-void WatchConnector::getAppbankStatus(const std::function<void(const QString &s)>& callback)
-{
- sendMessage(watchAPP_MANAGER, QByteArray(1, appmgrGET_APPBANK_STATUS),
- [this, callback](const QByteArray &data) {
- if (data.at(0) != appmgrGET_APPBANK_STATUS) {
- return false;
- }
- logger()->debug() << "getAppbankStatus response" << data.toHex();
-
- if (data.size() < 9) {
- logger()->warn() << "invalid getAppbankStatus response";
- return true;
- }
-
- Unpacker u(data);
-
- u.skip(sizeof(quint8));
-
- unsigned int num_banks = u.read<quint32>();
- unsigned int apps_installed = u.read<quint32>();
-
- logger()->debug() << num_banks << "/" << apps_installed;
-
- for (unsigned int i = 0; i < apps_installed; i++) {
- unsigned int id = u.read<quint32>();
- unsigned int index = u.read<quint32>();
- QString name = u.readFixedString(32);
- QString company = u.readFixedString(32);
- unsigned int flags = u.read<quint32>();
- unsigned short version = u.read<quint16>();
-
- logger()->debug() << id << index << name << company << flags << version;
-
- if (u.bad()) {
- logger()->warn() << "short read";
- return true;
- }
- }
-
- logger()->debug() << "finished";
-
- return true;
- });
-}
-
-void WatchConnector::getAppbankUuids(const function<void(const QList<QUuid> &)>& callback)
-{
- sendMessage(watchAPP_MANAGER, QByteArray(1, appmgrGET_APPBANK_UUIDS),
- [this, callback](const QByteArray &data) {
- if (data.at(0) != appmgrGET_APPBANK_UUIDS) {
- return false;
- }
- logger()->debug() << "getAppbankUuids response" << data.toHex();
-
- if (data.size() < 5) {
- logger()->warn() << "invalid getAppbankUuids response";
- return true;
- }
-
- Unpacker u(data);
-
- u.skip(sizeof(quint8));
-
- unsigned int apps_installed = u.read<quint32>();
-
- logger()->debug() << apps_installed;
-
- QList<QUuid> uuids;
-
- for (unsigned int i = 0; i < apps_installed; i++) {
- QUuid uuid = u.readUuid();
-
- logger()->debug() << uuid.toString();
-
- if (u.bad()) {
- logger()->warn() << "short read";
- return true;
- }
-
- uuids.push_back(uuid);
- }
-
- logger()->debug() << "finished";
-
- callback(uuids);
-
- return true;
- });
-}
diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h
index 6c7fdd4..a5fe1ea 100644
--- a/daemon/watchconnector.h
+++ b/daemon/watchconnector.h
@@ -107,6 +107,7 @@ public:
};
enum AppManager {
appmgrGET_APPBANK_STATUS = 1,
+ appmgrREMOVE_APP = 2,
appmgrGET_APPBANK_UUIDS = 5
};
enum AppMessage {
@@ -179,9 +180,6 @@ public:
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(uint endpoint, const QByteArray &data);
void nameChanged();