M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +1 -1
@@ 176,7 176,7 @@ sys::ReturnCodes ServiceDesktop::InitHandler()
}
if (updateOsMsg != nullptr && updateOsMsg->messageType == updateos::UpdateMessageType::UpdateNow) {
- LOG_DEBUG("ServiceDesktop::DataReceivedHandler file:%s uuuid:%" PRIu32 "",
+ LOG_DEBUG("ServiceDesktop::DataReceivedHandler file:%s uuid:%" PRIu32 "",
updateOsMsg->updateStats.updateFile.c_str(),
updateOsMsg->updateStats.uuid);
M module-services/service-desktop/endpoints/Context.hpp => module-services/service-desktop/endpoints/Context.hpp +13 -6
@@ 4,6 4,7 @@
#pragma once
#include <module-services/service-desktop/parser/ParserUtils.hpp>
+#include <utility>
#include "ResponseContext.hpp"
namespace parserFSM
@@ 40,7 41,7 @@ namespace parserFSM
auto validate() -> void
{
- if (body.is_object() == false) {
+ if (!body.is_object()) {
body = json11::Json();
}
if (static_cast<int>(endpoint) > lastEndpoint) {
@@ 83,16 84,22 @@ namespace parserFSM
virtual auto createSimpleResponse(const std::string &entryTitle = json::entries) -> std::string
{
- json11::Json responseJson = json11::Json::object{{json::endpoint, static_cast<int>(getEndpoint())},
- {json::status, static_cast<int>(responseContext.status)},
- {json::uuid, getUuid()},
- {json::body, responseContext.body}};
+ json11::Json::object contextJsonObject =
+ json11::Json::object{{json::endpoint, static_cast<int>(getEndpoint())},
+ {json::status, static_cast<int>(responseContext.status)},
+ {json::uuid, getUuid()}};
+ if (!responseContext.body.is_null()) {
+ contextJsonObject[json::body] = responseContext.body;
+ }
+
+ const json11::Json responseJson{std::move(contextJsonObject)};
+
return buildResponseStr(responseJson.dump().size(), responseJson.dump());
}
auto setResponse(endpoint::ResponseContext r)
{
- responseContext = r;
+ responseContext = std::move(r);
}
auto setResponseStatus(http::Code status)
M module-services/service-desktop/endpoints/DBHelper.hpp => module-services/service-desktop/endpoints/DBHelper.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 22,7 22,7 @@ namespace parserFSM
virtual auto updateDBEntry(Context &context) -> sys::ReturnCodes = 0;
virtual auto deleteDBEntry(Context &context) -> sys::ReturnCodes = 0;
- DBHelper(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
+ explicit DBHelper(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
virtual ~DBHelper() = default;
protected:
M module-services/service-desktop/endpoints/Endpoint.hpp => module-services/service-desktop/endpoints/Endpoint.hpp +2 -2
@@ 19,7 19,7 @@ namespace parserFSM
class Endpoint
{
public:
- Endpoint(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
+ explicit Endpoint(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
virtual ~Endpoint() = default;
virtual auto handle(parserFSM::Context &context) -> void = 0;
auto c_str() -> const char *
@@ 28,7 28,7 @@ namespace parserFSM
}
protected:
- std::string debugName = "";
+ std::string debugName;
sys::Service *ownerServicePtr = nullptr;
};
M module-services/service-desktop/endpoints/calendarEvents/CalendarEventsEndpoint.hpp => module-services/service-desktop/endpoints/calendarEvents/CalendarEventsEndpoint.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 14,7 14,7 @@ class CalendarEventsEndpoint : public parserFSM::Endpoint
std::unique_ptr<parserFSM::CalendarEventsHelper> helper;
public:
- CalendarEventsEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
+ explicit CalendarEventsEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
{
helper = std::make_unique<parserFSM::CalendarEventsHelper>(ownerServicePtr);
}
M module-services/service-desktop/endpoints/calendarEvents/CalendarEventsHelper.cpp => module-services/service-desktop/endpoints/calendarEvents/CalendarEventsHelper.cpp +6 -6
@@ 83,7 83,7 @@ namespace parserFSM
} // namespace parserFSM
using namespace parserFSM;
-auto CalendarEventsHelper::isICalEventValid(ICalEvent icalEvent) const -> bool
+auto CalendarEventsHelper::isICalEventValid(const ICalEvent &icalEvent) const -> bool
{
if (!icalEvent.event.isValid) {
LOG_ERROR("Ical event invalid!");
@@ 196,7 196,7 @@ auto CalendarEventsHelper::icalEventFrom(const EventsRecord &record) const -> IC
return ICalEvent{event, alarm, rrule};
}
-auto CalendarEventsHelper::eventJsonObjectFrom(EventsRecord record) const -> json11::Json
+auto CalendarEventsHelper::eventJsonObjectFrom(const EventsRecord &record) const -> json11::Json
{
auto icalEvent = icalEventFrom(record);
if (!isICalEventValid(icalEvent)) {
@@ 325,7 325,7 @@ auto CalendarEventsHelper::eventsRecordFrom(ICalEvent &icalEvent) const -> Event
return record;
}
-auto CalendarEventsHelper::ICalEventFromJson(json11::Json eventObj) const -> ICalEvent
+auto CalendarEventsHelper::ICalEventFromJson(const json11::Json &eventObj) const -> ICalEvent
{
ICalEvent icalEvent;
icalEvent.event.setUID(eventObj[json::calendar::event::uid].string_value());
@@ 358,7 358,7 @@ auto CalendarEventsHelper::createDBEntry(Context &context) -> sys::ReturnCodes
const auto eventsJsonObj = context.getBody();
const auto eventsJsonArray = eventsJsonObj[json::calendar::events].array_items();
bool ret = true;
- for (auto event : eventsJsonArray) {
+ for (const auto &event : eventsJsonArray) {
auto icalEvent = ICalEventFromJson(event);
@@ 415,7 415,7 @@ auto CalendarEventsHelper::updateDBEntry(Context &context) -> sys::ReturnCodes
auto eventsJsonObj = context.getBody();
bool ret = true;
- for (auto event : eventsJsonObj[json::calendar::events].array_items()) {
+ for (const auto &event : eventsJsonObj[json::calendar::events].array_items()) {
auto icalEvent = ICalEventFromJson(event);
if (!isICalEventValid(icalEvent) || icalEvent.event.getUID().empty()) {
@@ 429,7 429,7 @@ auto CalendarEventsHelper::updateDBEntry(Context &context) -> sys::ReturnCodes
auto listener = std::make_unique<db::EndpointListener>(
[](db::QueryResult *result, Context context) {
if (auto EventResult = dynamic_cast<db::query::events::EditICSResult *>(result)) {
- context.setResponseStatus(EventResult->getResult() ? http::Code::OK
+ context.setResponseStatus(EventResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
M module-services/service-desktop/endpoints/calendarEvents/CalendarEventsHelper.hpp => module-services/service-desktop/endpoints/calendarEvents/CalendarEventsHelper.hpp +5 -5
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 29,12 29,12 @@ namespace parserFSM
[[nodiscard]] auto repeatFrom(RecurrenceRule &rrule) const -> Repeat;
[[nodiscard]] auto eventsRecordFrom(ICalEvent &icalEvent) const -> EventsRecord;
- [[nodiscard]] auto eventJsonObjectFrom(EventsRecord record) const -> json11::Json;
- [[nodiscard]] auto ICalEventFromJson(json11::Json eventObj) const -> ICalEvent;
- [[nodiscard]] auto isICalEventValid(ICalEvent event) const -> bool;
+ [[nodiscard]] auto eventJsonObjectFrom(const EventsRecord &record) const -> json11::Json;
+ [[nodiscard]] auto ICalEventFromJson(const json11::Json &eventObj) const -> ICalEvent;
+ [[nodiscard]] auto isICalEventValid(const ICalEvent &event) const -> bool;
public:
- CalendarEventsHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr)
+ explicit CalendarEventsHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr)
{}
auto createDBEntry(Context &context) -> sys::ReturnCodes override;
M module-services/service-desktop/endpoints/calllog/CalllogEndpoint.hpp => module-services/service-desktop/endpoints/calllog/CalllogEndpoint.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 26,7 26,7 @@ class CalllogEndpoint : public parserFSM::Endpoint
std::unique_ptr<parserFSM::CalllogHelper> helper;
public:
- CalllogEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
+ explicit CalllogEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
{
debugName = "CalllogEndpoint";
helper = std::make_unique<parserFSM::CalllogHelper>(ownerServicePtr);
M module-services/service-desktop/endpoints/calllog/CalllogHelper.cpp => module-services/service-desktop/endpoints/calllog/CalllogHelper.cpp +3 -3
@@ 47,7 47,7 @@ auto CalllogHelper::requestDataFromDB(Context &context) -> sys::ReturnCodes
auto recordsPtr = std::make_unique<std::vector<CalllogRecord>>(contactResult->getRecords());
json11::Json::array calllogArray;
- for (auto record : *recordsPtr.get()) {
+ for (const auto &record : *recordsPtr) {
calllogArray.emplace_back(CalllogHelper::to_json(record));
}
@@ 102,7 102,7 @@ auto CalllogHelper::getCalllogByContactID(Context &context) -> sys::ReturnCodes
auto records = calllogResult->getResults();
json11::Json::array calllogArray;
- for (auto record : records) {
+ for (const auto &record : records) {
calllogArray.emplace_back(CalllogHelper::to_json(record));
}
@@ 133,7 133,7 @@ auto CalllogHelper::deleteDBEntry(Context &context) -> sys::ReturnCodes
[](db::QueryResult *result, Context context) {
if (auto calllogResult = dynamic_cast<db::query::CalllogRemoveResult *>(result)) {
- context.setResponseStatus(calllogResult->getResults() ? http::Code::OK
+ context.setResponseStatus(calllogResult->getResults() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
M module-services/service-desktop/endpoints/calllog/CalllogHelper.hpp => module-services/service-desktop/endpoints/calllog/CalllogHelper.hpp +1 -1
@@ 27,7 27,7 @@ namespace parserFSM
class CalllogHelper : public DBHelper
{
public:
- CalllogHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr){};
+ explicit CalllogHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr){};
auto createDBEntry(Context &context) -> sys::ReturnCodes override;
auto requestDataFromDB(Context &context) -> sys::ReturnCodes override;
M module-services/service-desktop/endpoints/contacts/ContactHelper.cpp => module-services/service-desktop/endpoints/contacts/ContactHelper.cpp +7 -7
@@ 30,11 30,11 @@
using namespace parserFSM;
-auto ContactHelper::to_json(ContactRecord record) -> json11::Json
+auto ContactHelper::to_json(const ContactRecord &record) -> json11::Json
{
auto numberArray = json11::Json::array();
- for (auto number : record.numbers) {
+ for (const auto &number : record.numbers) {
numberArray.emplace_back(number.number.getEntered().c_str());
}
@@ 48,7 48,7 @@ auto ContactHelper::to_json(ContactRecord record) -> json11::Json
return recordEntry;
}
-auto ContactHelper::from_json(json11::Json contactJSON) -> ContactRecord
+auto ContactHelper::from_json(const json11::Json &contactJSON) -> ContactRecord
{
auto newRecord = ContactRecord();
newRecord.primaryName = UTF8(contactJSON[json::contacts::primaryName].string_value());
@@ 56,7 56,7 @@ auto ContactHelper::from_json(json11::Json contactJSON) -> ContactRecord
newRecord.alternativeName = UTF8(contactJSON[json::contacts::alternativeName].string_value());
newRecord.address = UTF8(contactJSON[json::contacts::address].string_value());
- for (auto num : contactJSON[json::contacts::numbers].array_items()) {
+ for (const auto &num : contactJSON[json::contacts::numbers].array_items()) {
utils::PhoneNumber phoneNumber(num.string_value());
auto contactNum = ContactRecord::Number(phoneNumber.get(), phoneNumber.toE164(), ContactNumberType ::CELL);
newRecord.numbers.push_back(contactNum);
@@ 91,7 91,7 @@ auto ContactHelper::requestDataFromDB(Context &context) -> sys::ReturnCodes
context.setTotalCount(contactResult->getAllLength());
json11::Json::array contactsArray;
- for (const auto &record : *recordsPtr.get()) {
+ for (const auto &record : *recordsPtr) {
contactsArray.emplace_back(ContactHelper::to_json(record));
}
@@ 215,7 215,7 @@ auto ContactHelper::updateDBEntry(Context &context) -> sys::ReturnCodes
[](db::QueryResult *result, Context context) {
if (auto contactResult = dynamic_cast<db::query::ContactUpdateResult *>(result)) {
- context.setResponseStatus(contactResult->getResult() ? http::Code::OK
+ context.setResponseStatus(contactResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
@@ 242,7 242,7 @@ auto ContactHelper::deleteDBEntry(Context &context) -> sys::ReturnCodes
[](db::QueryResult *result, Context context) {
if (auto contactResult = dynamic_cast<db::query::ContactRemoveResult *>(result)) {
- context.setResponseStatus(contactResult->getResult() ? http::Code::OK
+ context.setResponseStatus(contactResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
M module-services/service-desktop/endpoints/contacts/ContactHelper.hpp => module-services/service-desktop/endpoints/contacts/ContactHelper.hpp +3 -3
@@ 28,7 28,7 @@ namespace parserFSM
{
public:
- ContactHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr)
+ explicit ContactHelper(sys::Service *_ownerServicePtr) : DBHelper(_ownerServicePtr)
{}
auto createDBEntry(Context &context) -> sys::ReturnCodes override;
@@ 38,8 38,8 @@ namespace parserFSM
auto requestCount(Context &context) -> sys::ReturnCodes;
auto requestContactByID(Context &context) -> sys::ReturnCodes;
- static auto to_json(ContactRecord record) -> json11::Json;
- static auto from_json(json11::Json contactJSON) -> ContactRecord;
+ static auto to_json(const ContactRecord &record) -> json11::Json;
+ static auto from_json(const json11::Json &contactJSON) -> ContactRecord;
};
namespace json::contacts
M module-services/service-desktop/endpoints/contacts/ContactsEndpoint.hpp => module-services/service-desktop/endpoints/contacts/ContactsEndpoint.hpp +1 -1
@@ 28,7 28,7 @@ class ContactsEndpoint : public parserFSM::Endpoint
std::unique_ptr<parserFSM::ContactHelper> helper;
public:
- ContactsEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
+ explicit ContactsEndpoint(sys::Service *_ownerServicePtr) : Endpoint(_ownerServicePtr)
{
debugName = "ContactsEndpoint";
helper = std::make_unique<parserFSM::ContactHelper>(ownerServicePtr);
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +18 -12
@@ 84,18 84,21 @@ auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
path.service = service::name::db;
path.scope = settings::SettingsScope::Global;
auto msg = std::make_shared<settings::Messages::SetVariable>(std::move(path), std::move(value));
- code = toCode(owner->bus.sendUnicast(std::move(msg), service::name::db));
+ code = owner->bus.sendUnicast(std::move(msg), service::name::db) ? http::Code::NoContent
+ : http::Code::InternalServerError;
+
return {sent::no, endpoint::ResponseContext{.status = code}};
}
else if (body[json::developerMode::changeSim].is_number()) {
int simSelected = body[json::developerMode::changeSim].int_value();
requestSimChange(simSelected);
- code = toCode(true);
+ code = http::Code::NoContent;
return {sent::no, endpoint::ResponseContext{.status = code}};
}
else if (body[json::developerMode::changeCellularStateCmd].is_number()) {
int cellularState = body[json::developerMode::changeCellularStateCmd].int_value();
- code = toCode(requestCellularPowerStateChange(cellularState));
+ code = requestCellularPowerStateChange(cellularState) ? http::Code::NoContent : http::Code::InternalServerError;
+
return {sent::no, endpoint::ResponseContext{.status = code}};
}
else if (body[json::developerMode::smsCommand].is_string()) {
@@ 118,7 121,8 @@ auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
else if (body[json::developerMode::phoneLockCodeEnabled].is_bool()) {
auto phoneLockState = body[json::developerMode::phoneLockCodeEnabled].bool_value();
auto msg = std::make_shared<locks::ExternalPhoneLockAvailabilityChange>(phoneLockState);
- code = toCode(owner->bus.sendUnicast(std::move(msg), "ApplicationManager"));
+ code = owner->bus.sendUnicast(std::move(msg), "ApplicationManager") ? http::Code::NoContent
+ : http::Code::InternalServerError;
}
else if (auto switchData = body[json::developerMode::switchApplication].object_items(); !switchData.empty()) {
auto msg = std::make_shared<app::manager::SwitchRequest>(
@@ 126,13 130,16 @@ auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
switchData[json::developerMode::switchData::applicationName].string_value(),
switchData[json::developerMode::switchData::windowName].string_value(),
nullptr);
- code = toCode(owner->bus.sendUnicast(std::move(msg), "ApplicationManager"));
+ code = owner->bus.sendUnicast(std::move(msg), "ApplicationManager") ? http::Code::NoContent
+ : http::Code::InternalServerError;
}
else if (auto switchData = body[json::developerMode::switchWindow].object_items(); !switchData.empty()) {
auto msg = std::make_shared<app::AppSwitchWindowMessage>(
switchData[json::developerMode::switchData::windowName].string_value(), "", nullptr);
- code = toCode(owner->bus.sendUnicast(
- std::move(msg), switchData[json::developerMode::switchData::applicationName].string_value()));
+ code = owner->bus.sendUnicast(std::move(msg),
+ switchData[json::developerMode::switchData::applicationName].string_value())
+ ? http::Code::NoContent
+ : http::Code::InternalServerError;
}
else {
@@ 157,7 164,7 @@ auto DeveloperModeHelper::processGet(Context &context) -> ProcessResult
return {sent::no, std::move(response)};
}
else if (keyValue == json::developerMode::cellularStateInfo) {
- if (requestServiceStateInfo(owner) == false) {
+ if (!requestServiceStateInfo(owner)) {
return {sent::no, endpoint::ResponseContext{.status = http::Code::NotAcceptable}};
}
else {
@@ 165,7 172,7 @@ auto DeveloperModeHelper::processGet(Context &context) -> ProcessResult
}
}
else if (keyValue == json::developerMode::cellularSleepModeInfo) {
- if (requestCellularSleepModeInfo(owner) == false) {
+ if (!requestCellularSleepModeInfo(owner)) {
return {sent::no, endpoint::ResponseContext{.status = http::Code::NotAcceptable}};
}
else {
@@ 179,7 186,6 @@ auto DeveloperModeHelper::processGet(Context &context) -> ProcessResult
else {
return {sent::no, endpoint::ResponseContext{.status = http::Code::BadRequest}};
}
- return {sent::no, std::nullopt};
}
auto DeveloperModeHelper::getKeyCode(int val) noexcept -> bsp::KeyCodes
@@ 247,7 253,7 @@ bool DeveloperModeHelper::sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::S
gui::InputEvent event(key, state, static_cast<gui::KeyCode>(keyCode));
LOG_INFO("Sending %s", event.str().c_str());
- auto message = std::make_shared<app::AppInputEventMessage>(std::move(event));
+ auto message = std::make_shared<app::AppInputEventMessage>(event);
return owner->bus.sendUnicast(std::move(message), service::name::evt_manager);
}
@@ 275,7 281,7 @@ bool DeveloperModeHelper::requestCellularPowerStateChange(const int cellularStat
}
return res;
}
-auto DeveloperModeHelper::smsRecordFromJson(json11::Json msgJson) -> SMSRecord
+auto DeveloperModeHelper::smsRecordFromJson(const json11::Json &msgJson) -> SMSRecord
{
auto record = SMSRecord();
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp +3 -3
@@ 26,9 26,9 @@ namespace parserFSM
static auto getKeyCode(int val) noexcept -> bsp::KeyCodes;
bool sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::State state);
- void requestSimChange(const int simSelected);
- auto smsRecordFromJson(json11::Json msgJson) -> SMSRecord;
- bool requestCellularPowerStateChange(const int simSelected);
+ void requestSimChange(int simSelected);
+ auto smsRecordFromJson(const json11::Json &msgJson) -> SMSRecord;
+ bool requestCellularPowerStateChange(int simSelected);
bool requestServiceStateInfo(sys::Service *serv);
bool requestCellularSleepModeInfo(sys::Service *serv);
auto prepareSMS(Context &context) -> ProcessResult;
M module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.hpp => module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 23,7 23,7 @@ class DeviceInfoEndpoint : public parserFSM::Endpoint
{
public:
- DeviceInfoEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ explicit DeviceInfoEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
{
debugName = "DeviceInfoEndpoint";
}
M module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp => module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp +38 -38
@@ 27,7 27,7 @@ namespace FactoryReset
inline constexpr auto copy_buf = 8192 * 4;
} // namespace
- static bool CopyFile(std::string sourcefile, std::string targetfile);
+ static bool CopyFile(const std::string &sourcefile, const std::string &targetfile);
static int recurseDepth = 0;
static const int max_recurse_depth = 120; /* 120 is just an arbitrary value of max number of recursive calls.
@@ 39,8 39,8 @@ namespace FactoryReset
{
LOG_INFO("Restoring factory state started...");
- recurseDepth = 0;
- const auto userOSPath = purefs::dir::getUserDiskPath();
+ recurseDepth = 0;
+ const auto userOSPath = purefs::dir::getUserDiskPath();
if (std::filesystem::is_directory(userOSPath.c_str()) && std::filesystem::is_empty(userOSPath.c_str())) {
LOG_ERROR("Restoring factory state aborted");
@@ 71,7 71,7 @@ namespace FactoryReset
for (const auto &ext : selectedFileExt) {
if (f.path().extension() == ext) {
auto removeStatus = std::filesystem::remove(f.path());
- if (removeStatus == false) {
+ if (!removeStatus) {
LOG_ERROR("Error deleting file %s, aborting...", f.path().c_str());
returnStatus = false;
}
@@ 85,42 85,42 @@ namespace FactoryReset
return returnStatus;
}
- bool DeleteDirContent(std::string dir)
+ bool DeleteDirContent(const std::string &dir)
{
for (auto &direntry : std::filesystem::directory_iterator(dir.c_str())) {
- if ((direntry.path().string().compare(".") != 0) && (direntry.path().string().compare("..") != 0) &&
- (direntry.path().string().compare("...") != 0)) {
-
- std::string delpath = dir;
- delpath += "/";
- delpath += direntry.path().string().c_str();
-
- if (std::filesystem::is_directory(direntry)) {
- if (direntry.path().string().compare(purefs::dir::getFactoryOSPath()) != 0) {
- LOG_INFO("FactoryReset: recursively deleting dir %s...", delpath.c_str());
- try {
- std::filesystem::remove_all(delpath.c_str());
- }
- catch (const std::filesystem::filesystem_error &e) {
- LOG_ERROR("FactoryReset: error deleting dir %s, aborting...", delpath.c_str());
- return false;
- }
+ if (!((direntry.path().string() != ".") && (direntry.path().string() != "..") &&
+ (direntry.path().string() != "..."))) {
+ continue;
+ }
+ std::string delpath = dir;
+ delpath += "/";
+ delpath += direntry.path().string();
+
+ if (std::filesystem::is_directory(direntry)) {
+ if (direntry.path().string() != purefs::dir::getFactoryOSPath()) {
+ LOG_INFO("FactoryReset: recursively deleting dir %s...", delpath.c_str());
+ try {
+ std::filesystem::remove_all(delpath.c_str());
}
- }
- else {
- LOG_INFO("FactoryReset: deleting file %s...", delpath.c_str());
- if (std::filesystem::remove(delpath.c_str())) {
- LOG_ERROR("FactoryReset: error deleting file %s, aborting...", delpath.c_str());
+ catch (const std::filesystem::filesystem_error &e) {
+ LOG_ERROR("FactoryReset: error deleting dir %s, aborting...", delpath.c_str());
return false;
}
}
}
+ else {
+ LOG_INFO("FactoryReset: deleting file %s...", delpath.c_str());
+ if (std::filesystem::remove(delpath.c_str())) {
+ LOG_ERROR("FactoryReset: error deleting file %s, aborting...", delpath.c_str());
+ return false;
+ }
+ }
}
return true;
}
- bool CopyDirContent(std::string sourcedir, std::string targetdir)
+ bool CopyDirContent(const std::string &sourcedir, const std::string &targetdir)
{
if (recurseDepth >= max_recurse_depth) {
LOG_ERROR("FactoryReset: recurse level %d (too high), error assumed, skipping restore of dir %s",
@@ 132,18 132,18 @@ namespace FactoryReset
const auto factoryOSPath = purefs::dir::getFactoryOSPath();
for (auto &direntry : std::filesystem::directory_iterator(sourcedir.c_str())) {
- if ((direntry.path().string().compare(".") == 0) || (direntry.path().string().compare("..") == 0) ||
- (direntry.path().string().compare("...") == 0)) {
+ if ((direntry.path().string() == ".") || (direntry.path().string() == "..") ||
+ (direntry.path().string() == "...")) {
continue;
}
std::string sourcepath = sourcedir;
sourcepath += "/";
- sourcepath += direntry.path().string().c_str();
+ sourcepath += direntry.path().string();
std::string targetpath = targetdir;
targetpath += "/";
- targetpath += direntry.path().string().c_str();
+ targetpath += direntry.path().string();
if ((sourcepath.size() >= max_filepath_length) || (targetpath.size() >= max_filepath_length)) {
LOG_ERROR("FactoryReset: path length (source or target) exceeds system limit of %d",
@@ 153,7 153,7 @@ namespace FactoryReset
}
if (std::filesystem::is_directory(direntry)) {
- if (targetpath.compare(factoryOSPath.c_str()) == 0) {
+ if (targetpath == factoryOSPath) {
continue;
}
@@ 172,7 172,7 @@ namespace FactoryReset
recurseDepth++;
- if (CopyDirContent(sourcepath, targetpath) != true) {
+ if (!CopyDirContent(sourcepath, targetpath)) {
recurseDepth--;
return false;
}
@@ 182,7 182,7 @@ namespace FactoryReset
else {
LOG_INFO("FactoryReset: restoring file %s into %s...", sourcepath.c_str(), targetpath.c_str());
- if (CopyFile(sourcepath, targetpath) != true) {
+ if (!CopyFile(sourcepath, targetpath)) {
return false;
}
}
@@ 191,7 191,7 @@ namespace FactoryReset
return true;
}
- static bool CopyFile(std::string sourcefile, std::string targetfile)
+ static bool CopyFile(const std::string &sourcefile, const std::string &targetfile)
{
bool ret = true;
auto lamb = [](std::FILE *stream) { std::fclose(stream); };
@@ 199,10 199,10 @@ namespace FactoryReset
std::unique_ptr<std::FILE, decltype(lamb)> sf(std::fopen(sourcefile.c_str(), "r"), lamb);
std::unique_ptr<std::FILE, decltype(lamb)> tf(std::fopen(targetfile.c_str(), "w"), lamb);
- if ((sf.get() != nullptr) && (tf.get() != nullptr)) {
+ if (sf && tf) {
std::unique_ptr<unsigned char[]> buffer(new unsigned char[copy_buf]);
- if (buffer.get() != nullptr) {
+ if (buffer) {
uint32_t loopcount = (std::filesystem::file_size(sourcefile) / copy_buf) + 1u;
uint32_t readsize = copy_buf;
M module-services/service-desktop/endpoints/factoryReset/FactoryReset.hpp => module-services/service-desktop/endpoints/factoryReset/FactoryReset.hpp +2 -2
@@ 15,6 15,6 @@ namespace FactoryReset
{
bool Run(sys::Service *ownerService);
bool DeleteSelectedUserFiles(const std::filesystem::path &userOSPath);
- bool DeleteDirContent(std::string dir);
- bool CopyDirContent(std::string sourcedir, std::string targetdir);
+ bool DeleteDirContent(const std::string &dir);
+ bool CopyDirContent(const std::string &sourcedir, const std::string &targetdir);
} // namespace FactoryReset
M module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.cpp => module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.cpp +2 -7
@@ 19,18 19,13 @@ auto FilesystemEndpoint::handle(Context &context) -> void
break;
}
}
-static bool isWritable(const fs::path file)
+static bool isWritable(const fs::path &file)
{
auto lamb = [](std::FILE *stream) { std::fclose(stream); };
std::unique_ptr<std::FILE, decltype(lamb)> sf(std::fopen(file.c_str(), "w"), lamb);
- if (sf.get() != nullptr) {
- return true;
- }
- else {
- return false;
- }
+ return static_cast<bool>(sf);
}
auto FilesystemEndpoint::run(Context &context) -> sys::ReturnCodes
M module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.hpp => module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 9,7 9,7 @@
class FilesystemEndpoint : public parserFSM::Endpoint
{
public:
- FilesystemEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ explicit FilesystemEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
{}
auto handle(parserFSM::Context &context) -> void override;
auto run(parserFSM::Context &context) -> sys::ReturnCodes;
M module-services/service-desktop/endpoints/messages/MessageHelper.cpp => module-services/service-desktop/endpoints/messages/MessageHelper.cpp +8 -8
@@ 165,7 165,7 @@ namespace parserFSM
auto MessageHelper::createSMS(Context &context) -> sys::ReturnCodes
{
- context.setResponseStatus(http::Code::InternalServerError);
+ context.setResponseStatus(http::Code::NotImplemented);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return sys::ReturnCodes::Success;
}
@@ 182,7 182,7 @@ namespace parserFSM
[=](db::QueryResult *result, Context context) {
if (auto smsTemplateResult = dynamic_cast<db::query::SMSRemoveResult *>(result)) {
- context.setResponseStatus(smsTemplateResult->getResults() ? http::Code::OK
+ context.setResponseStatus(smsTemplateResult->getResults() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
@@ 238,7 238,7 @@ namespace parserFSM
[=](db::QueryResult *result, Context context) {
if (auto smsTemplateResult = dynamic_cast<db::query::SMSTemplateUpdateResult *>(result)) {
- context.setResponseStatus(smsTemplateResult->getResult() ? http::Code::OK
+ context.setResponseStatus(smsTemplateResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
@@ 271,7 271,7 @@ namespace parserFSM
[=](db::QueryResult *result, Context context) {
if (auto smsTemplateResult = dynamic_cast<db::query::SMSTemplateAddResult *>(result)) {
- context.setResponseStatus(smsTemplateResult->getResult() ? http::Code::OK
+ context.setResponseStatus(smsTemplateResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
@@ 303,7 303,7 @@ namespace parserFSM
[=](db::QueryResult *result, Context context) {
if (auto smsTemplateResult = dynamic_cast<db::query::SMSTemplateRemoveResult *>(result)) {
- context.setResponseStatus(smsTemplateResult->getResults() ? http::Code::OK
+ context.setResponseStatus(smsTemplateResult->getResults() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
@@ 337,7 337,7 @@ namespace parserFSM
auto theResults = threadsResults->getResults();
threadsArray.reserve(theResults.size());
for (auto &record : theResults) {
- threadsArray.emplace_back(MessageHelper::toJson(std::move(record)));
+ threadsArray.emplace_back(MessageHelper::toJson(record));
}
context.setResponseBody(std::move(threadsArray));
context.setTotalCount(threadsResults->getTotalCount());
@@ 384,7 384,7 @@ namespace parserFSM
[=](db::QueryResult *result, Context context) {
if (auto threadResult = dynamic_cast<db::query::MarkAsReadResult *>(result)) {
- context.setResponseStatus(threadResult->getResult() ? http::Code::OK
+ context.setResponseStatus(threadResult->getResult() ? http::Code::NoContent
: http::Code::InternalServerError);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return true;
@@ 404,7 404,7 @@ namespace parserFSM
auto MessageHelper::deleteThread(Context &context) -> sys::ReturnCodes
{
- context.setResponseStatus(http::Code::InternalServerError);
+ context.setResponseStatus(http::Code::NotImplemented);
MessageHandler::putToSendQueue(context.createSimpleResponse());
return sys::ReturnCodes::Success;
}
M module-services/service-desktop/endpoints/restore/RestoreEndpoint.hpp => module-services/service-desktop/endpoints/restore/RestoreEndpoint.hpp +1 -1
@@ 20,7 20,7 @@ namespace sys
class RestoreEndpoint : public parserFSM::Endpoint
{
public:
- RestoreEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ explicit RestoreEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
{
debugName = "RestoreEndpoint";
}
M module-services/service-desktop/endpoints/security/SecurityEndpointHelper.cpp => module-services/service-desktop/endpoints/security/SecurityEndpointHelper.cpp +4 -2
@@ 44,7 44,7 @@ auto SecurityEndpointHelper::processStatus(Context &context) -> http::Code
preventBlockingDevice();
}
- return security == EndpointSecurity::Allow ? http::Code::OK : http::Code::Forbidden;
+ return security == EndpointSecurity::Allow ? http::Code::NoContent : http::Code::Forbidden;
}
auto SecurityEndpointHelper::passCodeArrayToVecOfInts(const json11::Json::array &passCode) -> std::vector<unsigned int>
@@ 73,7 73,9 @@ auto SecurityEndpointHelper::processConfiguration(Context &context) -> http::Cod
if (passCode.size() == PasscodeLength) {
try {
auto msg = std::make_shared<locks::ExternalUnLockPhone>(passCodeArrayToVecOfInts(passCode));
- status = toCode(owner->bus.sendUnicast(std::move(msg), app::manager::ApplicationManager::ServiceName));
+ status = owner->bus.sendUnicast(std::move(msg), app::manager::ApplicationManager::ServiceName)
+ ? http::Code::NoContent
+ : http::Code::InternalServerError;
}
catch (const std::exception &e) {
LOG_ERROR("Passcode decoding exception: %s", e.what());
M module-services/service-desktop/endpoints/update/UpdateEndpoint.hpp => module-services/service-desktop/endpoints/update/UpdateEndpoint.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 24,7 24,7 @@ class UpdateEndpoint : public parserFSM::Endpoint
{
public:
- UpdateEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
+ explicit UpdateEndpoint(sys::Service *ownerServicePtr) : Endpoint(ownerServicePtr)
{
debugName = "UpdateEndpoint";
}
M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +11 -8
@@ 53,7 53,7 @@ UpdateMuditaOS::UpdateMuditaOS(ServiceDesktop *ownerService) : owner(ownerServic
}
updateos::UpdateError UpdateMuditaOS::setUpdateFile(const std::filesystem::path &updatesOSPath,
- fs::path updateFileToUse)
+ const fs::path &updateFileToUse)
{
if (isUpdateToBeAborted()) {
setUpdateAbortFlag(false);
@@ 338,7 338,7 @@ updateos::UpdateError UpdateMuditaOS::updateBootloader()
unsigned long UpdateMuditaOS::getExtractedFileCRC32(const std::string &filePath)
{
- for (auto file : filesInUpdatePackage) {
+ for (const auto &file : filesInUpdatePackage) {
if (file.fileName == filePath) {
return file.fileCRC32;
}
@@ 448,7 448,7 @@ updateos::UpdateError UpdateMuditaOS::updateBootJSON()
auto *fpCRC = std::fopen(bootJSONAbsoulte.c_str(), "w");
if (fpCRC != nullptr) {
- std::array<char, boot::consts::crc_char_size + 1> crcBuf;
+ std::array<char, boot::consts::crc_char_size + 1> crcBuf{};
snprintf(crcBuf.data(), crcBuf.size(), "%lX", bootJSONAbsoulteCRC);
std::fwrite(crcBuf.data(), 1, boot::consts::crc_char_size, fpCRC);
std::fclose(fpCRC);
@@ 544,7 544,7 @@ updateos::UpdateError UpdateMuditaOS::cleanupAfterUpdate()
try {
mtar_close(&updateTar);
- if (std::remove(updateFile.c_str())) {
+ if (std::remove(updateFile.c_str()) != 0) {
return informError(updateos::UpdateError::CantRemoveUpdateFile, "Failed to delete %s", updateFile.c_str());
}
}
@@ 561,10 561,12 @@ updateos::UpdateError UpdateMuditaOS::cleanupAfterUpdate()
const fs::path UpdateMuditaOS::getUpdateTmpChild(const fs::path &childPath)
{
- if (childPath.string().rfind("./", 0) == 0)
+ if (childPath.string().rfind("./", 0) == 0) {
return updateTempDirectory / childPath.string().substr(2);
- else
+ }
+ else {
return updateTempDirectory / childPath;
+ }
}
updateos::UpdateError UpdateMuditaOS::prepareTempDirForUpdate(const std::filesystem::path &temporaryPath,
@@ 872,8 874,9 @@ void UpdateMuditaOS::informUpdateWindow()
auto msgToSend = std::make_shared<sdesktop::UpdateOsMessage>(updateos::UpdateMessageType::UpdateNow, file);
msgToSend->updateStats.versionInformation = UpdateMuditaOS::getVersionInfoFromFile(file);
msgToSend->updateStats.status = status;
- if (owner)
+ if (owner != nullptr) {
owner->bus.sendUnicast(msgToSend, app::name_desktop);
+ }
}
void UpdateMuditaOS::storeRunStatusInDB()
@@ 902,7 905,7 @@ void UpdateMuditaOS::storeRunStatusInDB()
}
}
- if (statusRunFound == false) {
+ if (!statusRunFound) {
// if our element was not found, insert it
tempTable.emplace_back(updateRunStatus);
}
M module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp +3 -3
@@ 31,7 31,7 @@ struct FileInfo
class UpdateMuditaOS : public updateos::UpdateStats
{
public:
- UpdateMuditaOS(ServiceDesktop *ownerService);
+ explicit UpdateMuditaOS(ServiceDesktop *ownerService);
updateos::UpdateError runUpdate();
updateos::UpdateError prepareTempDirForUpdate(const std::filesystem::path &temporaryPath,
@@ 42,13 42,13 @@ class UpdateMuditaOS : public updateos::UpdateStats
updateos::UpdateError updateBootloader();
updateos::UpdateError prepareRoot();
updateos::UpdateError updateBootJSON();
- updateos::UpdateError setUpdateFile(const std::filesystem::path &updatesOSPath, fs::path updateFileToUse);
+ updateos::UpdateError setUpdateFile(const std::filesystem::path &updatesOSPath, const fs::path &updateFileToUse);
updateos::UpdateError cleanupAfterUpdate();
updateos::UpdateError updateUserData();
updateos::UpdateError informError(updateos::UpdateError errorCode, const char *format, ...);
void informDebug(const char *format, ...);
- void informUpdate(const updateos::UpdateState statusCode, const char *format, ...);
+ void informUpdate(updateos::UpdateState statusCode, const char *format, ...);
updateos::UpdateError writeBootloader(fs::path bootloaderFile);
M module-services/service-desktop/endpoints/update/UpdateOSTypes.hpp => module-services/service-desktop/endpoints/update/UpdateOSTypes.hpp +3 -5
@@ 7,8 7,6 @@
#include <purefs/filesystem_paths.hpp>
namespace fs = std::filesystem;
-
-namespace fs = std::filesystem;
namespace updateos
{
inline constexpr auto initSysVer = "0.00.0";
@@ 97,7 95,7 @@ namespace updateos
uint32_t currentExtractedBytes = 0;
uint32_t fileExtractedSize = 0;
uint32_t uuid = 0;
- std::string messageText = "";
+ std::string messageText;
updateos::UpdateState status;
json11::Json versionInformation;
};
@@ 113,8 111,8 @@ namespace updateos
{
return json11::Json::object{{updateos::settings::startTime, std::to_string(startTime)},
{updateos::settings::endTime, std::to_string(endTime)},
- {updateos::settings::finishedState, (int)finishedState},
- {updateos::settings::finishedError, (int)finishedError},
+ {updateos::settings::finishedState, static_cast<int>(finishedState)},
+ {updateos::settings::finishedError, static_cast<int>(finishedError)},
{updateos::settings::fromVersion, fromVersion},
{updateos::settings::toVersion, toVersion}};
}
M module-services/service-desktop/parser/HttpEnums.hpp => module-services/service-desktop/parser/HttpEnums.hpp +3 -1
@@ 13,12 13,14 @@ namespace parserFSM::http
{
OK = 200,
Accepted = 202,
+ NoContent = 204,
SeeOther = 303,
BadRequest = 400,
Forbidden = 403,
NotFound = 404,
NotAcceptable = 406,
- InternalServerError = 500
+ InternalServerError = 500,
+ NotImplemented = 501
};
/*! Enum class for the HTTP methods.
M module-services/service-desktop/tests/unittest.cpp => module-services/service-desktop/tests/unittest.cpp +1 -2
@@ 226,8 226,7 @@ TEST_CASE("Context class test")
REQUIRE(context.getMethod() == http::Method::get);
REQUIRE(context.getUuid() == 12345);
REQUIRE(context.getEndpoint() == EndpointType::contacts);
- REQUIRE(context.createSimpleResponse() ==
- R"(#000000059{"body": null, "endpoint": 7, "status": 200, "uuid": 12345})");
+ REQUIRE(context.createSimpleResponse() == R"(#000000045{"endpoint": 7, "status": 200, "uuid": 12345})");
context.setResponseBody(context.getBody());
REQUIRE(context.createSimpleResponse() ==
M test/pytest/service-desktop/test_security.py => test/pytest/service-desktop/test_security.py +2 -2
@@ 12,8 12,8 @@ from harness.interface.defs import status
def test_security_phone_unlocked(harness):
body = {}
- ret = harness.endpoint_request("deviceInfo", "get", body)
- assert ret["status"] == status["OK"]
+ ret = harness.endpoint_request("usbSecurity", "get", body)
+ assert ret["status"] == status["NoContent"]
@pytest.mark.service_desktop_test