From 78d1697cd63033244304f7794cf9157029e4fdb5 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Wed, 8 Apr 2015 11:52:14 +0200 Subject: Implemented firmwareUpgrade in daemon --- daemon/manager.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'daemon/manager.cpp') diff --git a/daemon/manager.cpp b/daemon/manager.cpp index ca3830f..345fb1d 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -4,6 +4,7 @@ #include "manager.h" #include "watch_adaptor.h" +#include "bundle.h" Manager::Manager(Settings *settings, QObject *parent) : QObject(parent), l(metaObject()->className()), settings(settings), @@ -348,6 +349,67 @@ void Manager::onAppClosed(const QUuid &uuid) emit proxy->AppUuidChanged(); } +bool Manager::uploadFirmware(bool recovery, const QString &file) +{ + qCDebug(l) << "about to upload" << (recovery ? "recovery" : "normal") + << "firmware:" << file; + + Bundle bundle(Bundle::fromPath(file)); + if (!bundle.isValid()) { + qCWarning(l) << file << "is invalid bundle"; + return false; + } + + if (!bundle.fileExists(Bundle::BINARY) || !bundle.fileExists(Bundle::RESOURCES)) { + qCWarning(l) << file << "is missing binary or resource"; + return false; + } + + watch->systemMessage(WatchConnector::systemFIRMWARE_START, + [this, recovery, bundle](const QByteArray &data) { + qCDebug(l) << "got response to firmware start" << data.toHex(); + + QSharedPointer resourceFile(bundle.openFile(Bundle::RESOURCES)); + if (!resourceFile) { + qCWarning(l) << "failed to open" << bundle.path() << "resource"; + watch->systemMessage(WatchConnector::systemFIRMWARE_FAIL); + return true; + } + + upload->uploadFirmwareResources(resourceFile.data(), + [this, recovery, bundle, resourceFile]() { + qCDebug(l) << "firmware resource upload succesful"; + resourceFile->close(); + // Proceed to upload the resource file + QSharedPointer binaryFile(bundle.openFile(Bundle::BINARY)); + if (binaryFile) { + upload->uploadFirmwareBinary(recovery, binaryFile.data(), + [this, binaryFile]() { + binaryFile->close(); + qCDebug(l) << "firmware binary upload succesful"; + // Upload succesful + watch->systemMessage(WatchConnector::systemFIRMWARE_COMPLETE); + }, [this, binaryFile](int code) { + binaryFile->close(); + qCWarning(l) << "firmware binary upload failed" << code; + watch->systemMessage(WatchConnector::systemFIRMWARE_FAIL); + }); + } else { + qCWarning(l) << "failed to open" << bundle.path() << "binary"; + watch->systemMessage(WatchConnector::systemFIRMWARE_FAIL); + } + }, [this, resourceFile](int code) { + resourceFile->close(); + qCWarning(l) << "firmware resource upload failed" << code; + watch->systemMessage(WatchConnector::systemFIRMWARE_FAIL); + }); + + return true; + }); + + return true; +} + QStringList PebbledProxy::AppSlots() const { const int num_slots = manager()->bank->numSlots(); @@ -512,3 +574,20 @@ void PebbledProxy::UploadApp(const QString &uuid, int slot) "Cannot upload application"); } } + +void PebbledProxy::NotifyFirmware(bool ok) +{ + Q_ASSERT(calledFromDBus()); + manager()->watch->sendFirmwareState(ok); +} + +void PebbledProxy::UploadFirmware(bool recovery, const QString &file) +{ + Q_ASSERT(calledFromDBus()); + const QDBusMessage msg = message(); + + if (!manager()->uploadFirmware(recovery, file)) { + sendErrorReply(msg.interface() + ".Error.CannotUpload", + "Cannot upload firmware"); + } +} -- cgit v1.2.3