M module-services/service-desktop/CMakeLists.txt => module-services/service-desktop/CMakeLists.txt +0 -3
@@ 2,10 2,7 @@ message( "${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}" )
add_subdirectory( parser )
add_subdirectory( endpoints )
-add_subdirectory( update )
-add_subdirectory( backup-restore )
add_subdirectory( messages )
-add_subdirectory( factory-reset )
target_sources( ${PROJECT_NAME}
PRIVATE
M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +3 -2
@@ 1,8 1,9 @@
+#include <messages/QueryMessage.hpp>
#include "ServiceDesktop.hpp"
#include "BackupRestore.hpp"
#include "DesktopMessages.hpp"
-#include "EndpointHandler.hpp"
-#include "FactoryReset.hpp"
+#include "Endpoint.hpp"
+#include "module-services/service-desktop/endpoints/factoryReset/FactoryReset.hpp"
#include "log/log.hpp"
#include "messages/DBSMSMessage.hpp"
#include "messages/DBSMSTemplateMessage.hpp"
M module-services/service-desktop/ServiceDesktop.hpp => module-services/service-desktop/ServiceDesktop.hpp +1 -1
@@ 1,7 1,7 @@
#pragma once
#include "WorkerDesktop.hpp"
-#include "UpdatePureOS.hpp"
+#include "module-services/service-desktop/endpoints/update/UpdatePureOS.hpp"
namespace service::name
{
M module-services/service-desktop/WorkerDesktop.cpp => module-services/service-desktop/WorkerDesktop.cpp +0 -1
@@ 1,5 1,4 @@
#include "WorkerDesktop.hpp"
-#include "EndpointHandler.hpp"
#include "MessageHandler.hpp"
bool WorkerDesktop::handleMessage(uint32_t queueID)
D module-services/service-desktop/backup-restore/CMakeLists.txt => module-services/service-desktop/backup-restore/CMakeLists.txt +0 -13
@@ 1,13 0,0 @@
-target_include_directories(${PROJECT_NAME}
- PUBLIC
- "${CMAKE_CURRENT_LIST_DIR}"
-)
-target_include_directories(${CMAKE_PROJECT_NAME}
- PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}
- ${CMAKE_BINARY_DIR}
- )
-target_sources(${PROJECT_NAME}
- PRIVATE
- "BackupRestore.cpp"
-)
D module-services/service-desktop/endpoints/Backup.cpp => module-services/service-desktop/endpoints/Backup.cpp +0 -85
@@ 1,85 0,0 @@
-#include "EndpointHandler.hpp"
-#include "ParserUtils.hpp"
-#include "DesktopMessages.hpp"
-#include "ServiceDesktop.hpp"
-
-static bool backupReady = false;
-
-static sys::ReturnCodes request(uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- json11::Json responseBodyJson;
-
- if (body[ParserStateMachine::json::backupRequest] == true) {
- auto msg = std::make_shared<sdesktop::BackupMessage>();
- sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerService);
- backupReady = true;
-
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupRequest, true}});
- }
- else {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupRequest, false}});
- }
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::backup)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Success;
-}
-
-static sys::ReturnCodes upload(uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- json11::Json responseBodyJson;
-
- if (body[ParserStateMachine::json::backupReady] == true) {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupReady, backupReady}});
- }
- else if (body[ParserStateMachine::json::backupUpload] == true) {
- if (vfs.fileExists(purefs::dir::os_backup.c_str()) == true) {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupUpload, true}});
- }
- else {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupUpload, false}});
- }
- }
- else {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::backupReady, false}});
- }
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::backup)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Success;
-}
-
-sys::ReturnCodes EndpointHandler::backup(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::post)) {
- return request(uuid, body, responseStr, ownerService);
- }
- else if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::get)) {
- return upload(uuid, body, responseStr, ownerService);
- }
- else {
- json11::Json responseBodyJson;
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::backup)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::BadRequest)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Failure;
- }
-}
M module-services/service-desktop/endpoints/CMakeLists.txt => module-services/service-desktop/endpoints/CMakeLists.txt +14 -3
@@ 5,6 5,11 @@ target_include_directories(${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/../messages"
"${CMAKE_CURRENT_LIST_DIR}/messages"
"${CMAKE_CURRENT_LIST_DIR}/contacts"
+ "${CMAKE_CURRENT_LIST_DIR}/backup"
+ "${CMAKE_CURRENT_LIST_DIR}/deviceInfo"
+ "${CMAKE_CURRENT_LIST_DIR}/factoryReset"
+ "${CMAKE_CURRENT_LIST_DIR}/restore"
+ "${CMAKE_CURRENT_LIST_DIR}/update"
)
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC
@@ 13,14 18,20 @@ target_include_directories(${CMAKE_PROJECT_NAME}
)
target_sources(${PROJECT_NAME}
PRIVATE
- "DeviceInfo.cpp"
+ "deviceInfo/DeviceInfoEndpoint.cpp"
/*"Update.cpp"*/
- /*"Backup.cpp"*/
/*"Restore.cpp"*/
- /*"Factory.cpp"*/
"contacts/ContactHelper.cpp"
"contacts/ContactsEndpoint.cpp"
"messages/MessageHelper.cpp"
"messages/MessagesEndpoint.cpp"
+ "backup/BackupEndpoint.cpp"
+ "backup/BackupRestore.cpp"
+ "deviceInfo/DeviceInfoEndpoint.cpp"
+ "factoryReset/FactoryResetEndpoint.cpp"
+ "factoryReset/FactoryReset.cpp"
+ "restore/RestoreEndpoint.cpp"
+ "update/UpdateEndpoint.cpp"
+ "update/UpdatePureOS.cpp"
)
D module-services/service-desktop/endpoints/DeviceInfo.cpp => module-services/service-desktop/endpoints/DeviceInfo.cpp +0 -53
@@ 1,53 0,0 @@
-#include "EndpointHandler.hpp"
-#include "Endpoint.hpp"
-#include <source/version.hpp>
-#include <vfs.hpp>
-#include <common_data/EventStore.hpp>
-#include <time/time_conversion.hpp>
-#include <service-desktop/ServiceDesktop.hpp>
-#include <string>
-
-using namespace ParserStateMachine;
-
-time_t FreeRTOS_time(time_t *pxTime)
-{
- return utils::time::Time().getTime();
-}
-
-// sys::ReturnCodes EndpointHandler::deviceInfo(
-// uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-// {
-// if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::get)) {
-// vfs::FilesystemStats fsStats = vfs.getFilesystemStats();
-
-// json11::Json responseBodyJson = json11::Json::object(
-// {{json::batteryLevel, std::to_string(Store::Battery::get().level)},
-// {json::batteryState, std::to_string(static_cast<int>(Store::Battery::get().state))},
-// {json::selectedSim, std::to_string(static_cast<int>(Store::GSM::get()->selected))},
-// {json::trayState, std::to_string(static_cast<int>(Store::GSM::get()->tray))},
-// {json::signalStrength,
-// std::to_string(static_cast<int>(Store::GSM::get()->getSignalStrength().rssiBar))},
-// {json::fsTotal, std::to_string(fsStats.totalMbytes)},
-// {json::fsFree, std::to_string(fsStats.freeMbytes)},
-// {json::fsFreePercent, std::to_string(fsStats.freePercent)},
-// {json::gitRevision, (std::string)(GIT_REV)},
-// {json::gitTag, (std::string)GIT_TAG},
-// {json::gitBranch, (std::string)GIT_BRANCH},
-// {json::currentRTCTime,
-// std::to_string(static_cast<uint32_t>(utils::time::Time().getTime()))}});
-
-// json11::Json responsePayloadJson = json11::Json::object(
-// {{json::endpoint, static_cast<int>(EndpointType::deviceInfo)},
-// {json::status, static_cast<int>(http::Code::OK)},
-// {json::uuid, std::to_string(uuid)},
-// {json::body, responseBodyJson}});
-
-// responseStr = Endpoint::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
-// return sys::ReturnCodes::Success;
-// }
-// else {
-// LOG_ERROR("Incorrect method");
-// return sys::ReturnCodes::Failure;
-// }
-// }
M module-services/service-desktop/endpoints/EndpointFactory.hpp => module-services/service-desktop/endpoints/EndpointFactory.hpp +12 -8
@@ 4,6 4,10 @@
#include "Service/Service.hpp"
#include "contacts/ContactsEndpoint.hpp"
#include "messages/MessagesEndpoint.hpp"
+#include "backup/BackupEndpoint.hpp"
+#include "deviceInfo/DeviceInfoEndpoint.hpp"
+#include "update/UpdateEndpoint.hpp"
+#include "restore/RestoreEndpoint.hpp"
using namespace ParserStateMachine;
@@ 14,14 18,14 @@ class EndpointFactory
{
LOG_DEBUG("Creating endpoint: %d", static_cast<int>(context.getEndpoint()));
switch (context.getEndpoint()) {
- // case EndpointType::deviceInfo:
- // return std::make_unique(EndpointDeviceInfo());
- // case EndpointType::update:
- // return std::make_unique(EndpointUpdate());
- // case EndpointType::backup:
- // return std::make_unique(EndpointBackup());
- // case EndpointType::restore:
- // return std::make_unique(EndpointRestore());
+ case EndpointType::update:
+ return std::make_unique<UpdateEndpoint>(ownerServicePtr);
+ case EndpointType::backup:
+ return std::make_unique<BackupEndpoint>(ownerServicePtr);
+ case EndpointType::deviceInfo:
+ return std::make_unique<DeviceInfoEndpoint>(ownerServicePtr);
+ case EndpointType::restore:
+ return std::make_unique<RestoreEndpoint>(ownerServicePtr);
case EndpointType::contacts:
return std::make_unique<ContactsEndpoint>(ownerServicePtr);
case EndpointType::messages:
D module-services/service-desktop/endpoints/Factory.cpp => module-services/service-desktop/endpoints/Factory.cpp +0 -45
@@ 1,45 0,0 @@
-#include "EndpointHandler.hpp"
-#include "ParserStateMachine.hpp"
-#include "DesktopMessages.hpp"
-#include "ServiceDesktop.hpp"
-
-sys::ReturnCodes EndpointHandler::factory(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::post)) {
- json11::Json responseBodyJson;
-
- if (body[ParserStateMachine::json::factoryRequest] == true) {
- auto msg = std::make_shared<sdesktop::FactoryMessage>();
- sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerService);
-
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, true}});
- }
- else {
- responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, false}});
- }
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::factory)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Success;
- }
- else {
- json11::Json responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, false}});
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::factory)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::BadRequest)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Failure;
- }
-}
D module-services/service-desktop/endpoints/Update.cpp => module-services/service-desktop/endpoints/Update.cpp +0 -54
@@ 1,54 0,0 @@
-#include "EndpointHandler.hpp"
-
-static sys::ReturnCodes run(uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- std::string fileName = body["fileName"].string_value();
-
- json11::Json responseBodyJson = json11::Json::object({{ParserStateMachine::json::updateReady, true}});
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::update)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- auto msg = std::make_shared<sdesktop::UpdateOsMessage>(fileName, uuid);
- sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerService);
-
- return sys::ReturnCodes::Success;
-}
-
-static sys::ReturnCodes getUpdates(uint32_t uuid,
- json11::Json &body,
- std::string &responseStr,
- sys::Service *ownerService)
-{
- json11::Json fileList = vfs.listdir(purefs::dir::os_updates.c_str(), updateos::extension::update, true);
-
- json11::Json responseBodyJson = json11::Json::object{{ParserStateMachine::json::updateFileList, fileList}};
-
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::update)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
-
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Success;
-}
-
-sys::ReturnCodes EndpointHandler::update(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
-{
- if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::post)) {
- return run(uuid, body, responseStr, ownerService);
- }
- else if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::get)) {
- return getUpdates(uuid, body, responseStr, ownerService);
- }
-
- return sys::ReturnCodes::Failure;
-}
A module-services/service-desktop/endpoints/backup/BackupEndpoint.cpp => module-services/service-desktop/endpoints/backup/BackupEndpoint.cpp +71 -0
@@ 0,0 1,71 @@
+#include "BackupEndpoint.hpp"
+#include "ParserUtils.hpp"
+#include "DesktopMessages.hpp"
+#include "ServiceDesktop.hpp"
+
+static bool backupReady = false;
+
+auto BackupEndpoint::handle(Context &context) -> std::string
+{
+ switch (context.getMethod()) {
+ case http::Method::get:
+ upload(context);
+ break;
+ case http::Method::post:
+ request(context);
+ break;
+ case http::Method::put:
+ [[fallthrough]];
+ case http::Method::del:
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ sys::ReturnCodes::Failure, static_cast<int>(EndpointType::backup), context.getUuid(), json11::Json()));
+ break;
+ }
+
+ return std::string();
+}
+auto BackupEndpoint::request(Context &context) -> sys::ReturnCodes
+{
+ json11::Json responseBodyJson;
+
+ if (context.getBody()[json::backupRequest] == true) {
+ auto msg = std::make_shared<sdesktop::BackupMessage>();
+ sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerServicePtr);
+ backupReady = true;
+
+ responseBodyJson = json11::Json::object({{json::backupRequest, true}});
+ }
+ else {
+ responseBodyJson = json11::Json::object({{json::backupRequest, false}});
+ }
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::backup), context.getUuid(), responseBodyJson));
+
+ return sys::ReturnCodes::Success;
+}
+
+auto BackupEndpoint::upload(Context &context) -> sys::ReturnCodes
+{
+ json11::Json responseBodyJson;
+
+ if (context.getBody()[json::backupReady] == true) {
+ responseBodyJson = json11::Json::object({{json::backupReady, backupReady}});
+ }
+ else if (context.getBody()[json::backupUpload] == true) {
+ if (vfs.fileExists(purefs::dir::os_backup.c_str())) {
+ responseBodyJson = json11::Json::object({{json::backupUpload, true}});
+ }
+ else {
+ responseBodyJson = json11::Json::object({{json::backupUpload, false}});
+ }
+ }
+ else {
+ responseBodyJson = json11::Json::object({{json::backupReady, false}});
+ }
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::backup), context.getUuid(), responseBodyJson));
+
+ return sys::ReturnCodes::Success;
+}
A module-services/service-desktop/endpoints/backup/BackupEndpoint.hpp => module-services/service-desktop/endpoints/backup/BackupEndpoint.hpp +17 -0
@@ 0,0 1,17 @@
+#include "Endpoint.hpp"
+#include "ParserUtils.hpp"
+#include "ServiceDesktop.hpp"
+
+using namespace ParserStateMachine;
+
+class BackupEndpoint : public Endpoint
+{
+ public:
+ BackupEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ {
+ debugName = "BackupEndpoint";
+ }
+ auto handle(Context &context) -> std::string override;
+ auto request(Context &context) -> sys::ReturnCodes;
+ auto upload(Context &context) -> sys::ReturnCodes;
+};
R module-services/service-desktop/backup-restore/BackupRestore.cpp => module-services/service-desktop/endpoints/backup/BackupRestore.cpp +0 -0
R module-services/service-desktop/backup-restore/BackupRestore.hpp => module-services/service-desktop/endpoints/backup/BackupRestore.hpp +0 -0
A module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp => module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +49 -0
@@ 0,0 1,49 @@
+#include "DeviceInfoEndpoint.hpp"
+#include <source/version.hpp>
+#include <vfs.hpp>
+#include <common_data/EventStore.hpp>
+#include <time/time_conversion.hpp>
+#include <service-desktop/ServiceDesktop.hpp>
+#include <string>
+
+time_t FreeRTOS_time(time_t *pxTime)
+{
+ return utils::time::Time().getTime();
+}
+
+auto DeviceInfoEndpoint::handle(Context &context) -> std::string
+{
+ switch (context.getMethod()) {
+ case http::Method::get:
+ getDeviceInfo(context);
+ break;
+ default:
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ sys::ReturnCodes::Failure, static_cast<int>(EndpointType::deviceInfo), context.getUuid(), json11::Json()));
+ break;
+ }
+
+ return std::string();
+}
+auto DeviceInfoEndpoint::getDeviceInfo(Context &context) -> bool
+{
+ vfs::FilesystemStats fsStats = vfs.getFilesystemStats();
+
+ json11::Json responseBodyJson = json11::Json::object(
+ {{json::batteryLevel, std::to_string(Store::Battery::get().level)},
+ {json::batteryState, std::to_string(static_cast<int>(Store::Battery::get().state))},
+ {json::selectedSim, std::to_string(static_cast<int>(Store::GSM::get()->selected))},
+ {json::trayState, std::to_string(static_cast<int>(Store::GSM::get()->tray))},
+ {json::signalStrength, std::to_string(static_cast<int>(Store::GSM::get()->getSignalStrength().rssiBar))},
+ {json::fsTotal, std::to_string(fsStats.totalMbytes)},
+ {json::fsFree, std::to_string(fsStats.freeMbytes)},
+ {json::fsFreePercent, std::to_string(fsStats.freePercent)},
+ {json::gitRevision, (std::string)(GIT_REV)},
+ {json::gitTag, (std::string)GIT_TAG},
+ {json::gitBranch, (std::string)GIT_BRANCH},
+ {json::currentRTCTime, std::to_string(static_cast<uint32_t>(utils::time::Time().getTime()))}});
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::deviceInfo), context.getUuid(), responseBodyJson));
+ return true;
+}
A module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.hpp => module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.hpp +18 -0
@@ 0,0 1,18 @@
+#pragma once
+
+#include "Endpoint.hpp"
+#include "Service/Service.hpp"
+
+using namespace ParserStateMachine;
+
+class DeviceInfoEndpoint : public Endpoint
+{
+
+ public:
+ DeviceInfoEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ {
+ debugName = "DeviceInfoEndpoint";
+ }
+ auto handle(Context &context) -> std::string override;
+ auto getDeviceInfo(Context &context) -> bool;
+};
R module-services/service-desktop/factory-reset/FactoryReset.cpp => module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp +0 -0
R module-services/service-desktop/factory-reset/FactoryReset.hpp => module-services/service-desktop/endpoints/factoryReset/FactoryReset.hpp +0 -0
A module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.cpp => module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.cpp +33 -0
@@ 0,0 1,33 @@
+#include "FactoryResetEndpoint.hpp"
+#include "DesktopMessages.hpp"
+#include "ServiceDesktop.hpp"
+
+auto FactoryResetEndpoint::handle(Context &context) -> std::string
+{
+ if (context.getMethod() == ParserStateMachine::http::Method::post) {
+ json11::Json responseBodyJson;
+
+ if (context.getBody()[ParserStateMachine::json::factoryRequest] == true) {
+ auto msg = std::make_shared<sdesktop::FactoryMessage>();
+ sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerServicePtr);
+
+ responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, true}});
+ }
+ else {
+ responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, false}});
+ }
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ sys::ReturnCodes::Success, static_cast<int>(EndpointType::factory), context.getUuid(), json11::Json()));
+
+ return std::string();
+ }
+ else {
+ json11::Json responseBodyJson = json11::Json::object({{ParserStateMachine::json::factoryRequest, false}});
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ sys::ReturnCodes::Failure, static_cast<int>(EndpointType::factory), context.getUuid(), json11::Json()));
+
+ return std::string();
+ }
+}
A module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.hpp => module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.hpp +18 -0
@@ 0,0 1,18 @@
+#pragma once
+
+#include "Endpoint.hpp"
+#include "Service/Service.hpp"
+
+using namespace ParserStateMachine;
+
+class FactoryResetEndpoint : public Endpoint
+{
+
+ public:
+ FactoryResetEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ {
+ debugName = "FactoryResetEndpoint";
+ }
+ auto handle(Context &context) -> std::string override;
+ auto makeFactoryReset(Context &context) -> bool;
+};
R module-services/service-desktop/endpoints/Restore.cpp => module-services/service-desktop/endpoints/restore/RestoreEndpoint.cpp +9 -15
@@ 1,17 1,16 @@
-#include "EndpointHandler.hpp"
#include "ParserUtils.hpp"
#include "DesktopMessages.hpp"
#include "ServiceDesktop.hpp"
+#include "RestoreEndpoint.hpp"
-sys::ReturnCodes EndpointHandler::restore(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService)
+auto RestoreEndpoint::handle(Context &context) -> std::string
{
- if (httpMethod == static_cast<uint8_t>(ParserStateMachine::http::Method::post)) {
+ if (context.getMethod() == ParserStateMachine::http::Method::post) {
json11::Json responseBodyJson;
- if (body[ParserStateMachine::json::restoreRequest] == true) {
+ if (context.getBody()[ParserStateMachine::json::restoreRequest] == true) {
auto msg = std::make_shared<sdesktop::RestoreMessage>();
- sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerService);
+ sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerServicePtr);
responseBodyJson = json11::Json::object({{ParserStateMachine::json::restoreRequest, true}});
}
@@ 19,17 18,12 @@ sys::ReturnCodes EndpointHandler::restore(
responseBodyJson = json11::Json::object({{ParserStateMachine::json::restoreRequest, false}});
}
- json11::Json responsePayloadJson = json11::Json::object(
- {{ParserStateMachine::json::endpoint, static_cast<int>(ParserStateMachine::Endpoint::restore)},
- {ParserStateMachine::json::status, static_cast<int>(ParserStateMachine::http::Code::OK)},
- {ParserStateMachine::json::uuid, std::to_string(uuid)},
- {ParserStateMachine::json::body, responseBodyJson}});
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::restore), context.getUuid(), responseBodyJson));
- responseStr = EndpointHandler::buildResponseStr(responsePayloadJson.dump().size(), responsePayloadJson.dump());
-
- return sys::ReturnCodes::Success;
+ return std::string();
}
else {
- return sys::ReturnCodes::Failure;
+ return std::string();
}
}
A module-services/service-desktop/endpoints/restore/RestoreEndpoint.hpp => module-services/service-desktop/endpoints/restore/RestoreEndpoint.hpp +15 -0
@@ 0,0 1,15 @@
+#include "Endpoint.hpp"
+#include "ParserUtils.hpp"
+#include "ServiceDesktop.hpp"
+
+using namespace ParserStateMachine;
+
+class RestoreEndpoint : public Endpoint
+{
+ public:
+ RestoreEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ {
+ debugName = "RestoreEndpoint";
+ }
+ auto handle(Context &context) -> std::string override;
+};
A module-services/service-desktop/endpoints/update/UpdateEndpoint.cpp => module-services/service-desktop/endpoints/update/UpdateEndpoint.cpp +46 -0
@@ 0,0 1,46 @@
+
+#include "UpdateEndpoint.hpp"
+#include "DesktopMessages.hpp"
+#include "ServiceDesktop.hpp"
+
+auto UpdateEndpoint::handle(Context &context) -> std::string
+{
+ switch (context.getMethod()) {
+ case http::Method::post:
+ run(context);
+ break;
+ case http::Method::get:
+ getUpdates(context);
+ break;
+ default:
+ break;
+ }
+ return std::string();
+}
+
+auto UpdateEndpoint::run(Context &context) -> sys::ReturnCodes
+{
+ std::string fileName = context.getBody()["fileName"].string_value();
+
+ json11::Json responseBodyJson = json11::Json::object({{ParserStateMachine::json::updateReady, true}});
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::update), context.getUuid(), responseBodyJson));
+
+ auto msg = std::make_shared<sdesktop::UpdateOsMessage>(fileName, context.getUuid());
+ sys::Bus::SendUnicast(msg, service::name::service_desktop, ownerServicePtr);
+
+ return sys::ReturnCodes::Success;
+}
+
+auto UpdateEndpoint::getUpdates(Context &context) -> sys::ReturnCodes
+{
+ json11::Json fileList = vfs.listdir(purefs::dir::os_updates.c_str(), updateos::extension::update, true);
+
+ json11::Json responseBodyJson = json11::Json::object{{ParserStateMachine::json::updateFileList, fileList}};
+
+ MessageHandler::putToSendQueue(Endpoint::createSimpleResponse(
+ true, static_cast<int>(EndpointType::update), context.getUuid(), responseBodyJson));
+
+ return sys::ReturnCodes::Success;
+}
A module-services/service-desktop/endpoints/update/UpdateEndpoint.hpp => module-services/service-desktop/endpoints/update/UpdateEndpoint.hpp +19 -0
@@ 0,0 1,19 @@
+#pragma once
+
+#include "Endpoint.hpp"
+#include "Service/Service.hpp"
+
+using namespace ParserStateMachine;
+
+class UpdateEndpoint : public Endpoint
+{
+
+ public:
+ UpdateEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ {
+ debugName = "UpdateEndpoint";
+ }
+ auto handle(Context &context) -> std::string override;
+ auto run(Context &context) -> sys::ReturnCodes;
+ auto getUpdates(Context &context) -> sys::ReturnCodes;
+};
R module-services/service-desktop/update/UpdatePureOS.cpp => module-services/service-desktop/endpoints/update/UpdatePureOS.cpp +0 -0
R module-services/service-desktop/update/UpdatePureOS.hpp => module-services/service-desktop/endpoints/update/UpdatePureOS.hpp +0 -1
@@ 89,7 89,6 @@ class UpdatePureOS
const fs::path getUpdateTmpChild(const fs::path &childPath);
private:
-
fs::path updateTempDirectory;
std::vector<FileInfo> filesInUpdatePackage;
mtar_t updateTar = {};
D module-services/service-desktop/factory-reset/CMakeLists.txt => module-services/service-desktop/factory-reset/CMakeLists.txt +0 -13
@@ 1,13 0,0 @@
-target_include_directories(${PROJECT_NAME}
- PUBLIC
- "${CMAKE_CURRENT_LIST_DIR}"
-)
-target_include_directories(${CMAKE_PROJECT_NAME}
- PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}
- ${CMAKE_BINARY_DIR}
- )
-target_sources(${PROJECT_NAME}
- PRIVATE
- "FactoryReset.cpp"
-)
M module-services/service-desktop/parser/CMakeLists.txt => module-services/service-desktop/parser/CMakeLists.txt +0 -1
@@ 5,7 5,6 @@ target_include_directories(${PROJECT_NAME}
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_sources(${PROJECT_NAME}
PRIVATE
- "${CMAKE_CURRENT_LIST_DIR}/EndpointHandler.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ParserStateMachine.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ParserUtils.cpp"
"${CMAKE_CURRENT_LIST_DIR}/MessageHandler.cpp"
D module-services/service-desktop/parser/EndpointHandler.cpp => module-services/service-desktop/parser/EndpointHandler.cpp +0 -123
@@ 1,123 0,0 @@
-#include "EndpointHandler.hpp"
-#include "ParserUtils.hpp"
-#include "SMSRecord.hpp"
-#include "Service/Common.hpp"
-#include "Service/Service.hpp"
-#include "log/log.hpp"
-#include "messages/DBContactMessage.hpp"
-#include "messages/DBSMSMessage.hpp"
-#include "messages/DBSMSTemplateMessage.hpp"
-#include "messages/MessageHelper.hpp"
-#include "messages/QueryMessage.hpp"
-#include "queries/phonebook/QueryContactGet.hpp"
-#include "queries/sms/QuerySMSGetByID.hpp"
-#include "queries/sms/QuerySMSGetByContactID.hpp"
-#include "queries/sms/QuerySMSGetByText.hpp"
-#include "queries/sms/QuerySMSSearch.hpp"
-#include "queries/sms/QuerySMSTemplateGetByID.hpp"
-#include "queries/sms/QuerySmsThreadMarkAsRead.hpp"
-#include "json/json11.hpp"
-#include <string>
-
-using namespace ParserStateMachine;
-
-// sys::ReturnCodes EndpointHandler::handleContactsMessage(sys::DataMessage *msg, sys::ResponseMessage *resp)
-// {
-// LOG_DEBUG("resp->ResponseTo: %d", static_cast<short>(resp->responseTo));
-
-// if (dynamic_cast<DBContactResponseMessage *>(resp) != nullptr &&
-// resp->responseTo == MessageType::DBContactGetByID) {
-
-// auto status = contactHelper->updateContact(dynamic_cast<DBContactResponseMessage *>(resp)->records->front());
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// status, static_cast<int>(Endpoint::contacts), contactHelper->getLastUUID()));
-// }
-// else if (dynamic_cast<DBContactResponseMessage *>(resp) != nullptr &&
-// resp->responseTo == MessageType::DBContactAdd) {
-
-// LOG_DEBUG("Contact added! ret: %d", (resp->retCode == sys::ReturnCodes::Success ? 1 : 0));
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::contacts), contactHelper->getLastUUID()));
-// }
-// else if (dynamic_cast<DBContactResponseMessage *>(resp) != nullptr &&
-// resp->responseTo == MessageType::DBContactRemove) {
-
-// LOG_DEBUG("Contact removed! ret: %d", (resp->retCode == sys::ReturnCodes::Success ? 1 : 0));
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::contacts), contactHelper->getLastUUID()));
-// }
-
-// return sys::ReturnCodes::Success;
-// }
-
-// sys::ReturnCodes EndpointHandler::handleMessagesMessage(sys::DataMessage *msg, sys::ResponseMessage *resp)
-// {
-// LOG_DEBUG("resp->ResponseTo: %d", static_cast<short>(resp->responseTo));
-
-// if (resp->responseTo == MessageType::DBSMSGetCount) {
-
-// auto response = dynamic_cast<DBSMSResponseMessage *>(resp);
-// LOG_DEBUG("SMS count: %" PRIu32 "", response->count);
-// json11::Json body = json11::Json::object{{json::messages::count, static_cast<int>(response->count)}};
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID(), body));
-// }
-// else if (resp->responseTo == MessageType::DBSMSGetSMSLimitOffset ||
-// resp->responseTo == MessageType::DBSMSGetSMSLimitOffsetByThreadID) {
-
-// auto response = dynamic_cast<DBSMSResponseMessage *>(resp);
-// auto records = std::move(response->records);
-
-// json11::Json::array recordsArray;
-// for (auto record : *records) {
-// recordsArray.emplace_back(messageHelper->to_json(record));
-// }
-
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID(), recordsArray));
-// }
-// else if (resp->responseTo == MessageType::DBSMSRemove) {
-
-// LOG_DEBUG("SMS removed");
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID()));
-// }
-
-// return sys::ReturnCodes::Success;
-// }
-
-// sys::ReturnCodes EndpointHandler::handleMessageTemplatesMessage(sys::DataMessage *msg, sys::ResponseMessage *resp)
-// {
-// LOG_DEBUG("resp->ResponseTo: %d", static_cast<short>(resp->responseTo));
-
-// if (resp->responseTo == MessageType::DBSMSTemplateGetCount) {
-
-// auto response = dynamic_cast<DBSMSTemplateResponseMessage *>(resp);
-// LOG_DEBUG("SMS Template count: %" PRIu32 "", response->count);
-// json11::Json body = json11::Json::object{{json::messages::count, static_cast<int>(response->count)}};
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID(), body));
-// }
-// else if (resp->responseTo == MessageType::DBSMSTemplateGetLimitOffset) {
-
-// auto response = dynamic_cast<DBSMSTemplateResponseMessage *>(resp);
-// auto records = std::move(response->records);
-
-// json11::Json::array recordsArray;
-// for (auto record : *records) {
-// recordsArray.emplace_back(messageHelper->to_json(record));
-// }
-
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID(), recordsArray));
-// }
-// else if (resp->responseTo == MessageType::DBSMSTemplateAdd ||
-// resp->responseTo == MessageType::DBSMSTemplateRemove ||
-// resp->responseTo == MessageType::DBSMSTemplateUpdate) {
-
-// MessageHandler::putToSendQueue(EndpointHandler::createSimpleResponse(
-// resp->retCode, static_cast<int>(Endpoint::messages), messageHelper->getLastUUID()));
-// }
-
-// return sys::ReturnCodes::Success;
-// }
D module-services/service-desktop/parser/EndpointHandler.hpp => module-services/service-desktop/parser/EndpointHandler.hpp +0 -42
@@ 1,42 0,0 @@
-#pragma once
-
-#include <json/json11.hpp>
-#include "Service/Service.hpp"
-#include "ParserUtils.hpp"
-#include "Service/Common.hpp"
-#include <service-desktop/ServiceDesktop.hpp>
-#include <string>
-#include "DBHelper.hpp"
-#include "queries/phonebook/QueryContactGet.hpp"
-
-using namespace ParserStateMachine;
-
-class EndpointHandler
-{
- public:
- static void initHelpers(sys::Service *ownerService);
-
- static sys::ReturnCodes handleQueryMessage(sys::DataMessage *msg, sys::ResponseMessage *resp);
- static sys::ReturnCodes handleContactsMessage(sys::DataMessage *msg, sys::ResponseMessage *resp);
- static sys::ReturnCodes handleMessagesMessage(sys::DataMessage *msg, sys::ResponseMessage *resp);
- static sys::ReturnCodes handleMessageTemplatesMessage(sys::DataMessage *msg, sys::ResponseMessage *resp);
-
- static sys::ReturnCodes decodeMessage(db::query::ContactGetResult *message);
-
- static sys::ReturnCodes update(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes deviceInfo(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes backup(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes restore(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes factory(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes contacts(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
- static sys::ReturnCodes messages(
- uint8_t httpMethod, uint32_t uuid, json11::Json &body, std::string &responseStr, sys::Service *ownerService);
-
- private:
-};
M module-services/service-desktop/tests/CMakeLists.txt => module-services/service-desktop/tests/CMakeLists.txt +2 -3
@@ 7,10 7,9 @@ add_catch2_executable(
SRCS
"${CMAKE_CURRENT_LIST_DIR}/unittest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/tests-main.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/../update/UpdatePureOS.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/../factory-reset/FactoryReset.cpp"
+ "../endpoints/update/UpdatePureOS.cpp"
+ "../endpoints/factoryReset/FactoryReset.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../parser/MessageHandler.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/../parser/EndpointHandler.cpp"
LIBS
M module-services/service-desktop/tests/unittest.cpp => module-services/service-desktop/tests/unittest.cpp +2 -2
@@ 4,8 4,8 @@
#include "MessageType.hpp"
#include "ParserUtils.hpp"
#include "Service/Common.hpp"
-#include "UpdatePureOS.hpp"
-#include "FactoryReset.hpp"
+#include "module-services/service-desktop/endpoints/update/UpdatePureOS.hpp"
+#include "module-services/service-desktop/endpoints/factoryReset/FactoryReset.hpp"
#include "ParserStateMachine.hpp"
#include "contacts/ContactHelper.hpp"
#include "messages/MessageHelper.hpp"
D module-services/service-desktop/update/CMakeLists.txt => module-services/service-desktop/update/CMakeLists.txt +0 -12
@@ 1,12 0,0 @@
-target_include_directories(${PROJECT_NAME}
- PUBLIC
- "${CMAKE_CURRENT_LIST_DIR}"
-)
-target_include_directories(${PROJECT_NAME}
- PUBLIC
- ${CMAKE_BINARY_DIR})
-target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
-target_sources(${PROJECT_NAME}
- PRIVATE
- "UpdatePureOS.cpp"
-)