/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CELLULAR_DATA_STATE_MACHINE_H #define CELLULAR_DATA_STATE_MACHINE_H #include #include #include "event_handler.h" #include "inner_event.h" #include "network_state.h" #include "apn_item.h" #include "cellular_data_net_agent.h" #include "data_connection_manager.h" #include "data_connection_params.h" #include "data_disconnect_params.h" #include "state_machine.h" namespace OHOS { namespace Telephony { class DataConnectionManager; class CellularDataStateMachine : public StateMachine, public std::enable_shared_from_this { public: CellularDataStateMachine(sptr &cdConnectionManager, std::shared_ptr &&cellularDataHandler, const std::shared_ptr &runner) : StateMachine(runner), cdConnectionManager_(cdConnectionManager), cellularDataHandler_(std::move(cellularDataHandler)), cid_(0), capability_(0), rilRat_(RadioTech::RADIO_TECHNOLOGY_UNKNOWN), apnId_(0) {} ~CellularDataStateMachine() = default; bool operator==(const CellularDataStateMachine &stateMachine) const; bool IsInactiveState() const; sptr GetCurrentState() const; void SetCapability(uint64_t capability); uint64_t GetCapability() const; int32_t GetCid() const; int32_t GetSlotId() const; sptr GetApnItem() const; void Init(); void UpdateNetworkInfo(const SetupDataCallResultInfo &dataCallInfo); void UpdateNetworkInfo(); void SetConnectionBandwidth(const uint32_t upBandwidth, const uint32_t downBandwidth); void SetConnectionTcpBuffer(const std::string &tcpBuffer); protected: sptr activeState_; sptr inActiveState_; sptr activatingState_; sptr disconnectingState_; sptr defaultState_; sptr currentState_; sptr cdConnectionManager_; std::shared_ptr cellularDataHandler_; sptr netLinkInfo_; sptr netSupplierInfo_; private: void SetCurrentState(const sptr &&state); void SetCid(const int32_t cid); void DoConnect(const DataConnectionParams &connectionParams); void FreeConnection(const DataDisconnectParams ¶ms); void ResolveIp(std::vector &ipInfoArray); void ResolveDns(std::vector &dnsInfoArray); void ResolveRoute(std::vector &routeInfoArray, const std::string &name); private: friend class Active; friend class Activating; friend class Inactive; friend class Default; friend class Disconnecting; int32_t cid_; uint64_t capability_; RadioTech rilRat_; sptr apnItem_; int32_t apnId_; std::mutex mtx_; uint32_t upBandwidth_ = 0; uint32_t downBandwidth_ = 0; std::string tcpBuffer_; int32_t connectId_ = 0; }; } // namespace Telephony } // namespace OHOS #endif // CELLULAR_DATA_STATE_MACHINE_H