• 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 STATE_MACHINE_H
17 #define STATE_MACHINE_H
18 
19 #include <string>
20 #include <vector>
21 #include <memory>
22 #include <map>
23 
24 #include "charger_state_collection.h"
25 #include "constants.h"
26 #include "istate_collection.h"
27 #include "thermal_common_event_receiver.h"
28 
29 namespace OHOS {
30 namespace PowerMgr {
31 struct StateItem {
32     std::string name;
33     std::string params;
34     bool isExistParam = false;
35 };
36 
37 class StateMachine {
38 public:
39     using StateMachineMap = std::map<std::string, std::shared_ptr<IStateCollection>>;
40     bool Init();
SetStateItem(std::vector<StateItem> & vstateItem)41     void SetStateItem(std::vector<StateItem>& vstateItem)
42     {
43         vState_ = vstateItem;
44     }
45 
GetStateCollectionMap()46     StateMachineMap GetStateCollectionMap()
47     {
48         return stateCollectionMap_;
49     }
50 
SetIdleStateConfig(const IdleState & idleState)51     void SetIdleStateConfig(const IdleState& idleState)
52     {
53         idleStateConfig_ = idleState;
54     }
55 
GetIdleStateConfig()56     IdleState& GetIdleStateConfig()
57     {
58         return idleStateConfig_;
59     }
60 
GetCommonEventReceiver()61     std::shared_ptr<ThermalCommonEventReceiver> GetCommonEventReceiver()
62     {
63         return receiver_;
64     }
65 private:
66     StateMachineMap stateCollectionMap_;
67     std::vector<StateItem> vState_;
68     std::shared_ptr<ThermalCommonEventReceiver> receiver_;
69     IdleState idleStateConfig_;
70 };
71 } // namespace PowerMgr
72 } // namespace OHOS
73 #endif // STATE_MACHINE_H