From 3ce36b764fc55bdfc8fe98395cab072d50855e28 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 1 Mar 2016 09:13:06 +0100 Subject: New managers from javispedro AppFetchManager, BlobDBManager --- daemon/appfetchmanager.cc | 106 ---------------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 daemon/appfetchmanager.cc (limited to 'daemon/appfetchmanager.cc') diff --git a/daemon/appfetchmanager.cc b/daemon/appfetchmanager.cc deleted file mode 100644 index 9c58e27..0000000 --- a/daemon/appfetchmanager.cc +++ /dev/null @@ -1,106 +0,0 @@ -#include "appfetchmanager.h" -#include "appmanager.h" -#include "uploadmanager.h" -#include "unpacker.h" -#include "packer.h" - -AppFetchManager::AppFetchManager(WatchConnector *watch, UploadManager *upload, AppManager *apps, QObject *parent) - : QObject(parent), l(metaObject()->className()), - watch(watch), upload(upload), apps(apps) - -{ - watch->setEndpointHandler(WatchConnector::watchAPP_FETCH, - [this](const QByteArray &data) { - switch (data.at(0)) { - case WatchConnector::appfetchREQUEST: - handleAppFetchRequest(data); - break; - } - - return true; - }); -} - -void AppFetchManager::handleAppFetchRequest(const QByteArray &msg) -{ - Unpacker u(msg); - quint8 command = u.readLE(); - QUuid uuid = u.readUuid(); - qint32 appId = u.readLE(); - - Q_ASSERT(command == WatchConnector::appfetchREQUEST); - - uploadApp(uuid, appId); -} - -void AppFetchManager::sendAppFetchResponse(WatchConnector::AppFetchMessage command, WatchConnector::AppFetchStatus status) -{ - QByteArray msg; - Packer p(&msg); - - p.writeLE(command); - p.writeLE(status); - - watch->sendMessage(WatchConnector::watchAPP_FETCH, msg); -} - -void AppFetchManager::uploadApp(const QUuid &uuid, quint32 appId) -{ - AppInfo info = apps->info(uuid); - if (info.uuid() != uuid) { - qCWarning(l) << "uuid" << uuid << "is not installed"; - sendAppFetchResponse(WatchConnector::appfetchREQUEST, WatchConnector::appfetchINVALID_UUID); - return; - } - - qCDebug(l) << "about to upload app" << info.shortName(); - - QSharedPointer binaryFile(info.openFile(AppInfo::APPLICATION)); - if (!binaryFile) { - qCWarning(l) << "failed to open" << info.shortName() << "AppInfo::BINARY"; - sendAppFetchResponse(WatchConnector::appfetchREQUEST, WatchConnector::appfetchINVALID_UUID); - return; - } - - qCDebug(l) << "binary file size is" << binaryFile->size(); - - upload->uploadAppBinaryId(appId, binaryFile.data(), info.crcFile(AppInfo::APPLICATION), - [this, info, binaryFile, appId]() { - qCDebug(l) << "app binary upload succesful"; - binaryFile->close(); - - // Upload worker if present - if (info.type() == "worker") { - QSharedPointer workerFile(info.openFile(AppInfo::WORKER)); - if (workerFile) { - upload->uploadAppWorkerId(appId, workerFile.data(), info.crcFile(AppInfo::WORKER), - [this, workerFile]() { - qCDebug(l) << "app worker upload succesful"; - workerFile->close(); - }, [this, workerFile](int code) { - qCWarning(l) << "app worker upload failed" << code; - workerFile->close(); - }); - } - } - - // Proceed to upload the resource file - QSharedPointer resourceFile(info.openFile(AppInfo::RESOURCES)); - if (resourceFile) { - upload->uploadAppResourcesId(appId, resourceFile.data(), info.crcFile(AppInfo::RESOURCES), - [this, resourceFile]() { - qCDebug(l) << "app resources upload succesful"; - resourceFile->close(); - // Upload succesful - }, [this, resourceFile](int code) { - qCWarning(l) << "app resources upload failed" << code; - resourceFile->close(); - }); - } else { - // No resource file - } - }, [this, binaryFile](int code) { - binaryFile->close(); - qCWarning(l) << "app binary upload failed" << code; - }); -} -- cgit v1.2.3