7 files changed, 0 insertions(+), 878 deletions(-)
M products/PurePhone/test/CMakeLists.txt
D products/PurePhone/test/test-settings/CMakeLists.txt
D products/PurePhone/test/test-settings/Database.cpp
D products/PurePhone/test/test-settings/test-service-db-settings-api.cpp
D products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp
D products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp
D products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp
M products/PurePhone/test/CMakeLists.txt => products/PurePhone/test/CMakeLists.txt +0 -1
@@ 1,1 0,0 @@
-add_subdirectory(test-settings)
D products/PurePhone/test/test-settings/CMakeLists.txt => products/PurePhone/test/test-settings/CMakeLists.txt +0 -19
@@ 1,19 0,0 @@
-# service-db tests
-add_catch2_executable(
- NAME
- service-db-settings
- SRCS
- test-service-db-settings-api.cpp
- LIBS
- db
- evtmgr
- sys
- module-audio
- module-cellular
- module-vfs
- service-audio
- service-cellular
- Microsoft.GSL::GSL
- DEPS
- module-sys
-)
D products/PurePhone/test/test-settings/Database.cpp => products/PurePhone/test/test-settings/Database.cpp +0 -219
@@ 1,219 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include "module-db/Database/Database.hpp"
-
-#include <log/log.hpp>
-
-#include <purefs/filesystem_paths.hpp>
-#include <gsl/util>
-
-#include <cassert>
-#include <cstring>
-#include <memory>
-
-#include <service-db/agents/settings/Settings_queries.hpp>
-
-#include <map>
-#include <string>
-
-class DatabaseInitializer
-{
- public:
- DatabaseInitializer(Database *)
- {}
- virtual ~DatabaseInitializer() = default;
-};
-
-std::map<std::string, std::string> variables;
-std::string profile = "_startProfileValue";
-std::string mode = "_initialModeValue";
-std::set<std::string> profiles, modes;
-const std::string system_phone_mode("system/phone_mode");
-const std::string system_phone_profile("system/phone_profile");
-
-bool stubExecute(const std::string &format, const std::string &path, const std::string &val)
-{
- if (format.empty()) {
- return false;
- }
-
- if (format == std::string(settings::Statements::insertValue)) {
- LOG_DEBUG("Database::execute set %s", path.c_str());
- variables[path] = val;
- return true;
- }
-
- if (format == std::string(settings::Statements::setNotification)) {
- return true;
- }
- if (format == std::string(settings::Statements::clearNotificationdRow)) {
- return true;
- }
-
- if (format == std::string(settings::Statements::updateValue)) {
- // profile change, mode change
- if (val == system_phone_mode) {
- mode = path;
- return true;
- }
- if (val == system_phone_profile) {
- profile = path;
- return true;
- }
- return false;
- }
-
- if (format == std::string(settings::Statements::addDictValue)) {
- // add new profile, add new mode
- if (path == system_phone_mode) {
- modes.insert(val);
- return true;
- }
- if (path == system_phone_profile) {
- profiles.insert(val);
- return true;
- }
- return false;
- }
-
- return false;
-}
-
-std::unique_ptr<QueryResult> stubQuery(const std::string &format, const std::string &what)
-{
- std::vector<Field> row;
- auto queryResult = std::make_unique<QueryResult>();
- if (std::string(settings::Statements::getValue) == format) {
- if (system_phone_mode == what) // settings::DbPaths::phone_mode
- {
- row.push_back(Field{mode.c_str()});
- }
- else if (system_phone_profile == what) // settings::DbPaths::phone_profile
- {
- row.push_back(Field{profile.c_str()});
- }
- else // variable
- {
- if (variables.end() == variables.find(what)) {
- variables[what] = what + " _initialValue";
- }
- LOG_DEBUG("Database::query for %s", what.c_str());
- row.push_back(Field{variables[what].c_str()});
- }
- queryResult->addRow(row);
- }
- else if (std::string(settings::Statements::getDictValue) == format) {
- if (system_phone_mode == what) {
- for (const auto &mode : modes) {
- row.clear();
- row.push_back(Field{mode.c_str()});
- queryResult->addRow(row);
- }
- }
- else if (system_phone_profile == what) {
- for (const auto &profile : profiles) {
- row.clear();
- row.push_back(Field{profile.c_str()});
- queryResult->addRow(row);
- }
- }
- // allProfiles, allModes
- }
- return queryResult;
-}
-
-Database::Database(const char *name, bool) : dbName(name), queryStatementBuffer{nullptr}, isInitialized_(false)
-{
- isInitialized_ = true;
-}
-
-void Database::initQueryStatementBuffer()
-{}
-
-void Database::clearQueryStatementBuffer()
-{
- std::memset(queryStatementBuffer, 0, maxQueryLen);
-}
-
-Database::~Database()
-{}
-
-bool Database::initialize()
-{
- return true;
-}
-
-bool Database::deinitialize()
-{
- return true;
-}
-
-bool Database::execute(const char *format, ...)
-{
- if (format == nullptr) {
- return false;
- }
- std::string format_str(format);
- if (format_str.find("%") == std::string::npos) {
- return true;
- }
- std::string path, val;
- va_list ap;
- va_start(ap, format);
- format = va_arg(ap, const char *);
- if (format != nullptr) {
- path = std::string(format);
- format = va_arg(ap, const char *);
- if (format != nullptr) {
- val = std::string(format);
- }
- }
- va_end(ap);
- if (!path.empty() && !val.empty()) {
- return stubExecute(format_str, path, val);
- }
- return true;
-}
-
-std::unique_ptr<QueryResult> Database::query(const char *format, ...)
-{
- if (format == nullptr) {
- return nullptr;
- }
-
- std::string format_str(format);
- if (format_str.find("%") == std::string::npos) {
- return nullptr;
- }
- std::string what;
- va_list ap;
- va_start(ap, format);
- format = va_arg(ap, const char *);
- if (format != nullptr) {
- what = std::string(format);
- }
- va_end(ap);
- if (what.empty()) {
- return nullptr;
- }
- return stubQuery(format_str, what);
-}
-
-int Database::queryCallback(void *usrPtr, int count, char **data, char **columns)
-{
- return 0;
-}
-
-uint32_t Database::getLastInsertRowId()
-{
- return 1;
-}
-
-void Database::pragmaQuery(const std::string &pragmaStatemnt)
-{}
-
-bool Database::storeIntoFile(const std::filesystem::path &backupPath)
-{
- return true;
-}
D products/PurePhone/test/test-settings/test-service-db-settings-api.cpp => products/PurePhone/test/test-settings/test-service-db-settings-api.cpp +0 -102
@@ 1,102 0,0 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include <catch2/catch.hpp>
-#include <service-db/Settings.hpp>
-#include <service-db/SettingsMessages.hpp>
-#include <Service/Service.hpp>
-#include <functional>
-#include <thread> // for Message_t, ResponseMessage, DataMessage, Message
-
-#include <db/ServiceDB.hpp>
-#include <evtmgr/EventManager.hpp>
-#include <sys/SystemManager.hpp>
-
-#include "test-service-db-settings-testmsgs.hpp"
-#include "test-service-db-settings-testservices.hpp"
-#include "test-service-db-settings-testapps.hpp"
-#include "Database.cpp"
-
-#include "module-db/databases/CalllogDB.hpp"
-#include <module-db/databases/EventsDB.hpp>
-#include <module-db/databases/MultimediaFilesDB.hpp>
-#include "module-db/databases/NotesDB.hpp"
-#include "module-db/databases/NotificationsDB.hpp"
-#include "module-db/databases/SmsDB.hpp"
-#include <module-db/Interface/AlarmEventRecord.hpp>
-#include <module-db/Interface/CalllogRecord.hpp>
-#include <module-db/Interface/MultimediaFilesRecord.hpp>
-#include <module-db/Interface/NotesRecord.hpp>
-#include <module-db/Interface/NotificationsRecord.hpp>
-#include <module-db/Interface/SMSRecord.hpp>
-#include <module-db/Interface/SMSTemplateRecord.hpp>
-#include <module-db/Interface/ThreadRecord.hpp>
-#include <service-db/agents/quotes/QuotesAgent.hpp>
-
-TEST_CASE("SettingsApi", "[.]")
-{
- SECTION("variable/profile/mode register/set/get/unregister")
- {
- auto manager = std::make_shared<sys::SystemManager>(std::vector<std::unique_ptr<sys::BaseServiceCreator>>{});
- std::shared_ptr<settings::MyService> varWritter;
- std::shared_ptr<settings::MyService> varReader;
- std::shared_ptr<settings::AppTest> testVar;
- std::shared_ptr<std::mutex> testStart;
-
- std::shared_ptr<settings::Settings> postMortemSetting;
-
- manager->StartSystem(
- nullptr,
- [manager, &varWritter, &varReader, &testVar, &testStart, &postMortemSetting]() {
- // preliminary
- testStart = std::make_shared<std::mutex>();
- testStart->lock();
- std::cout << "start thr_id: " << std::this_thread::get_id() << std::endl << std::flush;
- auto ret = sys::SystemManagerCommon::RunSystemService(std::make_shared<EventManager>(), manager.get());
- ret &= sys::SystemManagerCommon::RunSystemService(std::make_shared<ServiceDB>(), manager.get());
-
- varWritter = std::make_shared<settings::MyService>("writterVar");
- varReader = std::make_shared<settings::MyService>("readerVar");
-
- postMortemSetting = varWritter->getSettings();
-
- ret &= sys::SystemManagerCommon::RunSystemService(varWritter, manager.get());
- ret &= sys::SystemManagerCommon::RunSystemService(varReader, manager.get());
-
- testVar = std::make_shared<settings::AppTest>("appTest", varWritter, varReader, testStart);
- ret &= sys::SystemManagerCommon::RunSystemService(testVar, manager.get());
-
- std::cout << "koniec start thr_id: " << std::this_thread::get_id() << std::endl << std::flush;
- testStart->unlock();
- auto msgStart = std::make_shared<settings::UTMsg::UTMsgStart>();
- manager->bus.sendUnicast(std::move(msgStart), "appTest");
-
- msgStart = std::make_shared<settings::UTMsg::UTMsgStart>();
- manager->bus.sendUnicast(std::move(msgStart), "appTestProfile");
-
- msgStart = std::make_shared<settings::UTMsg::UTMsgStart>();
- manager->bus.sendUnicast(std::move(msgStart), "appTestMode");
-
- return ret;
- },
- nullptr);
-
- try {
- // start application
- cpp_freertos::Thread::StartScheduler();
-
- // check the results
- std::cout << "testVar values:" << std::endl << std::flush;
- for (const auto &s : testVar->v) {
- std::cout << s << std::endl << std::flush;
- }
- REQUIRE(testVar->v.size() == 3);
- REQUIRE(testVar->v[1] == testVar->v[0] + "1");
- REQUIRE(testVar->v[2] == testVar->v[1] + "2");
- }
- catch (std::exception &error) {
- std::cout << error.what() << std::endl;
- exit(1);
- }
- }
-}
D products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp => products/PurePhone/test/test-settings/test-service-db-settings-testapps.hpp +0 -274
@@ 1,274 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include <iostream>
-#include <mutex>
-
-namespace app
-{
- class UserPowerDownRequest : public sys::DataMessage
- {};
-} // namespace app
-namespace settings
-{
- class TestService : public sys::Service
- {
- public:
- TestService(const std::string &name) : sys::Service(name)
- {}
- sys::ReturnCodes InitHandler() override
- {
- std::cout << "inithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush;
- return sys::ReturnCodes::Success;
- }
- sys::ReturnCodes DeinitHandler() override
- {
- std::cout << "deinithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush;
- return sys::ReturnCodes::Success;
- }
- sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override
- {
- return sys::ReturnCodes::Success;
- }
- sys::MessagePointer DataReceivedHandler(sys::DataMessage *req, sys::ResponseMessage *resp) override
- {
- return std::make_shared<sys::ResponseMessage>();
- };
- };
- /* @brief AppTest handles async communication between two services (setter and getter)
- and simulates synchronous following flow:
- 1. getter registers on value changes and gets the startup value of param "brightness"
- 2. the setter app sets "brightness" to received in step 1 value + "1"
- 3. check if the new value was received by getter
- 4. unregister "brightness" on getter
- 5. set "brightness" to value+"1"+"2" on setter
- 6. wait 200ms and if getter does not provide value change finish
- */
- class AppTest : public TestService
- {
- public:
- enum class State : uint8_t
- {
- Unk, // init
- Start, // got start, send register
- Register, // got register cnf
- RegisterStartVal, // got onchang (v), set (v+1)
- RegisterSetVal, // got vcnf (v+1) && got onchange (v+1), send unregister
- UnregisterWait, //
- Unregister,
- RegisterAllWait,
- RegisterAll,
- RegisterAllAdd,
- RegisterAllAddWait,
- Stop
- };
- std::shared_ptr<MyService> setter;
- std::shared_ptr<MyService> getter;
- std::shared_ptr<std::mutex> testStart;
- State state;
- std::string last_v;
- std::vector<std::string> v;
-
- void setState(State state)
- {
- printf("state change: [%s]->[%s]\n",
- std::string(magic_enum::enum_name(this->state)).c_str(),
- std::string(magic_enum::enum_name(state)).c_str());
- this->state = state;
- }
- bool isState(State cmp)
- {
- printf("state compare: [%s]->[%s]\n",
- std::string(magic_enum::enum_name(this->state)).c_str(),
- std::string(magic_enum::enum_name(state)).c_str());
- return this->state == cmp;
- }
-
- AppTest(std::string name,
- std::shared_ptr<MyService> setter,
- std::shared_ptr<MyService> getter,
- std::shared_ptr<std::mutex> testStart)
- : TestService(std::move(name)), setter(std::move(setter)), getter(std::move(getter)),
- testStart(std::move(testStart))
- {}
- sys::ReturnCodes InitHandler() override
- {
- setState(State::Unk);
- return sys::ReturnCodes::Success;
- }
- sys::ReturnCodes DeinitHandler() override
- {
- return sys::ReturnCodes::Success;
- }
- sys::MessagePointer DataReceivedHandler(sys::DataMessage *msg, sys::ResponseMessage *resp) override
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- if (nullptr != dynamic_cast<settings::UTMsg::UTMsgStart *>(msg)) {
- testStart->lock();
- testStart->unlock();
- if (!isState(State::Unk)) {
- closeSystem();
- }
- else {
- setState(State::Start);
- auto msg = std::make_shared<settings::UTMsg::ReqRegValChg>("brightness", "none");
- bus.sendUnicast(std::move(msg), getter->GetName());
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfRegValChg *>(msg)) {
- if (isState(State::Start)) {
- setState(State::Register);
- }
- }
- else if (auto m = dynamic_cast<settings::UTMsg::CnfValChg *>(msg)) {
- if (isState(State::Register)) {
- setState(State::RegisterStartVal);
- v.push_back(m->value);
- auto msg = std::make_shared<settings::UTMsg::ReqSetVal>("brightness", v[0] + "1");
- bus.sendUnicast(std::move(msg), setter->GetName());
- }
- else if (isState(State::RegisterSetVal)) {
- if (m->value == v[0] + "1") {
- v.push_back(m->value);
- auto msg = std::make_shared<settings::UTMsg::ReqUnRegValChg>("brightness", "empty");
- bus.sendUnicast(std::move(msg), getter->GetName());
- setState(State::UnregisterWait);
- }
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfUnRegValChg *>(msg)) {
- if (isState(State::UnregisterWait)) {
- setState(State::Unregister);
- auto msg = std::make_shared<settings::UTMsg::ReqSetVal>("brightness", v.back() + "2");
- bus.sendUnicast(std::move(msg), setter->GetName());
- }
- }
- else if (auto m = dynamic_cast<settings::UTMsg::CnfReqSetVal *>(msg)) {
- if (isState(State::RegisterStartVal)) {
- setState(State::RegisterSetVal);
- }
- else if (isState(State::Unregister)) {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- v.push_back(m->value);
- auto msg = std::make_shared<settings::UTMsg::UTMsgStop>();
- bus.sendUnicast(std::move(msg), GetName());
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::UTMsgStop *>(msg)) {
- if (isState(State::Unregister)) {
- closeSystem();
- }
- }
-
- return std::make_shared<sys::ResponseMessage>();
- }
-
- protected:
- void closeSystem()
- {
- auto msg = std::make_shared<app::UserPowerDownRequest>();
- bus.sendUnicast(std::move(msg), service::name::system_manager);
- }
- };
-
- class AppTestProfileMode : public AppTest
- {
- public:
- AppTestProfileMode(const std::string &name,
- std::shared_ptr<MyService> setter,
- std::shared_ptr<MyService> getter,
- std::shared_ptr<std::mutex> testStart)
- : AppTest(name, setter, getter, testStart)
- {}
- sys::MessagePointer DataReceivedHandler(sys::DataMessage *msg, sys::ResponseMessage *resp) override
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- if (nullptr != dynamic_cast<settings::UTMsg::UTMsgStart *>(msg)) {
- testStart->lock();
- testStart->unlock();
- if (!isState(State::Unk)) {
- closeSystem();
- }
- else {
- setState(State::Start);
- auto msg = std::make_shared<settings::UTMsg::ReqRegProfileChg>();
- bus.sendUnicast(std::move(msg), getter->GetName());
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfRegProfileChg *>(msg)) {
- if (isState(State::Start)) {
- setState(State::Register);
- }
- }
- else if (auto m = dynamic_cast<settings::UTMsg::ProfileChg *>(msg)) {
- if (isState(State::Register)) {
- setState(State::RegisterStartVal);
- v.push_back(m->name);
- auto msg = std::make_shared<settings::UTMsg::ReqSetCurrentProfile>(m->name + "1");
- bus.sendUnicast(std::move(msg), setter->GetName());
- }
- else if (isState(State::RegisterSetVal)) {
- if (m->name == v[0] + "1") {
- v.push_back(m->name);
- auto msg = std::make_shared<settings::UTMsg::ReqUnRegProfileChg>();
- bus.sendUnicast(std::move(msg), getter->GetName());
- setState(State::UnregisterWait);
- }
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfUnRegProfileChg *>(msg)) {
- if (isState(State::UnregisterWait)) {
- setState(State::Unregister);
- auto msg = std::make_shared<settings::UTMsg::ReqSetCurrentProfile>(v.back() + "2");
- bus.sendUnicast(std::move(msg), setter->GetName());
- }
- }
- else if (auto m = dynamic_cast<settings::UTMsg::CnfSetCurrentProfile *>(msg)) {
- if (isState(State::RegisterStartVal)) {
- setState(State::RegisterSetVal);
- }
- else if (isState(State::Unregister)) {
- v.push_back(m->name);
- auto msg = std::make_shared<settings::UTMsg::ReqGetAllProfiles>();
- bus.sendUnicast(std::move(msg), getter->GetName());
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfGetAllProfiles *>(msg)) {
- if (isState(State::Unregister)) {
- setState(State::RegisterAllWait);
- }
- }
- else if (auto m = dynamic_cast<settings::UTMsg::ProfilesChg *>(msg)) {
- if (isState(State::RegisterAllWait)) {
- setState(State::RegisterAll);
- for (auto prof : m->profiles) {
- v.push_back(prof);
- }
- auto msg = std::make_shared<settings::UTMsg::ReqAddProfile>("other");
- bus.sendUnicast(std::move(msg), setter->GetName());
- }
- else if (isState(State::RegisterAllAddWait)) {
- setState(State::RegisterAllAdd);
- for (auto prof : m->profiles) {
- v.push_back(prof);
- }
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- auto msg = std::make_shared<settings::UTMsg::UTMsgStop>();
- bus.sendUnicast(std::move(msg), GetName());
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::CnfAddProfile *>(msg)) {
- if (isState(State::RegisterAll)) {
- setState(State::RegisterAllAddWait);
- }
- }
- else if (nullptr != dynamic_cast<settings::UTMsg::UTMsgStop *>(msg)) {
- if (isState(State::RegisterAllAdd)) {
- closeSystem();
- }
- }
-
- return std::make_shared<sys::ResponseMessage>();
- }
- };
-} // namespace settings
D products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp => products/PurePhone/test/test-settings/test-service-db-settings-testmsgs.hpp +0 -177
@@ 1,177 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-namespace settings
-{
- namespace UTMsg
- {
- class SettingsUTMsg : public ::settings::Messages::SettingsMessage
- {
- public:
- explicit SettingsUTMsg(MessageType type = MessageType::Settings)
- : ::settings::Messages::SettingsMessage(type){};
- ~SettingsUTMsg() override = default;
- };
-
- class UTMsgReq : public SettingsUTMsg
- {
- public:
- std::string name, value;
- UTMsgReq() = default;
- UTMsgReq(std::string name, std::string value) : name(std::move(name)), value(std::move(value))
- {}
- };
- class UTMsgCnf : public SettingsUTMsg
- {
- public:
- std::string name, value;
- UTMsgCnf() = default;
- UTMsgCnf(std::string name, std::string value) : name(std::move(name)), value(std::move(value))
- {}
- };
- class UTMsgStart : public SettingsUTMsg
- {
- public:
- UTMsgStart() = default;
- };
- class UTMsgStop : public SettingsUTMsg
- {
- public:
- UTMsgStop() = default;
- };
-
- class ReqRegValChg : public UTMsgReq
- {
- public:
- ReqRegValChg(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value))
- {}
- };
- class ReqUnRegValChg : public UTMsgReq
- {
- public:
- ReqUnRegValChg(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value))
- {}
- };
- class ReqSetVal : public UTMsgReq
- {
- public:
- ReqSetVal(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value))
- {}
- };
- class ReqGetVal : public UTMsgReq
- {
- public:
- ReqGetVal(std::string name, std::string value) : UTMsgReq(std::move(name), std::move(value))
- {}
- };
- class CnfRegValChg : public UTMsgCnf
- {
- public:
- CnfRegValChg() = default;
- CnfRegValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value))
- {}
- };
- class CnfUnRegValChg : public UTMsgCnf
- {
- public:
- CnfUnRegValChg() = default;
- CnfUnRegValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value))
- {}
- };
- class CnfReqSetVal : public UTMsgCnf
- {
- public:
- CnfReqSetVal() = default;
- CnfReqSetVal(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value))
- {}
- };
- class CnfReqGetVal : public UTMsgCnf
- {
- public:
- CnfReqGetVal() = default;
- CnfReqGetVal(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value))
- {}
- };
- class CnfValChg : public UTMsgCnf
- {
- public:
- CnfValChg() = default;
- CnfValChg(std::string name, std::string value) : UTMsgCnf(std::move(name), std::move(value))
- {}
- };
-
- class ReqRegProfileChg : public UTMsgReq
- {
- public:
- ReqRegProfileChg() = default;
- };
- class ReqUnRegProfileChg : public UTMsgReq
- {
- public:
- ReqUnRegProfileChg() = default;
- };
- class ReqSetCurrentProfile : public UTMsgReq
- {
- public:
- ReqSetCurrentProfile(std::string profile) : UTMsgReq(std::move(profile), "")
- {}
- };
- class ReqGetAllProfiles : public UTMsgReq
- {
- public:
- ReqGetAllProfiles() = default;
- };
- class ReqAddProfile : public UTMsgReq
- {
- public:
- ReqAddProfile(std::string profile) : UTMsgReq(std::move(profile), "")
- {}
- };
- class CnfRegProfileChg : public UTMsgCnf
- {
- public:
- CnfRegProfileChg() = default;
- };
- class CnfUnRegProfileChg : public UTMsgCnf
- {
- public:
- CnfUnRegProfileChg() = default;
- };
- class CnfSetCurrentProfile : public UTMsgCnf
- {
- public:
- CnfSetCurrentProfile(std::string profile) : UTMsgCnf(std::move(profile), "")
- {}
- };
- class CnfGetAllProfiles : public UTMsgCnf
- {
- public:
- CnfGetAllProfiles() = default;
- };
- class CnfAddProfile : public UTMsgCnf
- {
- public:
- CnfAddProfile(std::string profile) : UTMsgCnf(std::move(profile), "")
- {}
- };
- class CnfReqProfileChg : public UTMsgCnf
- {
- public:
- CnfReqProfileChg(std::string profile) : UTMsgCnf(std::move(profile), "")
- {}
- };
- class ProfileChg : public UTMsgCnf
- {
- public:
- ProfileChg(std::string profile) : UTMsgCnf(std::move(profile), "")
- {}
- };
- class ProfilesChg : public UTMsgCnf
- {
- public:
- std::list<std::string> profiles;
- ProfilesChg(std::list<std::string> profiles) : UTMsgCnf(), profiles(std::move(profiles))
- {}
- };
- }; // namespace UTMsg
-} // namespace settings
D products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp => products/PurePhone/test/test-settings/test-service-db-settings-testservices.hpp +0 -86
@@ 1,86 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include <memory>
-#include <iostream>
-
-namespace settings
-{
- class MyService : public sys::Service
- {
- public:
- MyService(const std::string &name) : sys::Service(name)
- {}
- std::shared_ptr<settings::Settings> mySettings;
- std::vector<std::string> valChanged;
- std::string whoRequestedNotifyOnChange;
- void ValueChanged(std::string value)
- {
- valChanged.emplace_back(value);
- }
- void debug(const std::string &cmd, const std::string &k, const std::string &v)
- {
- std::cout << "[thr_id:" << std::this_thread::get_id() << ", thr_name:" << GetName() << "] " << cmd
- << " [key, val] = (" << k << ", " << v << ")" << std::endl
- << std::flush;
- }
- sys::MessagePointer DataReceivedHandler(sys::DataMessage *req, sys::ResponseMessage *resp) override
- {
- if (auto msg = dynamic_cast<settings::UTMsg::ReqRegValChg *>(req)) {
- debug("ReqRegValChg", msg->name, msg->value);
- whoRequestedNotifyOnChange = msg->sender;
- mySettings->registerValueChange(msg->name,
- ([this](std::string value) {
- ValueChanged(value);
- auto cnf = std::make_shared<settings::UTMsg::CnfValChg>("", value);
- bus.sendUnicast(std::move(cnf), whoRequestedNotifyOnChange);
- }),
- settings::SettingsScope::Global);
- auto cnf = std::make_shared<settings::UTMsg::CnfRegValChg>(msg->name, msg->value);
- bus.sendUnicast(std::move(cnf), whoRequestedNotifyOnChange);
- }
- else if (auto msg = dynamic_cast<settings::UTMsg::ReqUnRegValChg *>(req)) {
- // unregister
- debug("ReqUnRegValChg", msg->name, msg->value);
- mySettings->unregisterValueChange(msg->name, settings::SettingsScope::Global);
- auto cnf = std::make_shared<settings::UTMsg::CnfUnRegValChg>(msg->name, msg->value);
- bus.sendUnicast(std::move(cnf), msg->sender);
- }
- else if (auto msg = dynamic_cast<settings::UTMsg::ReqSetVal *>(req)) {
- // set value
- debug("ReqSetVal", msg->name, msg->value);
- mySettings->setValue(msg->name, msg->value, settings::SettingsScope::Global);
- auto cnf = std::make_shared<settings::UTMsg::CnfReqSetVal>(msg->name, msg->value);
- bus.sendUnicast(std::move(cnf), msg->sender);
- }
- else if (dynamic_cast<settings::UTMsg::ReqGetVal *>(msg)) {
- debug("ReqGetValChg", msg->name, msg->value);
- }
- return std::make_shared<sys::ResponseMessage>();
- }
- sys::ReturnCodes InitHandler() override
- {
- std::cout << "InitHandler thr_id: " << std::this_thread::get_id() << "name: " << GetName() << std::endl
- << std::flush;
- mySettings = std::make_shared<settings::Settings>();
- mySettings->init(service::ServiceProxy(shared_from_this()));
- return sys::ReturnCodes::Success;
- }
- sys::ReturnCodes DeinitHandler() override
- {
- mySettings->deinit();
- std::cout << "deinithandler thr_id: " << std::this_thread::get_id() << std::endl << std::flush;
- return sys::ReturnCodes::Success;
- }
- sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override
- {
- return sys::ReturnCodes::Success;
- }
-
- std::shared_ptr<settings::Settings> getSettings()
- {
- return mySettings;
- }
- };
-
-} // namespace settings