• 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 POWER_STATE_MACHINE_H
17 #define POWER_STATE_MACHINE_H
18 
19 #include "power_device.h"
20 #include "state_machine.h"
21 
22 namespace bluetooth {
23 const std::string ACTIVE_STATE = "Active";
24 const std::string SNIFF_STATE = "Sniff";
25 const std::string ACTIV_ACTIVING_STATE = "A_Activing";
26 const std::string ACTIV_SNIFFING_STATE = "A_Sniffing";
27 const std::string SNIFF_SNIFFING_STATE = "S_Sniffing";
28 const std::string SNIFF_ACTIVING_STATE = "S_Activing";
29 
30 /**
31  * @brief Represents power state machine.
32  *
33  * @since 6
34  */
35 class PowerStateMachine : public utility::StateMachine {
36 public:
37     enum PowerStateMessage {
38         MSG_PM_SET_SNIFF,
39         MSG_PM_SET_ACTIVE,
40         MSG_PM_MODE_CHANGE_ACTIVE,
41         MSG_PM_MODE_CHANGE_SNIFF,
42         MSG_PM_SET_SUBRATING_COMPLETE
43     };
44     /**
45      * @brief A constructor used to create an <b>PowerStateMachine</b> instance.
46      *
47      * @since 6
48      */
PowerStateMachine()49     PowerStateMachine(){};
50 
51     /**
52      * @brief A destructor used to delete the <b>PowerStateMachine</b> instance.
53      *
54      * @since 6
55      */
56     ~PowerStateMachine() = default;
57 
58     /**
59      * @brief A constructor used to create an <b>PowerStateMachine</b> instance.
60      *
61      * @param pd power device.
62      * @since 6
63      */
64     void Init(PowerDevice &pd);
65 };
66 
67 class PowerState : public utility::StateMachine::State {
68 public:
69     /**
70      * @brief A constructor used to create an <b>PowerState</b> instance.
71      *
72      * @param pm power manager.
73      * @since 6
74      */
PowerState(const std::string & name,PowerStateMachine & psm,PowerDevice & pd)75     PowerState(const std::string &name, PowerStateMachine &psm, PowerDevice &pd) : State(name, psm), pd_(pd){};
76 
77     /**
78      * @brief A constructor used to create an <b>PowerState</b> instance.
79      *
80      * @param pm power manager.
81      * @since 6
82      */
PowerState(const std::string & name,PowerStateMachine & psm,PowerDevice & pd,utility::StateMachine::State & fstate)83     PowerState(const std::string &name, PowerStateMachine &psm, PowerDevice &pd, utility::StateMachine::State &fstate)
84         : State(name, psm, fstate), pd_(pd){};
85 
86     /**
87      * @brief A destructor used to create an <b>PowerState</b> instance.
88      *
89      * @since 6
90      */
91     ~PowerState() = default;
92 
93 protected:
94     PowerDevice &pd_;
95 };
96 
97 class PowerActiveState : public PowerState {
98 public:
99     /**
100      * @brief A constructor used to create an <b>PowerActiveState</b> instance.
101      *
102      * @param psm StateMachine.
103      * @param pd Power Device.
104      * @since 6
105      */
PowerActiveState(PowerStateMachine & psm,PowerDevice & pd)106     PowerActiveState(PowerStateMachine &psm, PowerDevice &pd) : PowerState(ACTIVE_STATE, psm, pd){};
107 
108     /**
109      * @brief A destructor used to create an <b>PowerActiveState</b> instance.
110      *
111      * @since 6
112      */
113     ~PowerActiveState() = default;
114 
115     /**
116      * @brief Operation should be executed when Entry the state.
117      *
118      * @since 6
119      */
120     virtual void Entry();
121 
122     /**
123      * @brief Operation should be executed when Exit the state.
124      *
125      * @since 6
126      */
127     virtual void Exit();
128 
129     /**
130      * @brief State dispatch message.
131      *
132      * @param msg Message.
133      * @since 6
134      */
135     virtual bool Dispatch(const utility::Message &msg);
136 };
137 
138 class PowerActiveActivingState : public PowerState {
139 public:
140     /**
141      * @brief A constructor used to create an <b>PowerActiveActivingState</b> instance.
142      *
143      * @param psm StateMachine.
144      * @param pd Power Device.
145      * @param fstate Father State.
146      * @since 6
147      */
PowerActiveActivingState(PowerStateMachine & psm,PowerDevice & pd,utility::StateMachine::State & fstate)148     PowerActiveActivingState(PowerStateMachine &psm, PowerDevice &pd, utility::StateMachine::State &fstate)
149         : PowerState(ACTIV_ACTIVING_STATE, psm, pd, fstate){};
150 
151     /**
152      * @brief A destructor used to create an <b>PowerActiveActivingState</b> instance.
153      *
154      * @since 6
155      */
156     ~PowerActiveActivingState() = default;
157     virtual void Entry();
158     virtual void Exit();
159     virtual bool Dispatch(const utility::Message &msg);
160 };
161 
162 class PowerActiveSniffingState : public PowerState {
163 public:
164     /**
165      * @brief A constructor used to create an <b>PowerActiveSniffingState</b> instance.
166      *
167      * @param psm StateMachine.
168      * @param pd Power Device.
169      * @param fstate Father State.
170      * @since 6
171      */
PowerActiveSniffingState(PowerStateMachine & psm,PowerDevice & pd,utility::StateMachine::State & fstate)172     PowerActiveSniffingState(PowerStateMachine &psm, PowerDevice &pd, utility::StateMachine::State &fstate)
173         : PowerState(ACTIV_SNIFFING_STATE, psm, pd, fstate){};
174 
175     /**
176      * @brief A destructor used to create an <b>PowerActiveSniffingState</b> instance.
177      *
178      * @since 6
179      */
180     ~PowerActiveSniffingState() = default;
181     virtual void Entry();
182     virtual void Exit();
183     virtual bool Dispatch(const utility::Message &msg);
184 };
185 
186 class PowerSniffState : public PowerState {
187 public:
188     /**
189      * @brief A constructor used to create an <b>PowerSniffState</b> instance.
190      *
191      * @param psm StateMachine.
192      * @param pd Power Device.
193      * @since 6
194      */
PowerSniffState(PowerStateMachine & psm,PowerDevice & pd)195     PowerSniffState(PowerStateMachine &psm, PowerDevice &pd) : PowerState(SNIFF_STATE, psm, pd){};
196 
197     /**
198      * @brief A destructor used to create an <b>PowerSniffState</b> instance.
199      *
200      * @since 6
201      */
202     ~PowerSniffState() = default;
203     virtual void Entry();
204     virtual void Exit();
205     virtual bool Dispatch(const utility::Message &msg);
206 };
207 
208 class PowerSniffActivingState : public PowerState {
209 public:
210     /**
211      * @brief A constructor used to create an <b>PowerSniffActivingState</b> instance.
212      *
213      * @param psm StateMachine.
214      * @param pd Power Device.
215      * @param fstate Father State.
216      * @since 6
217      */
PowerSniffActivingState(PowerStateMachine & psm,PowerDevice & pd,utility::StateMachine::State & fstate)218     PowerSniffActivingState(PowerStateMachine &psm, PowerDevice &pd, utility::StateMachine::State &fstate)
219         : PowerState(SNIFF_ACTIVING_STATE, psm, pd, fstate){};
220 
221     /**
222      * @brief A destructor used to create an <b>PowerSniffActivingState</b> instance.
223      *
224      * @since 6
225      */
226     ~PowerSniffActivingState() = default;
227     virtual void Entry();
228     virtual void Exit();
229     virtual bool Dispatch(const utility::Message &msg);
230 };
231 
232 class PowerSniffSniffingState : public PowerState {
233 public:
234     /**
235      * @brief A constructor used to create an <b>PowerSniffSniffingState</b> instance.
236      *
237      * @param psm StateMachine.
238      * @param pd Power Device.
239      * @param fstate Father State.
240      * @since 6
241      */
PowerSniffSniffingState(PowerStateMachine & psm,PowerDevice & pd,utility::StateMachine::State & fstate)242     PowerSniffSniffingState(PowerStateMachine &psm, PowerDevice &pd, utility::StateMachine::State &fstate)
243         : PowerState(SNIFF_SNIFFING_STATE, psm, pd, fstate){};
244 
245     /**
246      * @brief A destructor used to create an <b>PowerSniffSniffingState</b> instance.
247      *
248      * @since 6
249      */
250     ~PowerSniffSniffingState() = default;
251     virtual void Entry();
252     virtual void Exit();
253     virtual bool Dispatch(const utility::Message &msg);
254 };
255 }  // namespace bluetooth
256 
257 #endif  // ADAPTER_STATE_MACHINE_H