From a88ccfe49e84b05773f5595acff255612d2f3ddd Mon Sep 17 00:00:00 2001 From: Adam Dobrowolski Date: Fri, 8 Apr 2022 10:22:44 +0200 Subject: [PATCH] [MOS-327] Removed call manager call logic in library Moved call handling to separate library and removed CallManager Apply suggestions from code review: Co-authored-by: Bartosz Cichocki Co-authored-by: Mateusz Piesta --- module-cellular/at/cmd/src/CLCC.cpp | 1 - .../service-cellular/CMakeLists.txt | 9 ++-- .../service-cellular/ServiceCellular.cpp | 42 ++++--------------- .../service-cellular/call/CMakeLists.txt | 26 ++++++++++++ .../service-cellular/call/CallMulticast.cpp | 18 ++++++++ .../service-cellular/call/CallMulticast.hpp | 22 ++++++++++ .../service-cellular/call/CallRingGuard.cpp | 2 +- .../service-cellular/call/CellularCall.cpp | 6 ++- .../service-cellular/call/README.md | 10 +++++ .../include}/call/CellularCall.hpp | 2 + .../service-cellular/ServiceCellular.hpp | 4 +- .../service-cellular/src/CallManager.cpp | 33 --------------- .../service-cellular/src/CallManager.hpp | 22 ---------- 13 files changed, 96 insertions(+), 101 deletions(-) create mode 100644 module-services/service-cellular/call/CMakeLists.txt create mode 100644 module-services/service-cellular/call/CallMulticast.cpp create mode 100644 module-services/service-cellular/call/CallMulticast.hpp create mode 100644 module-services/service-cellular/call/README.md rename module-services/service-cellular/{service-cellular => call/include}/call/CellularCall.hpp (98%) delete mode 100644 module-services/service-cellular/src/CallManager.cpp delete mode 100644 module-services/service-cellular/src/CallManager.hpp diff --git a/module-cellular/at/cmd/src/CLCC.cpp b/module-cellular/at/cmd/src/CLCC.cpp index 7f6d73af813ffa2cc27b9b2112d8856e9321add7..8baa0dc636fd90f3629df5a25e12ee74c6e43c2a 100644 --- a/module-cellular/at/cmd/src/CLCC.cpp +++ b/module-cellular/at/cmd/src/CLCC.cpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace at { diff --git a/module-services/service-cellular/CMakeLists.txt b/module-services/service-cellular/CMakeLists.txt index 78c97658ae2cc67dd1e423274b130a87da2ade7d..31908c49095bd4f29012cd0b2f058926e2098197 100644 --- a/module-services/service-cellular/CMakeLists.txt +++ b/module-services/service-cellular/CMakeLists.txt @@ -5,7 +5,6 @@ set(SOURCES src/ServiceCellularPriv.cpp src/State.cpp src/SimCard.cpp - src/CallManager.cpp src/NetworkTime.cpp src/SimContacts.cpp src/SMSPartsHandler.cpp @@ -16,11 +15,6 @@ set(SOURCES src/URCCounter.cpp src/CSQHandler.cpp - call/CellularCall.cpp - call/CallAudio.cpp - call/CallGUI.cpp - call/CallDB.cpp - call/CallRingGuard.cpp CellularServiceAPI.cpp CellularUrcHandler.cpp checkSmsCenter.cpp @@ -59,6 +53,8 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src ) +add_subdirectory(call) + target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL @@ -72,6 +68,7 @@ target_link_libraries(${PROJECT_NAME} json::json utils-time PUBLIC + service-cellular-call eventstore utf8 hal diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 9b5ff29c82327bc9ea1cae8ccb4f2eb6469ff995..3cbceb164439d9c2563958a2d6e2deb0b377a936 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -4,7 +4,6 @@ #include "endpoints/developerMode/event/ATRequest.hpp" #include "handler/RawATHandler.hpp" #include "CellularUrcHandler.hpp" -#include "service-cellular/call/CellularCall.hpp" #include "service-cellular/CellularMessage.hpp" #include "service-cellular/CellularServiceAPI.hpp" #include "service-cellular/ServiceCellular.hpp" @@ -492,11 +491,6 @@ void ServiceCellular::registerMessageHandlers() return handleCellularRingingMessage(msg); }); - connect(typeid(CellularCallerIdMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto msg = static_cast(request); - return handleCellularCallerIdMessage(msg); - }); - connect(typeid(CellularGetIMSIMessage), [&](sys::Message *request) -> sys::MessagePointer { return handleCellularGetIMSIMessage(request); }); @@ -1857,7 +1851,6 @@ void ServiceCellular::handleCellularHangupCallMessage(CellularHangupCallMessage auto channel = cmux->get(CellularMux::Channel::Commands); if (channel) { if (channel->cmd(at::AT::ATH)) { - callManager.hangUp(); callStateTimer.stop(); callEndedRecentlyTimer.start(); if (!ongoingCall.endCall(CellularCall::Forced::True)) { @@ -1946,17 +1939,6 @@ auto ServiceCellular::handleCellularRingingMessage(CellularRingingMessage *msg) return std::make_shared(ongoingCall.startOutgoing(msg->number)); } -auto ServiceCellular::handleCellularCallerIdMessage(sys::Message *msg) -> std::shared_ptr -{ - auto message = static_cast(msg); - if (not ongoingCall.handleCLIP(message->number)) { - CellularServiceAPI::DismissCall( - this, phoneModeObserver->getCurrentPhoneMode() == sys::phone_modes::PhoneMode::DoNotDisturb); - } - - return sys::MessageNone{}; -} - auto ServiceCellular::handleCellularGetIMSIMessage(sys::Message *msg) -> std::shared_ptr { std::string temp; @@ -2143,8 +2125,10 @@ auto ServiceCellular::handleCallActiveNotification(sys::Message *msg) -> std::sh auto ServiceCellular::handleCallAbortedNotification(sys::Message *msg) -> std::shared_ptr { callStateTimer.stop(); - auto ret = ongoingCall.endCall(); - callManager.hangUp(); + const auto ret = ongoingCall.endCall(); + if (not ret) { + LOG_ERROR("failed to end call"); + } return std::make_shared(ret); } auto ServiceCellular::handlePowerUpProcedureCompleteNotification(sys::Message *msg) @@ -2219,14 +2203,6 @@ auto ServiceCellular::handleCellularRingNotification(sys::Message *msg) -> std:: } ongoingCall.handleRING(); - /// NOTE: the code below should be investigated as there is something weird in this flow - /// most probably should be done on not dropped clip/ring - /// please see that in this case we lock antena, which makes sense when call is in progress - if (!callManager.isIncomingCallPropagated()) { - bus.sendMulticast(std::make_shared(), - sys::BusChannel::ServiceCellularNotifications); - callManager.ring(); - } return std::make_shared(true); } @@ -2242,11 +2218,11 @@ auto ServiceCellular::handleCellularCallerIdNotification(sys::Message *msg) -> s return std::make_shared(hangUpCallBusy()); } - if (!callManager.isCallerInfoComplete()) { - bus.sendMulticast(std::make_shared(message->getNubmer()), - sys::BusChannel::ServiceCellularNotifications); - callManager.completeCallerInfo(); + if (not ongoingCall.handleCLIP(message->getNubmer())) { + CellularServiceAPI::DismissCall( + this, phoneModeObserver->getCurrentPhoneMode() == sys::phone_modes::PhoneMode::DoNotDisturb); } + return std::make_shared(true); } @@ -2268,7 +2244,7 @@ auto ServiceCellular::hangUpCall() -> bool auto channel = cmux->get(CellularMux::Channel::Commands); if (channel != nullptr) { if (channel->cmd(at::factory(at::AT::ATH))) { - callManager.hangUp(); + ongoingCall.endCall(); return true; } } diff --git a/module-services/service-cellular/call/CMakeLists.txt b/module-services/service-cellular/call/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc3a539a3612b20a2185de7813723ba2b356a142 --- /dev/null +++ b/module-services/service-cellular/call/CMakeLists.txt @@ -0,0 +1,26 @@ +project(service-cellular-call) +message( "${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}" ) + +add_library(${PROJECT_NAME} STATIC + CellularCall.cpp + CallAudio.cpp + CallGUI.cpp + CallDB.cpp + CallMulticast.cpp + CallRingGuard.cpp +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ./include/ +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + module-sys + ) + +# uncomment to add tests: +# if (${ENABLE_TESTS}) +# add_subdirectory(tests) +# endif () diff --git a/module-services/service-cellular/call/CallMulticast.cpp b/module-services/service-cellular/call/CallMulticast.cpp new file mode 100644 index 0000000000000000000000000000000000000000..468bf311d95173e0d44631e783489eac0744d0a0 --- /dev/null +++ b/module-services/service-cellular/call/CallMulticast.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "CallMulticast.hpp" +#include "service-cellular/CellularMessage.hpp" +#include + +void CallMulticast::notifyIncommingCall() +{ + owner.bus.sendMulticast(std::make_shared(), + sys::BusChannel::ServiceCellularNotifications); +} + +void CallMulticast::notifyIdentifiedCall(const utils::PhoneNumber::View &number) +{ + owner.bus.sendMulticast(std::make_shared(number), + sys::BusChannel::ServiceCellularNotifications); +} diff --git a/module-services/service-cellular/call/CallMulticast.hpp b/module-services/service-cellular/call/CallMulticast.hpp new file mode 100644 index 0000000000000000000000000000000000000000..135a08cafe401a05780740cd9974bb163ee831d0 --- /dev/null +++ b/module-services/service-cellular/call/CallMulticast.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace sys +{ + class Service; +} + +class CallMulticast +{ + sys::Service &owner; + + public: + explicit CallMulticast(sys::Service &owner) : owner(owner) + {} + void notifyIncommingCall(); + void notifyIdentifiedCall(const utils::PhoneNumber::View &number); +}; diff --git a/module-services/service-cellular/call/CallRingGuard.cpp b/module-services/service-cellular/call/CallRingGuard.cpp index d4cc257ab77c242f871392f72c25ed5cc0532529..c4db7804a154f5365d9d0f65d0ddc79d0cdcef9e 100644 --- a/module-services/service-cellular/call/CallRingGuard.cpp +++ b/module-services/service-cellular/call/CallRingGuard.cpp @@ -2,7 +2,7 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "CallRingGuard.hpp" -#include "service-cellular/call/CellularCall.hpp" +#include "call/CellularCall.hpp" bool callRingGuard(CellularCall::Call &call) { diff --git a/module-services/service-cellular/call/CellularCall.cpp b/module-services/service-cellular/call/CellularCall.cpp index ee1c98afe2b0c15d82fee5331f2371424bfb6edc..8f6587658d2c47b99cff30028850591d7b4580d8 100644 --- a/module-services/service-cellular/call/CellularCall.cpp +++ b/module-services/service-cellular/call/CellularCall.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "service-cellular/call/CellularCall.hpp" +#include "call/CellularCall.hpp" #include "service-cellular/call/CallRingGuard.hpp" #include "service-cellular/ServiceCellular.hpp" #include "service-db/agents/settings/SystemSettings.hpp" @@ -22,7 +22,7 @@ namespace CellularCall { - Call::Call(ServiceCellular &owner) : owner(owner), audio(owner), gui(owner), db(owner) + Call::Call(ServiceCellular &owner) : owner(owner), audio(owner), multicast(owner), gui(owner), db(owner) { utils::PhoneNumber::View number = utils::PhoneNumber::View(); const CallType type = CallType::CT_NONE; @@ -47,6 +47,7 @@ namespace CellularCall if (!wasRinging) { wasRinging = true; gui.notifyRING(); + multicast.notifyIncommingCall(); } return true; } @@ -65,6 +66,7 @@ namespace CellularCall if (!isNumberDisplayed) { isNumberDisplayed = true; gui.notifyCLIP(number); + multicast.notifyIdentifiedCall(number); } return true; } diff --git a/module-services/service-cellular/call/README.md b/module-services/service-cellular/call/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1fb8b8ab43737dce9fb8a9bdfc467e2db206122d --- /dev/null +++ b/module-services/service-cellular/call/README.md @@ -0,0 +1,10 @@ +Encapsulated cellular call processing +===================================== + +This library's goal is to encapsulate the whole call flow/flows we can have. +It's end goal is to provide: actions and guards to write call state machine to asure full control over call processing. + +# library organisation + +Public api headers should be placed in `include/call/` catalog - these are exported in cmake to include paths for related libraries +All other headers should **not** be placed there. These are private internals of the library diff --git a/module-services/service-cellular/service-cellular/call/CellularCall.hpp b/module-services/service-cellular/call/include/call/CellularCall.hpp similarity index 98% rename from module-services/service-cellular/service-cellular/call/CellularCall.hpp rename to module-services/service-cellular/call/include/call/CellularCall.hpp index 0bea8ddb4876eecd3900f906119fc5995bd05743..a447eeb3abd8b3152963bf1e31ac3d4151f19e6a 100644 --- a/module-services/service-cellular/service-cellular/call/CellularCall.hpp +++ b/module-services/service-cellular/call/include/call/CellularCall.hpp @@ -6,6 +6,7 @@ #include "call/CallAudio.hpp" #include "call/CallGUI.hpp" #include "call/CallDB.hpp" +#include "call/CallMulticast.hpp" #include "PhoneModes/PhoneMode.hpp" #include #include @@ -70,6 +71,7 @@ namespace CellularCall ServiceCellular &owner; CallRingAudio audio; + CallMulticast multicast; CallGUI gui; CallDB db; diff --git a/module-services/service-cellular/service-cellular/ServiceCellular.hpp b/module-services/service-cellular/service-cellular/ServiceCellular.hpp index 020747e1def8d3423258e9c59c643f15ca1fedfb..0140a136f901a40cac14173277f13136e0d7509b 100644 --- a/module-services/service-cellular/service-cellular/ServiceCellular.hpp +++ b/module-services/service-cellular/service-cellular/ServiceCellular.hpp @@ -3,12 +3,11 @@ #pragma once -#include "call/CellularCall.hpp" +#include #include "CellularMessage.hpp" #include "USSD.hpp" #include "PacketData.hpp" #include "PacketDataCellularMessage.hpp" -#include "src/CallManager.hpp" #include #include "src/URCCounter.hpp" @@ -318,7 +317,6 @@ class ServiceCellular : public sys::Service auto tetheringTurnOnURC() -> bool; auto logTetheringCalls() -> void; std::unique_ptr priv; - cellular::internal::SimpleCallManager callManager; TaskHandle_t getTaskHandle(); }; diff --git a/module-services/service-cellular/src/CallManager.cpp b/module-services/service-cellular/src/CallManager.cpp deleted file mode 100644 index e04fd3efe81981d79936e9baa96b81426a516f78..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/src/CallManager.cpp +++ /dev/null @@ -1,33 +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 "CallManager.hpp" - -namespace cellular::internal -{ - void SimpleCallManager::hangUp() noexcept - { - incomingCallPropagated = false; - callerInfoComplete = false; - } - - void SimpleCallManager::ring() noexcept - { - incomingCallPropagated = true; - } - - void SimpleCallManager::completeCallerInfo() noexcept - { - callerInfoComplete = true; - } - - auto SimpleCallManager::isIncomingCallPropagated() const noexcept -> bool - { - return incomingCallPropagated; - } - - auto SimpleCallManager::isCallerInfoComplete() const noexcept -> bool - { - return callerInfoComplete; - } -} // namespace cellular::internal diff --git a/module-services/service-cellular/src/CallManager.hpp b/module-services/service-cellular/src/CallManager.hpp deleted file mode 100644 index cf9bd781ec33991f1d311b0ba81bebf49d988613..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/src/CallManager.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -namespace cellular::internal -{ - class SimpleCallManager - { - public: - void hangUp() noexcept; - void ring() noexcept; - void completeCallerInfo() noexcept; - - [[nodiscard]] auto isIncomingCallPropagated() const noexcept -> bool; - [[nodiscard]] auto isCallerInfoComplete() const noexcept -> bool; - - private: - bool incomingCallPropagated{false}; - bool callerInfoComplete{false}; - }; -} // namespace cellular::internal