• 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();
41     void DumpState(std::string& result);
42     void DumpIdle(std::string& result);
SetStateItem(std::vector<StateItem> & vstateItem)43     void SetStateItem(std::vector<StateItem>& vstateItem)
44     {
45         vState_ = vstateItem;
46     }
47 
GetStateCollectionMap()48     StateMachineMap GetStateCollectionMap()
49     {
50         return stateCollectionMap_;
51     }
52 
SetIdleStateConfig(const IdleState & idleState)53     void SetIdleStateConfig(const IdleState& idleState)
54     {
55         idleStateConfig_ = idleState;
56     }
57 
GetIdleStateConfig()58     IdleState& GetIdleStateConfig()
59     {
60         return idleStateConfig_;
61     }
62 
GetCommonEventReceiver()63     std::shared_ptr<ThermalCommonEventReceiver> GetCommonEventReceiver()
64     {
65         return receiver_;
66     }
67 private:
68     StateMachineMap stateCollectionMap_;
69     std::vector<StateItem> vState_;
70     std::shared_ptr<ThermalCommonEventReceiver> receiver_;
71     IdleState idleStateConfig_;
72 };
73 } // namespace PowerMgr
74 } // namespace OHOS
75 #endif // STATE_MACHINE_H