Skip to content

Commit d558e60

Browse files
committed
[CP-2013] Add time sync endpoint
Added endpoint that can be used to synchronize time via MC protocol.
1 parent 85a6dba commit d558e60

40 files changed

+312
-226
lines changed

doc/os_api/protocol_description/common_parameters_explanation.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
- *endpoint* - the target endpoint
44
```
5-
invalid = 0,
6-
deviceInfo = 1,
7-
update = 2,
8-
filesystemUpload = 3,
9-
backup = 4,
10-
restore = 5,
11-
factory = 6,
12-
contacts = 7,
13-
messages = 8,
14-
calllog = 9,
15-
calendarEvents= 10,
16-
developerMode = 11,
17-
bluetooth = 12,
18-
usbSecurity = 13
5+
Invalid = 0,
6+
DeviceInfo = 1,
7+
Update = 2,
8+
FilesystemUpload = 3,
9+
Backup = 4,
10+
Restore = 5,
11+
Factory = 6,
12+
Contacts = 7,
13+
Messages = 8,
14+
Calllog = 9,
15+
CalendarEvents = 10,
16+
DeveloperMode = 11,
17+
Bluetooth = 12,
18+
UsbSecurity = 13,
19+
Outbox = 14,
20+
Reboot = 15,
21+
TimeSync = 16
1922
```
2023

2124
- *method* - the request methods that indicate the desired action to be performed for a given resource.

harmony_changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Added versioning for private assets
1111
* Added greetings in all languages
1212
* Added fade in and fade out to relaxation songs
13+
* Added time sync endpoint to be used by Mudita Center
1314

1415
### Changed / Improved
1516

module-apps/application-desktop/windows/DesktopMainWindow.cpp

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

44
#include "ApplicationDesktop.hpp"
@@ -9,7 +9,6 @@
99
#include <messages/DialogMetadataMessage.hpp>
1010
#include <notifications/NotificationsModel.hpp>
1111
#include <service-appmgr/Controller.hpp>
12-
#include <service-time/TimeMessage.hpp>
1312
#include <time/time_conversion_factory.hpp>
1413
#include <windows/Dialog.hpp>
1514
#include <windows/DialogMetadata.hpp>
@@ -198,13 +197,6 @@ namespace gui
198197
};
199198
}
200199

201-
app::ApplicationDesktop *DesktopMainWindow::getAppDesktop() const
202-
{
203-
const auto app = dynamic_cast<app::ApplicationDesktop *>(application);
204-
assert(app);
205-
return app;
206-
}
207-
208200
RefreshModes DesktopMainWindow::updateTime()
209201
{
210202
AppWindow::updateTime();
@@ -220,4 +212,4 @@ namespace gui
220212
return app::manager::Controller::sendAction(
221213
application, app::manager::actions::Dial, std::make_unique<app::EnterNumberData>(number));
222214
}
223-
} /* namespace gui */
215+
} // namespace gui

module-apps/application-desktop/windows/DesktopMainWindow.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace gui
3232
void setActiveState();
3333
bool processLongReleaseEvent(const InputEvent &inputEvent);
3434
bool processShortReleaseEvent(const InputEvent &inputEvent);
35-
app::ApplicationDesktop *getAppDesktop() const;
3635

3736
public:
3837
explicit DesktopMainWindow(app::ApplicationCommon *app);

module-apps/apps-common/ApplicationCommon.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ namespace app
9595
gui::status_bar::Indicator::PhoneMode});
9696

9797
bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);
98-
9998
bus.channels.push_back(sys::BusChannel::USBNotifications);
99+
bus.channels.push_back(sys::BusChannel::ServiceEvtmgrNotifications);
100100

101101
longPressTimer = sys::TimerFactory::createPeriodicTimer(this,
102102
"LongPress",
@@ -360,6 +360,7 @@ namespace app
360360
case MessageType::KBDKeyEvent:
361361
return handleKBDKeyEvent(msgl);
362362
case MessageType::EVMMinuteUpdated:
363+
case MessageType::EVMTimeUpdated:
363364
return handleMinuteUpdated(msgl);
364365
case MessageType::AppAction:
365366
return handleAction(msgl);
@@ -905,7 +906,7 @@ namespace app
905906
/// request handle actually switches window to popup window
906907
auto retval = request->handle();
907908
if (!retval) {
908-
LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup);
909+
LOG_ERROR("Popup '%s' handling failure, please check registered blueprint!", popup);
909910
}
910911

911912
return retval;

module-services/service-desktop/DesktopMessages.cpp

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

