// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include #include #include namespace sys::phone_modes { enum class PhoneMode; } namespace cellular::internal::sms { class SMSSendHandler; class State; using OptionalState = std::optional>; class State { public: explicit State(const SMSSendHandler &ctx) : context(ctx) {} virtual ~State() = default; virtual OptionalState handle(std::optional record) = 0; virtual std::string toStr() const = 0; bool isNotification(std::optional record); bool isRecordEmpty(std::optional record); protected: const SMSSendHandler &context; }; class IdleState : public State { public: explicit IdleState(const SMSSendHandler &ctx) : State(ctx) {} OptionalState handle(std::optional record) override; std::string toStr() const override; }; class ProcessQueryState : public State { public: explicit ProcessQueryState(const SMSSendHandler &ctx) : State(ctx) {} OptionalState handle(std::optional record) override; std::string toStr() const override; }; class SMSSendHandler { public: SMSSendHandler(); /** * External action events */ void handleDBNotification(); void handleIncomingDbRecord(SMSRecord &record, bool onDelay); void handleNoMoreDbRecords(); void sendMessageIfDelayed(); void requestNotSendMessage(); /** * User defined callbacks/events */ /// Called when SMSSendHandler wants to send db query std::function query)> onSendQuery; /// Called upon sending SMS std::function onSend; /// Called when SMSSendHandler wants to check phone mode std::function onGetOfflineMode; /// Called when SMSSendHandler wants to check SIM state std::function onSIMNotInitialized; /// Called when SMSHandler wants to check if modem is rebooting std::function onGetModemResetInProgress; private: void handleStateChange(OptionalState state); std::unique_ptr currentState; std::function actionOnDelay; bool delayedMessage; }; } // namespace cellular::internal::sms