M module-services/service-cellular/call/CellularCall.cpp => module-services/service-cellular/call/CellularCall.cpp +1 -1
@@ 28,7 28,7 @@ namespace call
std::make_unique<CallDB>(owner),
std::make_unique<CallTimer>(std::move(timer)),
std::make_unique<TimerRing>(std::move(timerRing)),
- std::make_unique<cellular::Api>(owner, cmux),
+ std::make_unique<cellular::Api>(owner),
std::move(sentinel)});
}
M module-services/service-cellular/call/api/ModemCallApi.cpp => module-services/service-cellular/call/api/ModemCallApi.cpp +25 -33
@@ 3,58 3,50 @@
#include "ModemCallApi.hpp"
#include <modem/mux/CellularMux.h>
+#include <module-cellular/at/Commands.hpp>
#include <stdexcept>
#include <service-cellular/ServiceCellular.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
namespace cellular
{
- Api::Api(ServiceCellular *cellular, CellularMux *cmux) : cellular(cellular), cmux(cmux)
+ Api::Api(ServiceCellular *cellular) : cellular{cellular}
{}
- bool Api::answerIncomingCall()
+ bool Api::handleEvent(at::AT modemCommand)
{
- if (cmux == nullptr) {
- throw std::runtime_error("call api not initialized");
+ if (!cellular->cmux) {
+ LOG_INFO("no cmux at this time - ignoring request");
+ return false;
+ }
+
+ auto channel = cellular->cmux->get(CellularMux::Channel::Commands);
+ if (!channel) {
+ LOG_INFO("no cmux command channel at this time - ignoring request");
+ return false;
}
- auto channel = cmux->get(CellularMux::Channel::Commands);
- if (channel != nullptr) {
- auto response = channel->cmd(at::AT::ATA);
- if (response) {
- return true;
- }
+
+ if (!channel->cmd(modemCommand)) {
+ LOG_WARN("AT+%s command failed - ignoring request", magic_enum::enum_name(modemCommand).data());
+ return false;
}
- return false;
+
+ return true;
+ }
+
+ bool Api::answerIncomingCall()
+ {
+ return handleEvent(at::AT::ATA);
}
bool Api::hangupCall()
{
- if (cmux == nullptr) {
- return false;
- }
- auto channel = cmux->get(CellularMux::Channel::Commands);
- if (channel != nullptr) {
- auto response = channel->cmd(at::AT::ATH);
- if (response) {
- return true;
- }
- }
- return false;
+ return handleEvent(at::AT::ATH);
}
bool Api::rejectCall()
{
- if (cmux == nullptr) {
- return false;
- }
- auto channel = cmux->get(CellularMux::Channel::Commands);
- if (channel != nullptr) {
- auto response = channel->cmd(at::AT::CHUP);
- if (response) {
- return true;
- }
- }
- return false;
+ return handleEvent(at::AT::CHUP);
}
bool Api::areCallsFromFavouritesEnabled()
M module-services/service-cellular/call/api/ModemCallApi.hpp => module-services/service-cellular/call/api/ModemCallApi.hpp +8 -2
@@ 6,6 6,11 @@
#include "PhoneModes/PhoneMode.hpp"
#include "PhoneModes/Tethering.hpp"
+namespace at
+{
+ enum class AT;
+}
+
class CellularMux;
class ServiceCellular;
@@ 30,11 35,12 @@ namespace cellular
{
private:
ServiceCellular *cellular = nullptr;
- CellularMux *cmux = nullptr;
+
+ bool handleEvent(at::AT modemCommand);
public:
Api() = default;
- Api(ServiceCellular *cellular, CellularMux *);
+ Api(ServiceCellular *cellular);
bool answerIncomingCall() override;
bool hangupCall() override;