tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Application / ApplicationUtil.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 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 TIZENAPIS_PLATFORM_APPLICATION_UTIL_H_
19 #define TIZENAPIS_PLATFORM_APPLICATION_UTIL_H_
20
21 #include <CommonsJavaScript/Converter.h>
22 #include <PlatformException.h>
23 #include <Logger.h>
24
25 namespace DeviceAPI {
26 namespace Application {
27 class ApplicationUtil
28 {
29   public:
30     explicit ApplicationUtil(JSContextRef context,
31             JSValueRef* exception = NULL);
32     virtual ~ApplicationUtil();
33
34     bool isObject(const JSValueRef& arg);
35     bool isString(const JSValueRef& arg);
36     bool isFunction(const JSValueRef& arg);
37     bool isArray(const JSValueRef& arg);
38     bool isNullOrString(const JSValueRef& arg);
39     bool isNullOrObject(const JSValueRef& arg);
40     bool isNullOrFunction(const JSValueRef& arg);
41     bool isNullOrArray(const JSValueRef& arg);
42     bool isNullOrUndefined(const JSValueRef& arg);
43     bool isNullOrUndefinedOrString(const JSValueRef& arg);
44     bool isNullOrUndefinedOrObject(const JSValueRef& arg);
45     bool isNullOrUndefinedOrFunction(const JSValueRef& arg);
46     bool isNullOrUndefinedOrArray(const JSValueRef& arg);
47
48     static std::string getApplicationMessage(const int errorCode);
49     static std::string getApplicationManagerMessage(const int errorCode);
50     static std::string getApplicationPkgmgrinfoMessage(const int errorCode);
51     static std::string getApplicationPackageManagerMessage(const int errorCode);
52     static std::string getApplicationAulMessage(const int errorCode);
53
54     static std::string getApplicationErrorMessage(const int errorCode,
55             const std::string &hint,
56             std::string (*function)(const int));
57
58     template <class T>
59     static void throwApplicationException(
60               const int errorCode,
61               const std::string &hint,
62               std::string (*function)(const int))
63     {
64         LOGD("Entered");
65         std::string ss = getApplicationErrorMessage(errorCode, hint, function);
66         LOGE("%s", ss.c_str());
67         ThrowMsg(T, ss.c_str());
68     }
69
70   protected:
71     JSContextRef m_context;
72     JSValueRef* m_exception;
73 };
74
75 }
76 } //
77
78 #endif
79