tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Systeminfo / SystemInfoUtil.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 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 #ifndef __TIZEN_SYSTEMINFO_SYSTEMINFO_UTIL_H__
19 #define __TIZEN_SYSTEMINFO_SYSTEMINFO_UTIL_H__
20
21 #include <sstream>
22 #include <string>
23 #include <Logger.h>
24 #include <PlatformException.h>
25
26 namespace DeviceAPI {
27 namespace SystemInfo {
28
29 class SystemInfoUtil {
30 public:
31
32     static std::string getSystemInfoErrorMessage(const int errorCode);
33     static std::string getConnectionErrorMessage(const int errorCode);
34     static std::string getTapiErrorMessage(const int errorCode);
35     static std::string getSettingErrorMessage(const int errorCode);
36     static std::string getWIFIErrorMessage(const int errorCode);
37
38
39     template<class T = DeviceAPI::Common::UnknownException>
40     static void throwSystemInfoException(const int errorCode, const std::string& hint)
41     {
42         std::stringstream ss;
43         ss << hint << " : " << getSystemInfoErrorMessage(errorCode);
44         LOGE("%s", ss.str().c_str());
45
46         throw T(ss.str().c_str());
47     }
48
49     template<class T = DeviceAPI::Common::UnknownException>
50     static void throwConnectionException(const int errorCode, const std::string& hint)
51     {
52         std::stringstream ss;
53         ss << hint << " : " << getConnectionErrorMessage(errorCode);
54         LOGE("%s", ss.str().c_str());
55
56         throw T(ss.str().c_str());
57     }
58
59     template<class T = DeviceAPI::Common::UnknownException>
60     static void throwTapiException(const int errorCode, const std::string& hint)
61     {
62         std::stringstream ss;
63         ss << hint << " : " << getTapiErrorMessage(errorCode);
64         LOGE("%s", ss.str().c_str());
65
66         throw T(ss.str().c_str());
67     }
68
69     template<class T = DeviceAPI::Common::UnknownException>
70     static void throwSettingException(const int errorCode, const std::string& hint)
71     {
72         std::stringstream ss;
73         ss << hint << " : " << getSettingErrorMessage(errorCode);
74         LOGE("%s", ss.str().c_str());
75
76         throw T(ss.str().c_str());
77     }
78
79     template<class T = DeviceAPI::Common::UnknownException>
80     static void throwWIFIException(const int errorCode, const std::string& hint)
81     {
82         std::stringstream ss;
83         ss << hint << " : " << getWIFIErrorMessage(errorCode);
84         LOGE("%s", ss.str().c_str());
85
86         throw T(ss.str().c_str());
87     }
88
89 };
90
91 } //SystemInfo
92 } //DeviceAPI
93
94 #endif /* __TIZEN_SYSTEMINFO_SYSTEMINFO_UTIL_H__ */