tizen 2.3 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Power / PowerUtil.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "PowerUtil.h"
19
20 #include <sstream>
21 #include <PlatformException.h>
22 #include <Logger.h>
23
24 namespace DeviceAPI {
25 namespace Power {
26
27 using namespace DeviceAPI::Common;
28
29 void PowerUtil::throwPowerException(const int errorCode, const std::string &hint)
30 {
31     std::stringstream ss;
32     ss << hint << " : " << getPowerErrorMessage(errorCode);
33     LOGE("%s", ss.str().c_str());
34
35     switch(errorCode) {
36         case DEVICE_ERROR_INVALID_PARAMETER:
37             throw InvalidValuesException(ss.str().c_str());
38         case DEVICE_ERROR_PERMISSION_DENIED:
39             throw SecurityException(ss.str().c_str());
40         default:
41             throw UnknownException(ss.str().c_str());
42     }
43 }
44
45 std::string PowerUtil::getPowerErrorMessage(const int errorCode)
46 {
47     LOGE("%d", errorCode);
48
49     switch(errorCode) {
50         case DEVICE_ERROR_OPERATION_FAILED:
51             return "Operation failed";
52         case DEVICE_ERROR_PERMISSION_DENIED:
53             return "Permission denied";
54         case DEVICE_ERROR_INVALID_PARAMETER:
55             return "Invalid Parameter";
56         case DEVICE_ERROR_ALREADY_IN_PROGRESS:
57             return "Operation already in progress";
58         case DEVICE_ERROR_NOT_SUPPORTED:
59             return "Not supported";
60         case DEVICE_ERROR_NOT_INITIALIZED:
61             return "Not initialized";
62         default:
63             return "Unknown Error";
64     }
65 }
66
67 } // Power
68 } // DeviceAPI