~aleteoryx/muditaos

93eb6be683e169cad8ccb171e476a2305011138b — rrandomsky 1 year, 11 months ago 7a384a6
[BH-1799] Refactor usage of unicasts to dispatch BatteryStatusChangeMessage

Unicast type of sending BatteryStatusChangeMessage is changed to multicast type.
Thanks to this, the flow of messages is more transparent
and there is no unnecessary transmission to non-existent services.
M module-apps/apps-common/ApplicationCommon.cpp => module-apps/apps-common/ApplicationCommon.cpp +3 -3
@@ 844,9 844,9 @@ namespace app

        // two lines below is to **not** loose data on copy on dynamic_cast, but to move the data
        (void)params.release();
        auto data                    = std::unique_ptr<gui::PopupRequestParams>(rdata);
        const auto id                = data->getPopupId();
        auto blueprint               = popupBlueprint.getBlueprint(id);
        auto data      = std::unique_ptr<gui::PopupRequestParams>(rdata);
        const auto id  = data->getPopupId();
        auto blueprint = popupBlueprint.getBlueprint(id);

        const auto topOfWindowsStackId = windowsStack().getWindowData(app::topWindow)->disposition.id;
        if (data->ignoreIfTheSamePopupIsOnTopOfTheStack && id == topOfWindowsStackId) {

M module-services/service-bluetooth/ServiceBluetooth.cpp => module-services/service-bluetooth/ServiceBluetooth.cpp +3 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-bluetooth/ServiceBluetooth.hpp"


@@ 52,11 52,11 @@ namespace
ServiceBluetooth::ServiceBluetooth() : sys::Service(service::name::bluetooth, "", BluetoothServiceStackDepth)
{
    bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);
    bus.channels.push_back(sys::BusChannel::BatteryStatusNotification);
}

ServiceBluetooth::~ServiceBluetooth()
{
}
{}

sys::ReturnCodes ServiceBluetooth::InitHandler()
{

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +5 -5
@@ 131,6 131,7 @@ ServiceCellular::ServiceCellular()
    bus.channels.push_back(sys::BusChannel::ServiceDBNotifications);
    bus.channels.push_back(sys::BusChannel::ServiceEvtmgrNotifications);
    bus.channels.push_back(sys::BusChannel::PhoneModeChanges);
    bus.channels.push_back(sys::BusChannel::BatteryStatusNotification);

    callStateTimer = sys::TimerFactory::createPeriodicTimer(
        this, "call_state", std::chrono::milliseconds{1000}, [this](sys::Timer &) { CallStateTimerHandler(); });


@@ 190,8 191,7 @@ ServiceCellular::ServiceCellular()
}

ServiceCellular::~ServiceCellular()
{
}
{}

void ServiceCellular::SleepTimerHandler()
{


@@ 1371,7 1371,7 @@ bool ServiceCellular::handle_URCReady()
    }

    bool ret = true;
    ret = ret && channel->cmd(at::AT::ENABLE_NETWORK_REGISTRATION_URC);
    ret      = static_cast<bool>(channel->cmd(at::AT::ENABLE_NETWORK_REGISTRATION_URC));

    bus.sendMulticast<cellular::msg::notification::ModemStateChanged>(cellular::api::ModemState::Ready);



@@ 1812,7 1812,7 @@ auto ServiceCellular::handleCellularCallRequestMessage(cellular::CallRequestMess

    if (!request->isHandled()) {
        const auto errorType = translate(result.code);
        auto message = std::make_shared<cellular::CallRequestGeneralError>(errorType);
        auto message         = std::make_shared<cellular::CallRequestGeneralError>(errorType);
        bus.sendUnicast(message, ::service::name::appmgr);
    }



@@ 1941,7 1941,7 @@ auto ServiceCellular::handleCellularSelectAntennaMessage(sys::Message *msg) -> s
}
auto ServiceCellular::handleCellularSetScanModeMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    auto message = static_cast<cellular::SetScanModeMessage *>(msg);
    auto message   = static_cast<cellular::SetScanModeMessage *>(msg);
    const auto ret = SetScanMode(message->data);

    return std::make_shared<cellular::ResponseMessage>(ret);

M module-services/service-cellular/src/ServiceCellularPriv.cpp => module-services/service-cellular/src/ServiceCellularPriv.cpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ServiceCellularPriv.hpp"


