35730a1b4214bb274ea10b737a83ef33c98175d6
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Power / Battery.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #ifndef WRTDEVICEAPIS_POWER_BATTERY_H_
17 #define WRTDEVICEAPIS_POWER_BATTERY_H_
18
19 #include <map>
20 #include <cstddef>
21 #include <dpl/mutex.h>
22 #include <Power/IBattery.h>
23 #include <VConf/Key.h>
24
25 namespace WrtDeviceApis {
26 namespace Power {
27
28 class Battery : public Api::IBattery
29 {
30   private:
31     friend class Manager;
32
33   public:
34     ~Battery();
35
36     /**
37      * @see Api::Power::IBattery::isCharging()
38      */
39     bool isCharging() const;
40
41     /**
42      * @see Api::Power::IBattery::getRemaining()
43      */
44     unsigned int getRemaining() const;
45
46     /**
47      * @see Api::Power::IBattery::addOnCharging()
48      */
49     void addOnCharging(const Api::EventChargingEmitterPtr& emitter);
50
51     /**
52      * @see Api::Power::IBattery::removeOnCharing()
53      */
54     void removeOnCharging(Api::EventChargingEmitter::IdType id);
55
56     /**
57      * @see Api::Power::IBattery::addOnRemaining()
58      */
59     void addOnRemaining(const Api::EventRemainingEmitterPtr& emitter);
60
61     /**
62      * @see Api::Power::IBattery::removeOnRemaining()
63      */
64     void removeOnRemaining(Api::EventRemainingEmitter::IdType id);
65
66     /**
67      * @see Api::Power::IBattery::addOnLow()
68      */
69     void addOnLow(const Api::EventLowEmitterPtr& emitter);
70
71     /**
72      * @see Api::Power::IBattery::removeOnRemaining()
73      */
74     void removeOnLow(Api::EventLowEmitter::IdType id);
75
76   private:
77     typedef std::map<Api::EventChargingEmitter::IdType,
78                      Api::EventChargingEmitterPtr> ChargingEventEmitters;
79
80     typedef std::map<Api::EventRemainingEmitter::IdType,
81                      Api::EventRemainingEmitterPtr>
82     RemainingEventEmitters;
83
84     typedef std::map<Api::EventLowEmitter::IdType,
85                      Api::EventLowEmitterPtr> LowEventEmitters;
86   private:
87     explicit Battery(std::size_t index);
88
89     /**
90      * Callback method called by platform when battery charging state changes.
91      * @param key Vconf key object.
92      * @param data User data.
93      */
94     static void onCharging(const VConf::Node* node,
95             void* data);
96
97     /**
98      * Callback method called by platform when battery power level changes.
99      * @param key Vconf key object.
100      * @param data User data.
101      */
102     static void onRemaining(const VConf::Node* key,
103             void* data);
104
105     /**
106      * Callback method called by platform when battery power level gets low.
107      * @param key Vconf key object.
108      * @param data User data.
109      */
110     static void onLow(const VConf::Node* key,
111             void* data);
112
113   private:
114     std::size_t m_index; ///< Index of battery this interface represents.
115     VConf::Key m_onChargingKey; ///< Wrapper for vconf on battery charging key.
116     VConf::Key m_onRemainingKey; ///< Wrapper for vconf on battery level key.
117     VConf::Key m_onLowKey; ///< Wrapper for vconf on battery low level state key.
118     ChargingEventEmitters m_onCharging; ///< Charging event emitters.
119     RemainingEventEmitters m_onRemaining; ///< Remaining event emitters.
120     LowEventEmitters m_onLow; ///< Low level event emitters.
121     DPL::Mutex m_onChargingMtx; ///< Mutex synchronizing operations on m_onCharging object.
122     DPL::Mutex m_onRemainingMtx; ///< Mutex synchronizing operations on m_onRemaining object.
123     DPL::Mutex m_onLowMtx; ///< Mutex synchronizing operations on m_onLow object.
124 };
125
126 } // Power
127 } // WrtDeviceApis
128
129 #endif /* WRTDEVICEAPIS_POWER_BATTERY_H_ */