diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2015-11-29 00:27:47 +0100 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2015-11-29 00:27:47 +0100 |
| commit | 0623dc3fcf3a0928a364d46f2ec0327a6e478b82 (patch) | |
| tree | fe1d26aa5b4be45d13b2db5259d52ad590cfaa6b | |
| parent | f498a49bfebcd2b535fcb54aaa8c0008fb320232 (diff) | |
| parent | 05011ecce5da659f36a0abea79f1a96d24703801 (diff) | |
Merge pull request #98 from abranson/master
Support pebble apps with workers
| -rw-r--r-- | daemon/bankmanager.cpp | 19 | ||||
| -rw-r--r-- | daemon/bundle.cpp | 20 | ||||
| -rw-r--r-- | daemon/bundle.h | 4 | ||||
| -rw-r--r-- | daemon/manager.cpp | 6 | ||||
| -rw-r--r-- | daemon/uploadmanager.cpp | 5 | ||||
| -rw-r--r-- | daemon/uploadmanager.h | 1 |
6 files changed, 45 insertions, 10 deletions
diff --git a/daemon/bankmanager.cpp b/daemon/bankmanager.cpp index ef74ef6..797d7e3 100644 --- a/daemon/bankmanager.cpp +++ b/daemon/bankmanager.cpp @@ -80,7 +80,7 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) qCDebug(l) << "about to install app" << info.shortName() << "into slot" << slot; - QSharedPointer<QIODevice> binaryFile(info.openFile(AppInfo::BINARY)); + QSharedPointer<QIODevice> binaryFile(info.openFile(AppInfo::APPLICATION)); if (!binaryFile) { qCWarning(l) << "failed to open" << info.shortName() << "AppInfo::BINARY"; return false; @@ -93,11 +93,26 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) _slots[slot].name.clear(); _slots[slot].uuid = QUuid(); - upload->uploadAppBinary(slot, binaryFile.data(), info.crcFile(AppInfo::BINARY), + upload->uploadAppBinary(slot, binaryFile.data(), info.crcFile(AppInfo::APPLICATION), [this, info, binaryFile, slot]() { qCDebug(l) << "app binary upload succesful"; binaryFile->close(); + // Upload worker if present + if (info.type() == "worker") { + QSharedPointer<QIODevice> workerFile(info.openFile(AppInfo::WORKER)); + if (workerFile) { + upload->uploadAppWorker(slot, workerFile.data(), info.crcFile(AppInfo::WORKER), + [this, workerFile, slot]() { + qCDebug(l) << "app worker upload succesful"; + workerFile->close(); + }, [this, workerFile](int code) { + workerFile->close(); + qCWarning(l) << "app worker upload failed" << code; + }); + } + } + // Proceed to upload the resource file QSharedPointer<QIODevice> resourceFile(info.openFile(AppInfo::RESOURCES)); if (resourceFile) { diff --git a/daemon/bundle.cpp b/daemon/bundle.cpp index 63400b5..2b8de11 100644 --- a/daemon/bundle.cpp +++ b/daemon/bundle.cpp @@ -93,8 +93,14 @@ QIODevice *Bundle::openFile(enum Bundle::File file, QIODevice::OpenMode mode) co case Bundle::APPJS: fileName = "pebble-js-app.js"; break; - case Bundle::BINARY: - fileName = b->manifest.value(type()).toObject().value("name").toString(); + case Bundle::FIRMWARE: + fileName = b->manifest.value("firmware").toObject().value("name").toString(); + break; + case Bundle::APPLICATION: + fileName = b->manifest.value("application").toObject().value("name").toString(); + break; + case Bundle::WORKER: + fileName = b->manifest.value("worker").toObject().value("name").toString(); break; case Bundle::RESOURCES: fileName = b->manifest.value("resources").toObject().value("name").toString(); @@ -133,12 +139,18 @@ quint32 Bundle::crcFile(enum Bundle::File file) const quint32 ret = 0; switch (file) { - case Bundle::BINARY: - ret = b->manifest.value(type()).toObject().value("crc").toDouble(); + case Bundle::FIRMWARE: + ret = b->manifest.value("firmware").toObject().value("crc").toDouble(); break; case Bundle::RESOURCES: ret = b->manifest.value("resources").toObject().value("crc").toDouble(); break; + case Bundle::APPLICATION: + ret = b->manifest.value("application").toObject().value("crc").toDouble(); + break; + case Bundle::WORKER: + ret = b->manifest.value("worker").toObject().value("crc").toDouble(); + break; default: qCWarning(l) << "Unsupported CRC for" << file; } diff --git a/daemon/bundle.h b/daemon/bundle.h index 1b77c94..cb47cbf 100644 --- a/daemon/bundle.h +++ b/daemon/bundle.h @@ -18,7 +18,9 @@ public: enum File { MANIFEST, INFO, - BINARY, + FIRMWARE, + APPLICATION, + WORKER, RESOURCES, APPJS }; diff --git a/daemon/manager.cpp b/daemon/manager.cpp index b02264e..37625e3 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -343,7 +343,7 @@ bool Manager::uploadFirmware(bool recovery, const QString &file) return false; } - if (!bundle.fileExists(Bundle::BINARY) || !bundle.fileExists(Bundle::RESOURCES)) { + if (!bundle.fileExists(Bundle::FIRMWARE) || !bundle.fileExists(Bundle::RESOURCES)) { qCWarning(l) << file << "is missing binary or resource"; return false; } @@ -364,9 +364,9 @@ bool Manager::uploadFirmware(bool recovery, const QString &file) qCDebug(l) << "firmware resource upload succesful"; resourceFile->close(); // Proceed to upload the resource file - QSharedPointer<QIODevice> binaryFile(bundle.openFile(Bundle::BINARY)); + QSharedPointer<QIODevice> binaryFile(bundle.openFile(Bundle::FIRMWARE)); if (binaryFile) { - upload->uploadFirmwareBinary(recovery, binaryFile.data(), bundle.crcFile(Bundle::BINARY), + upload->uploadFirmwareBinary(recovery, binaryFile.data(), bundle.crcFile(Bundle::FIRMWARE), [this, binaryFile]() { binaryFile->close(); qCDebug(l) << "firmware binary upload succesful"; diff --git a/daemon/uploadmanager.cpp b/daemon/uploadmanager.cpp index 0751713..cfca8e5 100644 --- a/daemon/uploadmanager.cpp +++ b/daemon/uploadmanager.cpp @@ -67,6 +67,11 @@ uint UploadManager::uploadAppResources(int slot, QIODevice *device, quint32 crc, return upload(WatchConnector::uploadRESOURCES, slot, QString(), device, -1, crc, successCallback, errorCallback, progressCallback); } +uint UploadManager::uploadAppWorker(int slot, QIODevice *device, quint32 crc, SuccessCallback successCallback, ErrorCallback errorCallback, ProgressCallback progressCallback) +{ + return upload(WatchConnector::uploadWORKER, slot, QString(), device, -1, crc, successCallback, errorCallback, progressCallback); +} + uint UploadManager::uploadFile(const QString &filename, QIODevice *device, quint32 crc, SuccessCallback successCallback, ErrorCallback errorCallback, ProgressCallback progressCallback) { Q_ASSERT(!filename.isEmpty()); diff --git a/daemon/uploadmanager.h b/daemon/uploadmanager.h index 316f55d..85c5b3b 100644 --- a/daemon/uploadmanager.h +++ b/daemon/uploadmanager.h @@ -22,6 +22,7 @@ public: uint uploadAppBinary(int slot, QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); uint uploadAppResources(int slot, QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); + uint uploadAppWorker(int slot, QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); uint uploadFile(const QString &filename, QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); uint uploadFirmwareBinary(bool recovery, QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); uint uploadFirmwareResources(QIODevice *device, quint32 crc, SuccessCallback successCallback = SuccessCallback(), ErrorCallback errorCallback = ErrorCallback(), ProgressCallback progressCallback = ProgressCallback()); |
