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 ACTIVE_H
17 #define ACTIVE_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "cellular_data_event_code.h"
23 #include "cellular_data_state_machine.h"
24 #include "inner_event.h"
25 #include "radio_event.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class Active : public State {
30 public:
Active(std::weak_ptr<CellularDataStateMachine> && cellularService,std::string && name)31     Active(std::weak_ptr<CellularDataStateMachine> &&cellularService, std::string &&name)
32         : State(std::move(name)), stateMachine_(std::move(cellularService))
33     {}
34     virtual ~Active() = default;
35     virtual void StateBegin();
36     virtual void StateEnd();
37     virtual bool StateProcess(const AppExecFwk::InnerEvent::Pointer &event);
38 
39 private:
40     bool ProcessConnectDone(const AppExecFwk::InnerEvent::Pointer &event);
41     bool ProcessDisconnectDone(const AppExecFwk::InnerEvent::Pointer &event);
42     bool ProcessDisconnectAllDone(const AppExecFwk::InnerEvent::Pointer &event);
43     bool ProcessLostConnection(const AppExecFwk::InnerEvent::Pointer &event);
44     bool ProcessRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer &event);
45     bool ProcessLinkCapabilityChanged(const AppExecFwk::InnerEvent::Pointer &event);
46     bool ProcessDataConnectionRoamOn(const AppExecFwk::InnerEvent::Pointer &event);
47     bool ProcessDataConnectionRoamOff(const AppExecFwk::InnerEvent::Pointer &event);
48     bool ProcessDataConnectionVoiceCallStartedOrEnded(const AppExecFwk::InnerEvent::Pointer &event);
49     bool ProcessNrStateChanged(const AppExecFwk::InnerEvent::Pointer &event);
50     bool ProcessNrFrequencyChanged(const AppExecFwk::InnerEvent::Pointer &event);
51     bool ProcessDataConnectionComplete(const AppExecFwk::InnerEvent::Pointer &event);
52     void RefreshConnectionBandwidths();
53     void RefreshTcpBufferSizes();
54 
55 private:
56     using Fun = std::function<bool(const AppExecFwk::InnerEvent::Pointer &data)>;
57     std::map<uint32_t, Fun> eventIdFunMap_ {
58         { CellularDataEventCode::MSG_SM_CONNECT,
59             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessConnectDone(data); } },
60         { CellularDataEventCode::MSG_SM_DISCONNECT,
61             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDisconnectDone(data); } },
62         { CellularDataEventCode::MSG_SM_DISCONNECT_ALL,
63             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDisconnectAllDone(data); } },
64         { CellularDataEventCode::MSG_SM_LOST_CONNECTION,
65             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessLostConnection(data); } },
66         { CellularDataEventCode::MSG_SM_LINK_CAPABILITY_CHANGED,
67             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessLinkCapabilityChanged(data); } },
68         { CellularDataEventCode::MSG_SM_DATA_ROAM_ON,
69             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDataConnectionRoamOn(data); } },
70         { CellularDataEventCode::MSG_SM_DATA_ROAM_OFF,
71             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDataConnectionRoamOff(data); } },
72         { CellularDataEventCode::MSG_SM_VOICE_CALL_STARTED,
73             [this](const AppExecFwk::InnerEvent::Pointer &data) {
74                 return ProcessDataConnectionVoiceCallStartedOrEnded(data);
75             } },
76         { CellularDataEventCode::MSG_SM_VOICE_CALL_ENDED,
77             [this](const AppExecFwk::InnerEvent::Pointer &data) {
78                 return ProcessDataConnectionVoiceCallStartedOrEnded(data);
79             } },
80         { CellularDataEventCode::MSG_SM_RIL_ADAPTER_HOST_DIED,
81             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessRilAdapterHostDied(data); } },
82         { RadioEvent::RADIO_NR_STATE_CHANGED,
83             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessNrStateChanged(data); } },
84         { RadioEvent::RADIO_NR_FREQUENCY_CHANGED,
85             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessNrFrequencyChanged(data); } },
86         { RadioEvent::RADIO_RIL_SETUP_DATA_CALL,
87             [this](const AppExecFwk::InnerEvent::Pointer &data) { return ProcessDataConnectionComplete(data); } },
88     };
89     std::weak_ptr<CellularDataStateMachine> stateMachine_;
90 };
91 } // namespace Telephony
92 } // namespace OHOS
93 #endif // ACTIVE_H
94