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