92d1f2515e0fcdd9aca0b8feeebf2db98fb27930
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Power / Manager.cpp
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 #include "Manager.h"
17 #include <algorithm>
18 #include <Commons/Exception.h>
19
20 namespace {
21 const std::size_t NUMBER_OF_AVAILABLE_BATTERIES = 1;
22 const std::size_t NUMBER_OF_AVAILABLE_BACKLIGHT = 1;
23 }
24
25 namespace WrtDeviceApis {
26 namespace Power {
27
28 Manager& Manager::getInstance()
29 {
30     static Manager instance;
31     return instance;
32 }
33
34 Manager::Manager()
35 {
36     //m_backlight = new Backlight();
37 }
38
39 Manager::~Manager()
40 {
41 }
42
43 void Manager::Release()
44 {
45     LogDebug("entered");
46     Batteries::iterator it = m_batteries.begin();
47     for (; it != m_batteries.end(); ++it) {
48         //delete it->second;
49     }
50     if (m_batteries.size() > 0) {
51         m_batteries.clear();
52     }
53
54     if (NULL != m_backlight) {
55         //delete m_backlight;
56         //m_backlight = NULL;
57     }
58 }
59
60 Battery* Manager::getBattery(std::size_t index) const
61 {
62     if (index > NUMBER_OF_AVAILABLE_BATTERIES) {
63         ThrowMsg(Commons::OutOfRangeException, "Battery not available.");
64     }
65
66     Batteries::iterator it = m_batteries.find(index);
67     if (it == m_batteries.end()) {
68         Battery* battery = new Battery(index);
69         m_batteries.insert(Batteries::value_type(index, battery));
70         return battery;
71     }
72     return it->second;
73 }
74
75 std::size_t Manager::getBatteriesCount() const
76 {
77     return NUMBER_OF_AVAILABLE_BATTERIES;
78 }
79
80 Api::IBacklightPtr Manager::getBacklight(void)
81 {
82     if (NULL == m_backlight) {
83         m_backlight = Api::IBacklightPtr(new Backlight());
84     }
85     return m_backlight;
86 }
87
88 std::size_t Manager::getBacklightCount() const
89 {
90     return NUMBER_OF_AVAILABLE_BACKLIGHT;
91 }
92 } // Power
93 } // WrtDeviceApis