1 /* 2 * Copyright (c) 2020-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 FSM_STATE_H 17 #define FSM_STATE_H 18 19 #include <string> 20 #include "hi_fsm.h" 21 #include "hi_state.h" 22 23 namespace OHOS { 24 class FsmState : public HiState { 25 public: FsmState(HI_FSM_StateHandleEvent event,HI_FSM_StateEnter enter,HI_FSM_StateExit exit,void * priv,std::string name)26 FsmState(HI_FSM_StateHandleEvent event, HI_FSM_StateEnter enter, HI_FSM_StateExit exit, void *priv, 27 std::string name) 28 : HiState(name), m_eventHandler(event), m_stateEnter(enter), m_stateExit(exit), m_privateDate(priv) 29 { 30 } 31 ~FsmState()32 virtual ~FsmState(){} 33 HandleMessage(const MsgInfo & msg)34 int32_t HandleMessage(const MsgInfo &msg) override 35 { 36 if (m_eventHandler == nullptr) { 37 return HI_FAILURE; 38 } 39 return m_eventHandler(m_privateDate, &msg); 40 } 41 Enter()42 int32_t Enter() override 43 { 44 if (m_stateEnter == nullptr) { 45 return HI_FAILURE; 46 } 47 return m_stateEnter(m_privateDate, Name().c_str()); 48 } 49 Exit()50 int32_t Exit() override 51 { 52 if (m_stateExit == nullptr) { 53 return HI_FAILURE; 54 } 55 return m_stateExit(m_privateDate, Name().c_str()); 56 } 57 58 private: 59 HI_FSM_StateHandleEvent m_eventHandler {nullptr}; 60 HI_FSM_StateEnter m_stateEnter {nullptr}; 61 HI_FSM_StateExit m_stateExit {nullptr}; 62 void *m_privateDate {nullptr}; 63 }; 64 }; 65 #endif 66