• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CPP_POWERPOLICY_SERVER_SRC_POWERCOMPONENTHANDLER_H_
18 #define CPP_POWERPOLICY_SERVER_SRC_POWERCOMPONENTHANDLER_H_
19 
20 #include <android-base/result.h>
21 #include <android/frameworks/automotive/powerpolicy/CarPowerPolicy.h>
22 #include <utils/Mutex.h>
23 
24 #include <memory>
25 #include <unordered_map>
26 
27 namespace android {
28 namespace frameworks {
29 namespace automotive {
30 namespace powerpolicy {
31 
32 using CarPowerPolicyPtr = std::shared_ptr<CarPowerPolicy>;
33 
34 class PowerComponentHandler final {
35 public:
PowerComponentHandler()36     PowerComponentHandler() {}
37 
38     // Sets the initial state of all power components.
39     void init();
40     // Applies the given power policy and updates the latest state of all power components.
41     void applyPowerPolicy(const CarPowerPolicyPtr& powerPolicy);
42     // Gets the current state of the given power component.
43     android::base::Result<bool> getPowerComponentState(const PowerComponent componentId) const;
44     // Gets the accumulated state of all components after applying power policies.
45     CarPowerPolicyPtr getAccumulatedPolicy() const;
46     // Dumps the internal status.
47     android::base::Result<void> dump(int fd);
48 
49 private:
50     mutable android::Mutex mMutex;
51     CarPowerPolicyPtr mAccumulatedPolicy GUARDED_BY(mMutex);
52 };
53 
54 }  // namespace powerpolicy
55 }  // namespace automotive
56 }  // namespace frameworks
57 }  // namespace android
58 
59 #endif  // CPP_POWERPOLICY_SERVER_SRC_POWERCOMPONENTHANDLER_H_
60