44
#include "service-desktop/DesktopMessages.hpp"
@@ -16,28 +16,28 @@ namespace sdesktop
1616
AppFocusChangeEvent::AppFocusChangeEvent(std::string appName)
1717
{
1818
context.setResponseStatus(http::Code::OK);
19-
context.setEndpoint(EndpointType::developerMode);
19+
context.setEndpoint(EndpointType::DeveloperMode);
2020
context.setResponseBody(json11::Json::object{{json::developerMode::focus, appName}});
2121
}
2222

2323
ScreenlockCheckEvent::ScreenlockCheckEvent(bool isLocked)
2424
{
2525
context.setResponseStatus(http::Code::OK);
26-
context.setEndpoint(EndpointType::developerMode);
26+
context.setEndpoint(EndpointType::DeveloperMode);
2727
context.setResponseBody(json11::Json::object{{json::developerMode::phoneLocked, isLocked}});
2828
}
2929

3030
CellularStateInfoRequestEvent::CellularStateInfoRequestEvent(std::string stateStr)
3131
{
3232
context.setResponseStatus(http::Code::OK);
33-
context.setEndpoint(EndpointType::developerMode);
33+
context.setEndpoint(EndpointType::DeveloperMode);
3434
context.setResponseBody(json11::Json::object{{json::developerMode::cellularStateInfo, stateStr}});
3535
}
3636

3737
CellularSleepModeInfoRequestEvent::CellularSleepModeInfoRequestEvent(bool isInSleepMode)
3838
{
3939
context.setResponseStatus(http::Code::OK);
40-
context.setEndpoint(EndpointType::developerMode);
40+
context.setEndpoint(EndpointType::DeveloperMode);
4141
context.setResponseBody(json11::Json::object{{json::developerMode::cellularSleepModeInfo, isInSleepMode}});
4242
}
4343
} // namespace developerMode

module-services/service-desktop/endpoints/BaseHelper.cpp

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

44
#include <endpoints/BaseHelper.hpp>
55

