1 /* 2 * Copyright (C) 2021-2024 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 MULTI_STA_STATE_MACHINE_H 17 #define MULTI_STA_STATE_MACHINE_H 18 19 #include "state.h" 20 #include "state_machine.h" 21 #include "wifi_logger.h" 22 #include "wifi_errcode.h" 23 #include <string> 24 #include "wifi_ap_msg.h" 25 #include "wifi_internal_msg.h" 26 #include "wifi_controller_define.h" 27 28 namespace OHOS { 29 namespace Wifi { 30 class MultiStaStateMachine : public StateMachine { 31 public: 32 MultiStaStateMachine(); 33 ~MultiStaStateMachine(); 34 35 class IdleState : public State { 36 public: 37 explicit IdleState(MultiStaStateMachine *multiStaStateMachine); 38 ~IdleState() override; 39 void GoInState() override; 40 void GoOutState() override; 41 bool ExecuteStateMsg(InternalMessagePtr msg) override; 42 43 private: 44 MultiStaStateMachine *pMultiStaStateMachine = nullptr; 45 void HandleStartInIdleState(InternalMessagePtr msg); 46 }; 47 48 class DefaultState : public State { 49 public: 50 explicit DefaultState(MultiStaStateMachine *multiStaStateMachine); 51 ~DefaultState() override; 52 void GoInState() override; 53 void GoOutState() override; 54 bool ExecuteStateMsg(InternalMessagePtr msg) override; 55 56 private: 57 MultiStaStateMachine *pMultiStaStateMachine = nullptr; 58 }; 59 60 class StartedState : public State { 61 public: 62 explicit StartedState(MultiStaStateMachine *multiStaStateMachine); 63 ~StartedState() override; 64 void GoInState() override; 65 void GoOutState() override; 66 bool ExecuteStateMsg(InternalMessagePtr msg) override; 67 68 private: 69 MultiStaStateMachine *pMultiStaStateMachine = nullptr; 70 }; 71 72 public: 73 ErrCode InitMultiStaStateMachine(); 74 ErrCode RegisterCallback(const MultiStaModeCallback &callbacks); 75 76 private: 77 template <typename T> ParsePointer(T * & pointer)78 inline void ParsePointer(T *&pointer) 79 { 80 if (pointer != nullptr) { 81 delete pointer; 82 pointer = nullptr; 83 } 84 } 85 86 template <typename T> JudgmentEmpty(T * & pointer)87 inline ErrCode JudgmentEmpty(T *&pointer) 88 { 89 if (pointer == nullptr) { 90 return WIFI_OPT_FAILED; 91 } 92 return WIFI_OPT_SUCCESS; 93 } 94 95 void BuildStateTree(); 96 ErrCode InitMultiStaStates(); 97 DefaultState *pDefaultState; 98 IdleState *pIdleState; 99 StartedState *pStartedState; 100 MultiStaModeCallback mcb; 101 static int mid; 102 std::string ifaceName{""}; 103 }; 104 } // namespace Wifi 105 } // namespace OHOS 106 #endif