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_OBERVER_H
17 #define FSM_OBERVER_H
18 #include <list>
19 #include <string>
20 #include "hi_fsm.h"
21 #include "hi_state_machine.h"
22 
23 using OHOS::HiStateMachineObserver;
24 using OHOS::HiStateMachine;
25 using OHOS::FsmState;
26 
27 namespace OHOS {
28 class FsmOberver : public HiStateMachineObserver {
29 public:
FsmOberver(HI_FSM_EventCallback msgCallback,void * priv)30     FsmOberver(HI_FSM_EventCallback msgCallback, void *priv)
31         : m_eventCallback(msgCallback), m_privateDate(priv)
32     {
33     }
34 
~FsmOberver()35     ~FsmOberver()
36     {
37     }
38 
OnEventHandled(const HiStateMachine & stateMachine,int32_t event,int32_t result)39     void OnEventHandled(const HiStateMachine &stateMachine, int32_t event, int32_t result) override
40     {
41         HiStateMachine *instance = const_cast<HiStateMachine *>(&stateMachine);
42         if (m_eventCallback != nullptr) {
43             m_eventCallback(instance, m_privateDate, event, result);
44         }
45     }
46 
47 private:
48     HI_FSM_EventCallback m_eventCallback;
49     void *m_privateDate;
50 };
51 }
52 #endif
53