66
namespace sdesktop::endpoints
77
{
8-
98
auto ret() -> BaseHelper::ProcessResult
109
{
1110
return {sent::no, std::nullopt};
@@ -35,17 +34,16 @@ namespace sdesktop::endpoints
3534
{
3635
preProcess(method, context);
3736
switch (method) {
38-
case http::Method::del:
37+
case http::Method::Del:
3938
return processDelete(context);
40-
case http::Method::get:
39+
case http::Method::Get:
4140
return processGet(context);
42-
case http::Method::post:
41+
case http::Method::Post:
4342
return processPost(context);
44-
case http::Method::put:
43+
case http::Method::Put:
4544
return processPut(context);
4645
}
4746
postProcess(method, context);
4847
return {sent::no, std::nullopt};
4948
}
50-
5149
} // namespace sdesktop::endpoints

module-services/service-desktop/endpoints/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ target_sources(
6565
update/UpdateHelper.cpp
6666
reboot/RebootEndpoint.cpp
6767
reboot/RebootHelper.cpp
68+
timeSync/TimeSyncEndpoint.cpp
69+
timeSync/TimeSyncHelper.cpp
6870
PUBLIC
6971
include/endpoints/backup/BackupEndpoint.hpp
7072
include/endpoints/backup/BackupHelper.hpp
@@ -92,6 +94,8 @@ target_sources(
9294
include/endpoints/update/UpdateHelper.hpp
9395
include/endpoints/reboot/RebootEndpoint.hpp
9496
include/endpoints/reboot/RebootHelper.hpp
97+
include/endpoints/timeSync/TimeSyncEndpoint.hpp
98+
include/endpoints/timeSync/TimeSyncHelper.hpp
9599
)
96100

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

44
#include <endpoints/HttpEnums.hpp>
@@ -7,17 +7,16 @@
77

88
namespace sdesktop::endpoints::http
99
{
10-
11-
auto isMethodValid(uint8_t method) -> bool
10+
auto isMethodValid(std::uint8_t method) -> bool
1211
{
13-
if (method == static_cast<uint8_t>(http::Method::get) || method == static_cast<uint8_t>(http::Method::post) ||
14-
method == static_cast<uint8_t>(http::Method::put) || method == static_cast<uint8_t>(http::Method::del)) {
12+
if (method == static_cast<std::uint8_t>(http::Method::Get) ||
13+
method == static_cast<std::uint8_t>(http::Method::Post) ||
14+
method == static_cast<std::uint8_t>(http::Method::Put) ||
15+
method == static_cast<std::uint8_t>(http::Method::Del)) {
1516
return true;
1617
}
17-
else {
18-
LOG_ERROR("Invalid method!");
19-
return false;
20-
}
21-
}
2218

19+
LOG_ERROR("Invalid method!");
20+
return false;
21+
}
2322
} // namespace sdesktop::endpoints::http
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <endpoints/bluetooth/BluetoothEndpoint.hpp>
55

66
namespace sdesktop::endpoints
77
{
8-
98
auto BluetoothEndpoint::handle(Context &context) -> void
109
{
1110
switch (context.getMethod()) {
12-
case http::Method::get:
11+
case http::Method::Get:
1312
helper->processGetRequest(context);
1413
break;
15-
case http::Method::post:
14+
case http::Method::Post:
1615
helper->processPostRequest(context);
1716
break;
18-
case http::Method::put:
17+
case http::Method::Put:
1918
helper->processPutRequest(context);
2019
break;
21-
case http::Method::del:
20+
case http::Method::Del:
2221
helper->processDeleteRequest(context);
2322
break;
2423
}
2524
}
26-
2725
} // namespace sdesktop::endpoints
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <endpoints/bluetooth/BluetoothEventMessages.hpp>
@@ -8,7 +8,6 @@ namespace sdesktop::bluetooth
88
BluetoothEvent::BluetoothEvent()
99
{
1010
context.setResponseStatus(endpoints::http::Code::OK);
11-
context.setEndpoint(endpoints::EndpointType::bluetooth);
11+
context.setEndpoint(endpoints::EndpointType::Bluetooth);
1212
}
13-
1413
} // namespace sdesktop::bluetooth

module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp

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

44
#include <endpoints/deviceInfo/DeviceInfoEndpointCommon.hpp>
@@ -12,7 +12,7 @@ namespace sdesktop::endpoints
1212
{
1313
http::Code status;
1414
switch (context.getMethod()) {
15-
case http::Method::get:
15+
case http::Method::Get:
1616
status = handleGet(context);
1717
break;
1818
default:
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include <endpoints/factoryReset/FactoryResetEndpoint.hpp>
@@ -14,32 +14,23 @@
1414

1515
namespace sdesktop::endpoints
1616
{
17-
1817
auto FactoryResetEndpoint::handle(Context &context) -> void
1918
{
20-
if (context.getMethod() == http::Method::post) {
21-
19+
if (context.getMethod() == http::Method::Post) {
2220
if (context.getBody()[json::factoryReset::factoryRequest] == true) {
2321
auto msg = std::make_shared<sdesktop::FactoryMessage>();
24-
ownerServicePtr->bus.sendUnicast(msg, service::name::service_desktop);
22+
ownerServicePtr->bus.sendUnicast(std::move(msg), service::name::service_desktop);
2523

2624
context.setResponseBody(json11::Json::object({{json::factoryReset::factoryRequest, true}}));
2725
}
2826
else {
2927
context.setResponseBody(json11::Json::object({{json::factoryReset::factoryRequest, false}}));
3028
}
31-
32-
sender::putToSendQueue(context.createSimpleResponse());
33-
34-
return;
3529
}
3630
else {
3731
context.setResponseBody(json11::Json::object({{json::factoryReset::factoryRequest, false}}));
38-
39-
sender::putToSendQueue(context.createSimpleResponse());
40-
41-
return;
4232
}
43-
}
4433

34+
sender::putToSendQueue(context.createSimpleResponse());
35+
}
4536
} // namespace sdesktop::endpoints

module-services/service-desktop/endpoints/include/endpoints/Context.hpp

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

44
#pragma once
@@ -48,10 +48,10 @@ namespace sdesktop::endpoints
4848
body = json11::Json();
4949
}
5050
if (static_cast<unsigned>(endpoint) > lastEndpoint) {
51-
endpoint = EndpointType::invalid;
51+
endpoint = EndpointType::Invalid;
5252
}
53-
if (method > http::Method::del) {
54-
method = http::Method::get;
53+
if (method > http::Method::Del) {
54+
method = http::Method::Get;
5555
}
5656
}
5757

@@ -67,9 +67,9 @@ namespace sdesktop::endpoints
6767
Context()
6868
{
6969
body = json11::Json();
70-
endpoint = EndpointType::invalid;
70+
endpoint = EndpointType::Invalid;
7171
uuid = invalidUuid;
72-
method = http::Method::get;
72+
method = http::Method::Get;
7373
}
7474
virtual ~Context() noexcept = default;
7575

@@ -186,10 +186,10 @@ namespace sdesktop::endpoints
186186
{
187187
switch (static_cast<EndpointType>(js[json::endpoint].int_value())) {
188188
// enable for pagination in other endpoints
189-
// case EndpointType::calllog:
190-
case EndpointType::contacts:
189+
// case EndpointType::Calllog:
190+
case EndpointType::Contacts:
191191
return std::make_unique<PagedContext>(js, endpoint_pageing::contactsPageSize);
192-
case EndpointType::messages:
192+
case EndpointType::Messages:
193193
return std::make_unique<PagedContext>(js, endpoint_pageing::messagesPageSize);
194194
default:
195195
return std::make_unique<Context>(js);

0 commit comments

Comments
 (0)