• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CELLULAR_DATA_STATE_MACHINE_H
17 #define CELLULAR_DATA_STATE_MACHINE_H
18 
19 #include <memory>
20 #include <map>
21 
22 #include "event_handler.h"
23 #include "inner_event.h"
24 
25 #include "network_state.h"
26 
27 #include "apn_item.h"
28 #include "cellular_data_net_agent.h"
29 #include "data_connection_manager.h"
30 #include "data_connection_params.h"
31 #include "data_disconnect_params.h"
32 #include "state_machine.h"
33 
34 namespace OHOS {
35 namespace Telephony {
36 class DataConnectionManager;
37 class CellularDataStateMachine : public StateMachine,
38     public std::enable_shared_from_this<CellularDataStateMachine> {
39 public:
CellularDataStateMachine(sptr<DataConnectionManager> & cdConnectionManager,std::shared_ptr<AppExecFwk::EventHandler> && cellularDataHandler,const std::shared_ptr<AppExecFwk::EventRunner> & runner)40     CellularDataStateMachine(sptr<DataConnectionManager> &cdConnectionManager,
41         std::shared_ptr<AppExecFwk::EventHandler> &&cellularDataHandler,
42         const std::shared_ptr<AppExecFwk::EventRunner> &runner)
43         : StateMachine(runner), cdConnectionManager_(cdConnectionManager),
44         cellularDataHandler_(std::move(cellularDataHandler)), cid_(0), capability_(0),
45         rilRat_(RadioTech::RADIO_TECHNOLOGY_UNKNOWN), apnId_(0)
46     {}
47     ~CellularDataStateMachine() = default;
48     bool operator==(const CellularDataStateMachine &stateMachine) const;
49     bool IsInactiveState() const;
50     sptr<State> GetCurrentState() const;
51     void SetCapability(uint64_t capability);
52     uint64_t GetCapability() const;
53     int32_t GetCid() const;
54     int32_t GetSlotId() const;
55     sptr<ApnItem> GetApnItem() const;
56     void Init();
57     void UpdateNetworkInfo(const SetupDataCallResultInfo &dataCallInfo);
58     void UpdateNetworkInfo();
59     void SetConnectionBandwidth(const uint32_t upBandwidth, const uint32_t downBandwidth);
60     void SetConnectionTcpBuffer(const std::string &tcpBuffer);
61 
62 protected:
63     sptr<State> activeState_;
64     sptr<State> inActiveState_;
65     sptr<State> activatingState_;
66     sptr<State> disconnectingState_;
67     sptr<State> defaultState_;
68     sptr<State> currentState_;
69     sptr<DataConnectionManager> cdConnectionManager_;
70     std::shared_ptr<AppExecFwk::EventHandler> cellularDataHandler_;
71     sptr<NetManagerStandard::NetLinkInfo> netLinkInfo_;
72     sptr<NetManagerStandard::NetSupplierInfo> netSupplierInfo_;
73 
74 private:
75     void SetCurrentState(const sptr<State> &&state);
76     void SetCid(const int32_t cid);
77     void DoConnect(const DataConnectionParams &connectionParams);
78     void FreeConnection(const DataDisconnectParams &params);
79     void ResolveIp(std::vector<AddressInfo> &ipInfoArray);
80     void ResolveDns(std::vector<AddressInfo> &dnsInfoArray);
81     void ResolveRoute(std::vector<AddressInfo> &routeInfoArray, const std::string &name);
82 
83 private:
84     friend class Active;
85     friend class Activating;
86     friend class Inactive;
87     friend class Default;
88     friend class Disconnecting;
89     int32_t cid_;
90     uint64_t capability_;
91     RadioTech rilRat_;
92     sptr<ApnItem> apnItem_;
93     int32_t apnId_;
94     std::mutex mtx_;
95     uint32_t upBandwidth_ = 0;
96     uint32_t downBandwidth_ = 0;
97     std::string tcpBuffer_;
98     int32_t connectId_ = 0;
99 };
100 } // namespace Telephony
101 } // namespace OHOS
102 #endif // CELLULAR_DATA_STATE_MACHINE_H