@@ 62,7 62,7 @@ namespace cellular::internal
        simCard->onSimReady = [this]() {
            state->set(State::ST::Ready);

            auto channel     = owner->cmux->get(CellularMux::Channel::Commands);
            auto channel = owner->cmux->get(CellularMux::Channel::Commands);

            const auto permitVolte = volteCapability->isVolteAllowed(*channel);
            const auto enableVolte =

M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +2 -5
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-evtmgr/BatteryMessages.hpp"


@@ 59,6 59,7 @@ EventManagerCommon::EventManagerCommon(LogDumpFunction logDumpFunction,
    alarmTimestamp = 0;
    alarmID        = 0;
    bus.channels.push_back(sys::BusChannel::ServiceDBNotifications);
    bus.channels.push_back(sys::BusChannel::BatteryStatusNotification);
}

EventManagerCommon::~EventManagerCommon()


@@ 145,10 146,6 @@ sys::ReturnCodes EventManagerCommon::InitHandler()
            if (!targetApplication.empty()) {
                bus.sendUnicast(std::make_shared<sevm::BatteryStatusChangeMessage>(), targetApplication);
            }
            bus.sendUnicast(std::make_shared<sevm::BatteryStatusChangeMessage>(), service::name::appmgr);
            bus.sendUnicast(std::make_shared<sevm::BatteryStatusChangeMessage>(), service::name::service_desktop);
            bus.sendUnicast(std::make_shared<sevm::BatteryStatusChangeMessage>(), service::name::bluetooth);
            bus.sendUnicast(std::make_shared<sevm::BatteryStatusChangeMessage>(), service::name::cellular);
        }
        return sys::msgHandled();
    });

M module-services/service-evtmgr/battery/BatteryController.cpp => module-services/service-evtmgr/battery/BatteryController.cpp +6 -6
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryController.hpp"


@@ 132,7 132,7 @@ BatteryController::BatteryController(sys::Service *service, xQueueHandle notific
                   params.battery}
{
    updateSoc();
    Store::Battery::modify().state = transformChargingState(charger->getChargingStatus());
    Store::Battery::modify().state       = transformChargingState(charger->getChargingStatus());
    Store::Battery::modify().temperature = transformTemperatureState(charger->getTemperatureState());
    batteryState.check(transformChargingState(Store::Battery::get().state),
                       static_cast<float>(Store::Battery::get().level));


@@ 179,12 179,12 @@ void sevm::battery::BatteryController::printCurrentState()

void sevm::battery::BatteryController::update()
{
    const auto lastSoc   = Store::Battery::get().level;
    const auto lastState = Store::Battery::get().state;
    const auto lastSoc         = Store::Battery::get().level;
    const auto lastState       = Store::Battery::get().state;
    const auto lastTemperature = Store::Battery::get().temperature;

    updateSoc();
    Store::Battery::modify().state = transformChargingState(charger->getChargingStatus());
    Store::Battery::modify().state       = transformChargingState(charger->getChargingStatus());
    Store::Battery::modify().temperature = transformTemperatureState(charger->getTemperatureState());

    const auto currentSoc         = Store::Battery::get().level;


@@ 194,7 194,7 @@ void sevm::battery::BatteryController::update()
    /// Send BatteryStatusChangeMessage only when battery SOC, charger state or temperature has changed
    if ((lastSoc != currentSoc) || (lastState != currentState) || (lastTemperature != currentTemperature)) {
        auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
        service->bus.sendUnicast(std::move(message), service::name::evt_manager);
        service->bus.sendMulticast(std::move(message), sys::BusChannel::BatteryStatusNotification);
    }

    if (isFirstUpdateDone) {

M module-sys/common/include/system/Common.hpp => module-sys/common/include/system/Common.hpp +4 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 14,6 14,7 @@ namespace sys
        System,
        SystemManagerRequests,
        PowerManagerRequests,
        BatteryStatusNotification,
        USBNotifications,
        ServiceCellularNotifications,
        Test2CustomBusChannel,


@@ 111,6 112,8 @@ inline const char *c_str(sys::BusChannel channel)
        return "SystemManagerRequests";
    case sys::BusChannel::PowerManagerRequests:
        return "PowerManagerRequests";
    case sys::BusChannel::BatteryStatusNotification:
        return "BatteryStatusNotification";
    case sys::BusChannel::USBNotifications:
        return "USBNotifications";
    case sys::BusChannel::ServiceCellularNotifications:

M products/PurePhone/services/appmgr/ApplicationManager.cpp => products/PurePhone/services/appmgr/ApplicationManager.cpp +1 -0
@@ 58,6 58,7 @@ namespace app::manager
        constexpr auto updateAllowed = false;
        notificationProvider.handleBatteryTooHot(isBatteryTooHotWhilePlugged(), updateAllowed);

        bus.channels.push_back(sys::BusChannel::BatteryStatusNotification);
        bus.channels.push_back(sys::BusChannel::BluetoothModeChanges);
        bus.channels.push_back(sys::BusChannel::BluetoothNotifications);
        bus.channels.push_back(sys::BusChannel::PhoneModeChanges);