From 958ce4906c5386ad8aaa0e7e72697be7388ca9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Smoczy=C5=84ski?= Date: Mon, 20 Sep 2021 15:15:12 +0200 Subject: [PATCH] [BH-897] Split module-sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split system module to better manage dependencies between system components. Signed-off-by: Marcin Smoczyński --- .../ApplicationAntenna.cpp | 2 +- .../ApplicationAntenna.hpp | 2 +- .../application-call/ApplicationCall.cpp | 2 +- .../application-call/ApplicationCall.hpp | 2 +- .../application-clock/ApplicationClock.cpp | 97 +++++++++++++++++++ .../application-clock/ApplicationClock.hpp | 51 ++++++++++ module-apps/apps-common/ApplicationCommon.cpp | 10 +- module-apps/apps-common/CallbackStorage.hpp | 2 +- module-apps/apps-common/GuiTimer.cpp | 4 +- module-apps/apps-common/GuiTimer.hpp | 4 +- .../locks/handlers/PhoneLockHandler.cpp | 2 +- .../locks/handlers/PhoneLockHandler.hpp | 2 +- .../locks/handlers/PhoneLockSubject.hpp | 2 +- .../locks/handlers/SimLockHandler.cpp | 8 +- .../locks/handlers/SimLockHandler.hpp | 4 +- .../locks/handlers/SimLockSubject.hpp | 2 +- .../popups/TetheringConfirmationPopup.cpp | 2 +- .../apps-common/popups/WindowWithTimer.hpp | 2 +- .../popups/data/BluetoothModeParams.hpp | 2 +- .../popups/data/PhoneModeParams.hpp | 2 +- .../popups/data/PopupRequestParams.hpp | 2 +- .../popups/presenter/PowerOffPresenter.cpp | 2 +- .../linux/watchdog/software_watchdog.cpp | 2 +- module-bsp/bsp/vibrator/vibrator.hpp | 6 +- module-gui/gui/widgets/Item.hpp | 2 +- .../service-antenna/ServiceAntenna.cpp | 4 +- .../service-antenna/ServiceAntenna.hpp | 2 +- .../include/service-appmgr/Controller.hpp | 2 +- .../service-audio/ServiceAudio.cpp | 2 +- .../BluetoothDevicesModel.cpp | 2 +- .../CellularRequestHandler.cpp | 6 +- .../service-cellular/handler/RawATHandler.cpp | 2 +- .../service-cellular/handler/RawATHandler.hpp | 2 +- .../service-cellular/ServiceCellular.hpp | 2 +- .../connection-manager/ConnectionManager.hpp | 2 +- .../test-settings-Interface.cpp | 2 +- .../service-desktop/ServiceDesktop.cpp | 8 +- .../developerMode/DeveloperModeHelper.cpp | 4 +- .../ScreenLightControl.hpp | 2 +- .../service-evtmgr/BatteryMessages.hpp | 2 +- .../service-evtmgr/KbdMessage.hpp | 2 +- .../service-evtmgr/vibra/Vibra.cpp | 5 +- .../service-time/AlarmRepository.hpp | 7 +- .../include/service-time/AlarmServiceAPI.hpp | 2 +- .../service-time/RTCCommandInterface.hpp | 2 +- .../service-time/service-time/TimeMessage.hpp | 2 +- module-sys/CMakeLists.txt | 72 +++----------- module-sys/PhoneModes/CMakeLists.txt | 22 +++++ module-sys/PhoneModes/Observer.cpp | 4 +- module-sys/PhoneModes/Subject.cpp | 2 +- .../{ => include/PhoneModes}/Common.hpp | 0 .../{ => include/PhoneModes}/Observer.hpp | 4 +- .../{ => include/PhoneModes}/Subject.hpp | 0 module-sys/Service/BusProxy.cpp | 2 +- module-sys/Service/CMakeLists.txt | 45 +++++++++ module-sys/Service/CpuSentinel.cpp | 2 +- module-sys/Service/Message.cpp | 4 +- module-sys/Service/Service.cpp | 39 ++++---- module-sys/Service/Worker.cpp | 2 +- module-sys/Service/details/bus/Bus.cpp | 4 +- module-sys/Service/details/bus/Bus.hpp | 4 +- .../{ => include/Service}/BusProxy.hpp | 4 +- .../Service/{ => include/Service}/Common.hpp | 0 .../{ => include/Service}/CpuSentinel.hpp | 0 .../Service/{ => include/Service}/Mailbox.hpp | 0 .../Service/{ => include/Service}/Message.hpp | 0 .../{ => include/Service}/MessageForward.hpp | 0 .../Service/{ => include/Service}/Service.hpp | 26 ++--- .../{ => include/Service}/ServiceCreator.hpp | 0 .../{ => include/Service}/ServiceForward.hpp | 0 .../{ => include/Service}/ServiceManifest.hpp | 0 .../{ => include/Service}/ServiceProxy.hpp | 0 .../Service}/SystemReturnCodes.hpp | 0 .../{ => include/Service}/Watchdog.hpp | 0 .../Service/{ => include/Service}/Worker.hpp | 0 .../Service/tests/test-system_messages.cpp | 2 +- module-sys/SystemManager/CMakeLists.txt | 44 +++++++++ module-sys/SystemManager/CpuGovernor.cpp | 2 +- module-sys/SystemManager/CpuStatistics.cpp | 2 +- module-sys/SystemManager/DependencyGraph.cpp | 2 +- module-sys/SystemManager/DeviceManager.cpp | 2 +- module-sys/SystemManager/PowerManager.cpp | 2 +- .../SystemManager/SystemManagerCommon.cpp | 12 +-- .../{ => include/SystemManager}/Constants.hpp | 0 .../SystemManager}/CpuGovernor.hpp | 0 .../SystemManager}/CpuStatistics.hpp | 0 .../SystemManager}/DependencyGraph.hpp | 2 +- .../SystemManager}/DeviceManager.hpp | 0 .../SystemManager}/PowerManager.hpp | 0 .../SystemManager}/SystemManagerCommon.hpp | 0 .../messages/CpuFrequencyMessage.hpp | 0 .../messages/DeviceRegistrationMessage.hpp | 0 .../messages/RequestCpuFrequencyMessage.hpp | 0 .../messages/SentinelRegistrationMessage.hpp | 0 .../messages/SystemManagerMessage.hpp | 0 .../messages/TetheringQuestionRequest.hpp | 2 +- .../messages/TetheringStateRequest.hpp | 2 +- module-sys/SystemWatchdog/CMakeLists.txt | 22 +++++ module-sys/SystemWatchdog/SystemWatchdog.cpp | 2 +- .../SystemWatchdog}/SystemWatchdog.hpp | 2 +- module-sys/Timers/CMakeLists.txt | 25 +++++ module-sys/Timers/SystemTimer.cpp | 6 +- module-sys/Timers/TimerFactory.cpp | 4 +- module-sys/Timers/TimerHandle.cpp | 2 +- .../{ => include/Timers}/SystemTimer.hpp | 2 +- .../Timers/{ => include/Timers}/Timer.hpp | 0 .../{ => include/Timers}/TimerFactory.hpp | 0 .../{ => include/Timers}/TimerHandle.hpp | 0 .../{ => include/Timers}/TimerMessage.hpp | 2 +- .../alarms/src/actions/PlayToneAction.hpp | 2 +- .../presenters/HomeScreenPresenter.cpp | 4 +- .../presenters/HomeScreenPresenter.hpp | 4 +- .../include/appmgr/messages/AlarmMessage.hpp | 2 +- .../services/evtmgr/EventManager.cpp | 2 +- .../ScreenLightControl.cpp | 2 +- .../sys/include/sys/SystemManager.hpp | 2 +- .../services/appmgr/ApplicationManager.cpp | 4 +- .../ScreenLightControl.cpp | 2 +- .../service-fileindexer/StartupIndexer.hpp | 2 +- products/PurePhone/sys/SystemManager.cpp | 6 +- .../sys/include/sys/SystemManager.hpp | 4 +- .../include/sys/messages/PhoneModeRequest.hpp | 2 +- ...heringPhoneModeChangeProhibitedMessage.hpp | 2 +- .../test-service-db-settings-api.cpp | 2 +- 124 files changed, 480 insertions(+), 221 deletions(-) create mode 100644 module-apps/application-clock/ApplicationClock.cpp create mode 100644 module-apps/application-clock/ApplicationClock.hpp create mode 100644 module-sys/PhoneModes/CMakeLists.txt rename module-sys/PhoneModes/{ => include/PhoneModes}/Common.hpp (100%) rename module-sys/PhoneModes/{ => include/PhoneModes}/Observer.hpp (92%) rename module-sys/PhoneModes/{ => include/PhoneModes}/Subject.hpp (100%) create mode 100644 module-sys/Service/CMakeLists.txt rename module-sys/Service/{ => include/Service}/BusProxy.hpp (97%) rename module-sys/Service/{ => include/Service}/Common.hpp (100%) rename module-sys/Service/{ => include/Service}/CpuSentinel.hpp (100%) rename module-sys/Service/{ => include/Service}/Mailbox.hpp (100%) rename module-sys/Service/{ => include/Service}/Message.hpp (100%) rename module-sys/Service/{ => include/Service}/MessageForward.hpp (100%) rename module-sys/Service/{ => include/Service}/Service.hpp (82%) rename module-sys/Service/{ => include/Service}/ServiceCreator.hpp (100%) rename module-sys/Service/{ => include/Service}/ServiceForward.hpp (100%) rename module-sys/Service/{ => include/Service}/ServiceManifest.hpp (100%) rename module-sys/Service/{ => include/Service}/ServiceProxy.hpp (100%) rename module-sys/Service/{ => include/Service}/SystemReturnCodes.hpp (100%) rename module-sys/Service/{ => include/Service}/Watchdog.hpp (100%) rename module-sys/Service/{ => include/Service}/Worker.hpp (100%) create mode 100644 module-sys/SystemManager/CMakeLists.txt rename module-sys/SystemManager/{ => include/SystemManager}/Constants.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/CpuGovernor.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/CpuStatistics.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/DependencyGraph.hpp (96%) rename module-sys/SystemManager/{ => include/SystemManager}/DeviceManager.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/PowerManager.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/SystemManagerCommon.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/CpuFrequencyMessage.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/DeviceRegistrationMessage.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/RequestCpuFrequencyMessage.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/SentinelRegistrationMessage.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/SystemManagerMessage.hpp (100%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/TetheringQuestionRequest.hpp (97%) rename module-sys/SystemManager/{ => include/SystemManager}/messages/TetheringStateRequest.hpp (93%) create mode 100644 module-sys/SystemWatchdog/CMakeLists.txt rename module-sys/SystemWatchdog/{ => include/SystemWatchdog}/SystemWatchdog.hpp (97%) create mode 100644 module-sys/Timers/CMakeLists.txt rename module-sys/Timers/{ => include/Timers}/SystemTimer.hpp (98%) rename module-sys/Timers/{ => include/Timers}/Timer.hpp (100%) rename module-sys/Timers/{ => include/Timers}/TimerFactory.hpp (100%) rename module-sys/Timers/{ => include/Timers}/TimerHandle.hpp (100%) rename module-sys/Timers/{ => include/Timers}/TimerMessage.hpp (93%) diff --git a/module-apps/application-antenna/ApplicationAntenna.cpp b/module-apps/application-antenna/ApplicationAntenna.cpp index 000c314d9..79d39d5dd 100644 --- a/module-apps/application-antenna/ApplicationAntenna.cpp +++ b/module-apps/application-antenna/ApplicationAntenna.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/module-apps/application-antenna/include/application-antenna/ApplicationAntenna.hpp b/module-apps/application-antenna/include/application-antenna/ApplicationAntenna.hpp index 70a5ad45e..3e2f199ee 100644 --- a/module-apps/application-antenna/include/application-antenna/ApplicationAntenna.hpp +++ b/module-apps/application-antenna/include/application-antenna/ApplicationAntenna.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include namespace app diff --git a/module-apps/application-call/ApplicationCall.cpp b/module-apps/application-call/ApplicationCall.cpp index f943afe2e..f99d0be3a 100644 --- a/module-apps/application-call/ApplicationCall.cpp +++ b/module-apps/application-call/ApplicationCall.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/module-apps/application-call/include/application-call/ApplicationCall.hpp b/module-apps/application-call/include/application-call/ApplicationCall.hpp index 7908f525e..46bbbf40e 100644 --- a/module-apps/application-call/include/application-call/ApplicationCall.hpp +++ b/module-apps/application-call/include/application-call/ApplicationCall.hpp @@ -6,7 +6,7 @@ #include "Application.hpp" #include "CallState.hpp" -#include +#include #include #include #include diff --git a/module-apps/application-clock/ApplicationClock.cpp b/module-apps/application-clock/ApplicationClock.cpp new file mode 100644 index 000000000..fcd979b12 --- /dev/null +++ b/module-apps/application-clock/ApplicationClock.cpp @@ -0,0 +1,97 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +// module-gui +#include "AppWindow.hpp" +#include "gui/widgets/Window.hpp" + +// module-utils +#include +#include +#include +#include +// MessageType +#include "MessageType.hpp" +// this module +#include "windows/ClockMainWindow.hpp" +#include "ApplicationClock.hpp" + +namespace app +{ + ApplicationClock::ApplicationClock(std::string name, + std::string parent, + sys::phone_modes::PhoneMode phoneMode, + sys::bluetooth::BluetoothMode bluetoothMode, + StartInBackground startInBackground, + uint32_t stackDepth, + sys::ServicePriority priority) + : Application(name, parent, phoneMode, bluetoothMode, startInBackground, stackDepth, priority) + { + timerClock = sys::TimerFactory::createPeriodicTimer( + this, "Clock", std::chrono::milliseconds{1000}, [&](sys::Timer &) { timerClockCallback(); }); + timerClock.start(); + } + + void ApplicationClock::timerClockCallback() + { + auto win = reinterpret_cast(windowsStack.get(gui::name::window::main_window)); + win->incrementSecond(); + win->updateLabels(); + render(gui::RefreshModes::GUI_REFRESH_FAST); + } + + // Invoked upon receiving data message + sys::MessagePointer ApplicationClock::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) + { + + auto retMsg = Application::DataReceivedHandler(msgl); + // if message was handled by application's template there is no need to process further. + if (reinterpret_cast(retMsg.get())->retCode == sys::ReturnCodes::Success) { + return retMsg; + } + + // this variable defines whether message was processed. + bool handled = false; + // if keyboard message received + + if (handled) + return std::make_shared(); + else + return std::make_shared(sys::ReturnCodes::Unresolved); + } + + // Invoked during initialization + sys::ReturnCodes ApplicationClock::InitHandler() + { + + auto ret = Application::InitHandler(); + if (ret != sys::ReturnCodes::Success) + return ret; + + createUserInterface(); + + setActiveWindow("MainWindow"); + + return ret; + } + + sys::ReturnCodes ApplicationClock::DeinitHandler() + { + timerClock.stop(); + return Application::DeinitHandler(); + } + + void ApplicationClock::createUserInterface() + { + windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) { + return std::make_unique(app, name); + }); + + attachPopups( + {gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock}); + } + + void ApplicationClock::destroyUserInterface() + {} + +} /* namespace app */ diff --git a/module-apps/application-clock/ApplicationClock.hpp b/module-apps/application-clock/ApplicationClock.hpp new file mode 100644 index 000000000..09724eed7 --- /dev/null +++ b/module-apps/application-clock/ApplicationClock.hpp @@ -0,0 +1,51 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once +#include "Application.hpp" +#include "Service/Message.hpp" +#include "gui/widgets/Label.hpp" +#include "gui/widgets/Image.hpp" +#include "gui/widgets/ProgressBar.hpp" +#include "Timers/TimerHandle.hpp" + +namespace app +{ + const inline std::string name_clock = "ApplicationClock"; + + class ApplicationClock : public Application + { + sys::TimerHandle timerClock; + void timerClockCallback(); + + public: + explicit ApplicationClock(std::string name = name_clock, + std::string parent = {}, + sys::phone_modes::PhoneMode phoneMode = sys::phone_modes::PhoneMode::Connected, + sys::bluetooth::BluetoothMode bluetoothMode = sys::bluetooth::BluetoothMode::Disabled, + StartInBackground startInBackground = {false}, + uint32_t stackDepth = 4096, + sys::ServicePriority priority = sys::ServicePriority::Idle); + + sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; + sys::ReturnCodes InitHandler() override; + sys::ReturnCodes DeinitHandler() override; + + sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final + { + return sys::ReturnCodes::Success; + } + + void createUserInterface() override; + void destroyUserInterface() override; + }; + + template <> struct ManifestTraits + { + static auto GetManifest() -> manager::ApplicationManifest + { + return { + {manager::actions::Launch, manager::actions::PhoneModeChanged, manager::actions::BluetoothModeChanged}}; + } + }; +} /* namespace app */ diff --git a/module-apps/apps-common/ApplicationCommon.cpp b/module-apps/apps-common/ApplicationCommon.cpp index 43cd416c3..eee735640 100644 --- a/module-apps/apps-common/ApplicationCommon.cpp +++ b/module-apps/apps-common/ApplicationCommon.cpp @@ -2,11 +2,11 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationCommon.hpp" -#include "Common.hpp" // for RefreshModes -#include "GuiTimer.hpp" // for GuiTimer -#include "Item.hpp" // for Item -#include "MessageType.hpp" // for MessageType -#include "module-sys/Timers/TimerFactory.hpp" // for Timer +#include "Common.hpp" // for RefreshModes +#include "GuiTimer.hpp" // for GuiTimer +#include "Item.hpp" // for Item +#include "MessageType.hpp" // for MessageType +#include "Timers/TimerFactory.hpp" // for Timer #include "StatusBar.hpp" #include "status-bar/Time.hpp" #include "Translator.hpp" // for KeyInputSim... diff --git a/module-apps/apps-common/CallbackStorage.hpp b/module-apps/apps-common/CallbackStorage.hpp index f43311b93..6cc724078 100644 --- a/module-apps/apps-common/CallbackStorage.hpp +++ b/module-apps/apps-common/CallbackStorage.hpp @@ -5,7 +5,7 @@ #include "AsyncTask.hpp" -#include "module-sys/Service/Message.hpp" +#include "Service/Message.hpp" #include #include diff --git a/module-apps/apps-common/GuiTimer.cpp b/module-apps/apps-common/GuiTimer.cpp index 46374a2ab..1378e279d 100644 --- a/module-apps/apps-common/GuiTimer.cpp +++ b/module-apps/apps-common/GuiTimer.cpp @@ -6,8 +6,8 @@ #include // for Application -#include "module-sys/Timers/SystemTimer.hpp" // for Timer, Timer::Type, Timer::Ty... -#include "module-sys/Timers/TimerFactory.hpp" +#include "Timers/SystemTimer.hpp" // for Timer, Timer::Type, Timer::Ty... +#include "Timers/TimerFactory.hpp" #include diff --git a/module-apps/apps-common/GuiTimer.hpp b/module-apps/apps-common/GuiTimer.hpp index d1b28433d..9667ca61b 100644 --- a/module-apps/apps-common/GuiTimer.hpp +++ b/module-apps/apps-common/GuiTimer.hpp @@ -3,8 +3,8 @@ #pragma once -#include "module-sys/Timers/Timer.hpp" // for Timer -#include "module-sys/Timers/TimerHandle.hpp" // for TimerHandle +#include "Timers/Timer.hpp" // for Timer +#include "Timers/TimerHandle.hpp" // for TimerHandle #include #include // for string diff --git a/module-apps/apps-common/locks/handlers/PhoneLockHandler.cpp b/module-apps/apps-common/locks/handlers/PhoneLockHandler.cpp index b1f8aa3f9..5c340bc77 100644 --- a/module-apps/apps-common/locks/handlers/PhoneLockHandler.cpp +++ b/module-apps/apps-common/locks/handlers/PhoneLockHandler.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include