• 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 #ifndef OHOS_AP_STATE_MACHINE_H
16 #define OHOS_AP_STATE_MACHINE_H
17 
18 #include "state_machine.h"
19 #include <vector>
20 #include <shared_mutex>
21 #include "dhcpd_interface.h"
22 #include "i_ap_service.h"
23 #include "ap_root_state.h"
24 #include "ap_idle_state.h"
25 #include "ap_started_state.h"
26 
27 namespace OHOS {
28 namespace Wifi {
29 class ApConfigUse;
30 class ApStationsManager;
31 class ApMonitor;
32 class ApStateMachine : public StateMachine {
33     friend class ApRootState;
34     friend class ApIdleState;
35     friend class ApStartedState;
36     FRIEND_GTEST(ApStateMachine);
37 
38 public:
39     /**
40      * @Description  construction method.
41      * @param None
42      * @return None
43      */
44     ApStateMachine(ApStationsManager &apStationsManager, ApRootState &apRootState, ApIdleState &apIdleState,
45         ApStartedState &apStartedState, ApMonitor &apMonitor, int id = 0);
46 
47     /**
48      * @Description  destructor method.
49      * @param None
50      * @return None
51      */
52     virtual ~ApStateMachine();
53 
54     /**
55      * @Description  Reporting New State.
56      * @param state - the state.
57      * @return None
58      */
59     void OnApStateChange(ApState state);
60 
61     /**
62      * @Description  Reporting station change msg.
63      * @param staInfo - station information
64      * @param act - action event
65      * @return None
66      */
67     void BroadCastStationChange(const StationInfo &staInfo, ApStatemachineEvent act);
68 
69     /**
70      * @Description  Register callback list to reporting msg.
71      * @param callbacks - callback list
72      * @return None
73      */
74     ErrCode RegisterApServiceCallbacks(const IApServiceCallbacks &callbacks);
75 
76     /**
77      * @Description  Apmonitor Initialization Function.
78      * @param None
79      * @return None
80      */
81     void Init();
82 
83     /**
84      * @Description  Disable dhcp server.
85      * @param None
86      * @return true - success
87      * @return false - fail
88      */
89     bool StopDhcpServer();
90 
91     /**
92      * @Description  Enable dhcp server.
93      * @param ipAddress - HotspotConfig dhcp server address
94      * @param leaseTime - HotspotConfig dhcp lease time
95      * @return true - success
96      * @return false - fail
97      */
98     bool StartDhcpServer(const std::string &ipAddress, const int32_t &leaseTime);
99 
100     /**
101      * @Description  Get the Station List object.
102      * @param result - Current connected station info
103      * @return true - success
104      * @return false - fail
105      */
106     bool GetConnectedStationInfo(std::map<std::string, StationInfo> &result);
107 
108 private:
109     DISALLOW_COPY_AND_ASSIGN(ApStateMachine);
110 
111     /**
112      * @Description  Register event handler to apmonitor.
113      * @param None
114      * @return None
115      */
116     virtual void RegisterEventHandler();
117 
118 private:
119     std::string m_iface;
120     std::shared_mutex m_callbackMutex;
121     std::map<std::string, IApServiceCallbacks> m_callbacks;
122     /* STA Manager */
123     ApStationsManager &m_ApStationsManager;
124     /* The reference of RootState */
125     ApRootState &m_ApRootState;
126     /* The reference of IdleState */
127     ApIdleState &m_ApIdleState;
128     /* The reference of StartedState */
129     ApStartedState &m_ApStartedState;
130     ApMonitor &m_ApMonitor;
131 
132     DhcpdInterface m_DhcpdInterface;
133     int m_id;
134 }; /* ApStateMachine */
135 }  // namespace Wifi
136 }  // namespace OHOS
137 
138 #endif