Skip to content

Commit 65119cb

Browse files
Piotr TańskiPiotr Tanski
Piotr Tański
authored and
Piotr Tanski
committed
[EGD-5027] Services synchronization introduced
Dependencies between services are now supported.
1 parent e1400ae commit 65119cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1048
-253
lines changed

module-apps/ApplicationLauncher.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -79,14 +79,14 @@ namespace app
7979
{
8080
parent = (caller == nullptr ? "" : caller->GetName());
8181
handle = std::make_shared<T>(name, parent);
82-
return sys::SystemManager::CreateService(handle, caller);
82+
return sys::SystemManager::RunService(handle, caller);
8383
}
8484

8585
bool runBackground(sys::Service *caller) override
8686
{
8787
parent = (caller == nullptr ? "" : caller->GetName());
8888
handle = std::make_shared<T>(name, parent, true);
89-
return sys::SystemManager::CreateService(handle, caller);
89+
return sys::SystemManager::RunService(handle, caller);
9090
}
9191
};
9292

module-apps/application-settings-new/windows/AddDeviceWindow.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#include <i18n/i18n.hpp>
1010
#include <utility>
1111

12+
extern "C"
13+
{
14+
#include <module-bluetooth/lib/btstack/src/btstack_util.h>
15+
}
16+
1217
namespace gui
1318
{
1419

module-apps/application-settings/windows/BtScanWindow.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
#include <Style.hpp>
1818

19+
extern "C"
20+
{
21+
#include <module-bluetooth/lib/btstack/src/btstack_util.h>
22+
}
23+
1924
namespace gui
2025
{
2126

module-db/Database/Database.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "Database.hpp"
@@ -70,7 +70,7 @@ Database::Database(const char *name)
7070
{
7171
LOG_INFO("Creating database: %s", dbName.c_str());
7272
if (const auto rc = sqlite3_open(name, &dbConnection); rc != SQLITE_OK) {
73-
LOG_ERROR("SQLITE INITIALIZATION ERROR! rc=%d dbName=%s", rc, name);
73+
LOG_ERROR("SQLITE INITIALIZATION ERROR! rc=%d ( %s ) dbName=%s", rc, sqlite3_errstr(rc), name);
7474
throw DatabaseInitialisationError{"Failed to initialize the sqlite db"};
7575
}
7676

module-services/service-antenna/ServiceAntenna.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "service-antenna/ServiceAntenna.hpp"
@@ -25,8 +25,6 @@
2525
#include <string>
2626
#include <vector>
2727

28-
const char *ServiceAntenna::serviceName = "ServiceAntenna";
29-
3028
namespace antenna
3129
{
3230
const char *c_str(antenna::State state)
@@ -55,9 +53,9 @@ namespace antenna
5553
}
5654
} // namespace antenna
5755

58-
ServiceAntenna::ServiceAntenna() : sys::Service(serviceName)
56+
ServiceAntenna::ServiceAntenna() : sys::Service(service::name::antenna)
5957
{
60-
LOG_INFO("[%s] Initializing", serviceName);
58+
LOG_INFO("[%s] Initializing", service::name::antenna);
6159

6260
timer = std::make_unique<sys::Timer>("Antena", this, 5000, sys::Timer::Type::Periodic);
6361
timer->connect([&](sys::Timer &) {
@@ -80,7 +78,7 @@ ServiceAntenna::ServiceAntenna() : sys::Service(serviceName)
8078

8179
ServiceAntenna::~ServiceAntenna()
8280
{
83-
LOG_INFO("[%s] Cleaning resources", serviceName);
81+
LOG_INFO("[%s] Cleaning resources", service::name::antenna);
8482
}
8583

8684
// Invoked upon receiving data message

module-services/service-antenna/api/AntennaServiceAPI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <service-antenna/AntennaServiceAPI.hpp>
@@ -29,7 +29,7 @@ namespace AntennaServiceAPI
2929
bool LockRequest(sys::Service *serv, antenna::lockState request)
3030
{
3131
auto msg = std::make_shared<AntennaLockRequestMessage>(MessageType::AntennaLockService, request);
32-
auto ret = serv->bus.sendUnicast(msg, ServiceAntenna::serviceName, 5000);
32+
auto ret = serv->bus.sendUnicast(msg, service::name::antenna, 5000);
3333
if (ret.first == sys::ReturnCodes::Success) {
3434

3535
return true;
@@ -40,7 +40,7 @@ namespace AntennaServiceAPI
4040
bool GetLockState(sys::Service *serv, antenna::lockState &response)
4141
{
4242
auto msg = std::make_shared<AntennaLockRequestMessage>(MessageType::AntennaGetLockState);
43-
auto ret = serv->bus.sendUnicast(msg, ServiceAntenna::serviceName, 5000);
43+
auto ret = serv->bus.sendUnicast(msg, service::name::antenna, 5000);
4444
if (ret.first == sys::ReturnCodes::Success) {
4545
auto responseMsg = dynamic_cast<AntennaLockRequestResponse *>(ret.second.get());
4646
if (responseMsg != nullptr) {

module-services/service-antenna/service-antenna/ServiceAntenna.hpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -10,6 +10,7 @@
1010
#include <Service/Message.hpp>
1111
#include <Service/Service.hpp>
1212
#include <Service/Worker.hpp>
13+
#include <service-db/DBServiceName.hpp>
1314

1415
#include <algorithm>
1516
#include <cassert>
@@ -28,6 +29,11 @@ namespace utils
2829
} // namespace state
2930
} // namespace utils
3031

32+
namespace service::name
33+
{
34+
constexpr inline auto antenna = "ServiceAntenna";
35+
} // namespace service::name
36+
3137
namespace antenna
3238
{
3339
enum class State
@@ -76,8 +82,6 @@ class ServiceAntenna : public sys::Service
7682
bool suspended = false;
7783

7884
public:
79-
static const char *serviceName;
80-
8185
ServiceAntenna();
8286
~ServiceAntenna();
8387

@@ -102,3 +106,17 @@ class ServiceAntenna : public sys::Service
102106
bool csqChangeStateHandler(void);
103107
bool lockedStateHandler(void);
104108
};
109+
110+
namespace sys
111+
{
112+
template <> struct ManifestTraits<ServiceAntenna>
113+
{
114+
static auto GetManifest() -> ServiceManifest
115+
{
116+
ServiceManifest manifest;
117+
manifest.name = service::name::antenna;
118+
manifest.dependencies = {service::name::db};
119+
return manifest;
120+
}
121+
};
122+
} // namespace sys

module-services/service-appmgr/model/ApplicationManager.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ namespace app::manager
157157
},
158158
::settings::SettingsScope::Global);
159159

160-
startSystemServices();
161160
startBackgroundApplications();
162161
if (auto app = getApplication(rootApplicationName); app != nullptr) {
163162
Controller::sendAction(this, actions::Home);
@@ -166,20 +165,6 @@ namespace app::manager
166165
return sys::ReturnCodes::Success;
167166
}
168167

169-
void ApplicationManager::startSystemServices()
170-
{
171-
if (bool ret = sys::SystemManager::CreateService(
172-
std::make_shared<service::gui::ServiceGUI>(service::name::gui, GetName()), this);
173-
!ret) {
174-
LOG_ERROR("Failed to initialize GUI service");
175-
}
176-
if (bool ret = sys::SystemManager::CreateService(
177-
std::make_shared<service::eink::ServiceEink>(service::name::eink, GetName()), this);
178-
!ret) {
179-
LOG_ERROR("Failed to initialize EInk service");
180-
}
181-
}
182-
183168
void ApplicationManager::suspendSystemServices()
184169
{
185170
sys::SystemManager::SuspendService(service::name::gui, this);

module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
#include <string_view>
2323
#include <vector>
2424

25+
#include <service-db/DBServiceName.hpp>
2526
#include <service-db/Settings.hpp>
27+
#include <service-gui/Common.hpp>
28+
#include <service-eink/Common.hpp>
2629

2730
namespace app
2831
{
@@ -100,7 +103,6 @@ namespace app::manager
100103

101104
private:
102105
auto startApplication(ApplicationHandle &app) -> bool;
103-
void startSystemServices();
104106
void startBackgroundApplications();
105107
void rebuildActiveApplications();
106108
void suspendSystemServices();
@@ -158,3 +160,17 @@ namespace app::manager
158160
std::string displayLanguage;
159161
};
160162
} // namespace app::manager
163+
164+
namespace sys
165+
{
166+
template <> struct ManifestTraits<app::manager::ApplicationManager>
167+
{
168+
static auto GetManifest() -> ServiceManifest
169+
{
170+
ServiceManifest manifest;
171+
manifest.name = app::manager::ApplicationManager::ServiceName;
172+
manifest.dependencies = {service::name::db, service::name::gui, service::name::eink};
173+
return manifest;
174+
}
175+
};
176+
} // namespace sys

module-services/service-audio/AudioServiceAPI.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "service-audio/AudioServiceAPI.hpp"
@@ -25,7 +25,7 @@ namespace AudioServiceAPI
2525
{
2626
auto msgType = static_cast<int>(msg->type);
2727
LOG_DEBUG("Msg type %d", msgType);
28-
auto ret = serv->bus.sendUnicast(msg, ServiceAudio::serviceName, sys::BusProxy::defaultTimeout);
28+
auto ret = serv->bus.sendUnicast(msg, service::name::audio, sys::BusProxy::defaultTimeout);
2929
if (ret.first == sys::ReturnCodes::Success) {
3030
if (auto resp = std::dynamic_pointer_cast<AudioResponseMessage>(ret.second)) {
3131
LOG_DEBUG("Msg type %d done", msgType);
@@ -42,19 +42,19 @@ namespace AudioServiceAPI
4242
bool PlaybackStart(sys::Service *serv, const audio::PlaybackType &playbackType, const std::string &fileName)
4343
{
4444
auto msg = std::make_shared<AudioStartPlaybackRequest>(fileName, playbackType);
45-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
45+
return serv->bus.sendUnicast(msg, service::name::audio);
4646
}
4747

4848
bool RecordingStart(sys::Service *serv, const std::string &fileName)
4949
{
5050
auto msg = std::make_shared<AudioStartRecorderRequest>(fileName);
51-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
51+
return serv->bus.sendUnicast(msg, service::name::audio);
5252
}
5353

5454
bool RoutingStart(sys::Service *serv)
5555
{
5656
auto msg = std::make_shared<AudioStartRoutingRequest>();
57-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
57+
return serv->bus.sendUnicast(msg, service::name::audio);
5858
}
5959

6060
bool Stop(sys::Service *serv, const std::vector<audio::PlaybackType> &stopVec)
@@ -63,43 +63,43 @@ namespace AudioServiceAPI
6363
return true;
6464
}
6565
auto msg = std::make_shared<AudioStopRequest>(stopVec);
66-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
66+
return serv->bus.sendUnicast(msg, service::name::audio);
6767
}
6868

6969
bool Stop(sys::Service *serv, const audio::Token &token)
7070
{
7171
auto msg = std::make_shared<AudioStopRequest>(token);
72-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
72+
return serv->bus.sendUnicast(msg, service::name::audio);
7373
}
7474

7575
bool StopAll(sys::Service *serv)
7676
{
7777
auto msg = std::make_shared<AudioStopRequest>();
78-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
78+
return serv->bus.sendUnicast(msg, service::name::audio);
7979
}
8080

8181
bool Pause(sys::Service *serv, const audio::Token &token)
8282
{
8383
auto msg = std::make_shared<AudioPauseRequest>(token);
84-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
84+
return serv->bus.sendUnicast(msg, service::name::audio);
8585
}
8686

8787
bool Resume(sys::Service *serv, const audio::Token &token)
8888
{
8989
auto msg = std::make_shared<AudioResumeRequest>(token);
90-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
90+
return serv->bus.sendUnicast(msg, service::name::audio);
9191
}
9292

9393
bool SendEvent(sys::Service *serv, std::shared_ptr<audio::Event> evt)
9494
{
9595
auto msg = std::make_shared<AudioEventRequest>(std::move(evt));
96-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
96+
return serv->bus.sendUnicast(msg, service::name::audio);
9797
}
9898

9999
bool SendEvent(sys::Service *serv, audio::EventType eType, audio::Event::DeviceState state)
100100
{
101101
auto msg = std::make_shared<AudioEventRequest>(eType, state);
102-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
102+
return serv->bus.sendUnicast(msg, service::name::audio);
103103
}
104104

105105
template <typename T>
@@ -164,7 +164,7 @@ namespace AudioServiceAPI
164164
bool KeyPressed(sys::Service *serv, const int step)
165165
{
166166
auto msg = std::make_shared<AudioKeyPressedRequest>(step);
167-
return serv->bus.sendUnicast(msg, ServiceAudio::serviceName);
167+
return serv->bus.sendUnicast(msg, service::name::audio);
168168
}
169169

170170
} // namespace AudioServiceAPI

module-services/service-audio/ServiceAudio.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313

1414
#include <type_traits>
1515

16-
const char *ServiceAudio::serviceName = "ServiceAudio";
17-
1816
using namespace audio;
1917

2018
ServiceAudio::ServiceAudio()
21-
: sys::Service(serviceName, "", 4096 * 2, sys::ServicePriority::Idle),
19+
: sys::Service(service::name::audio, "", 4096 * 2, sys::ServicePriority::Idle),
2220
audioMux([this](auto... params) { return this->AudioServicesCallback(params...); }),
2321
settingsProvider(std::make_unique<settings::Settings>(this))
2422
{
@@ -426,7 +424,7 @@ void ServiceAudio::HandleNotification(const AudioNotificationMessage::Type &type
426424
}
427425
else {
428426
auto newMsg = std::make_shared<AudioStopRequest>(token);
429-
bus.sendUnicast(newMsg, ServiceAudio::serviceName);
427+
bus.sendUnicast(newMsg, service::name::audio);
430428
}
431429
return;
432430
}

0 commit comments

Comments
 (0)