Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Application / JSApplicationContext.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
17 #ifndef TIZENAPIS_TIZEN_JS_APPLICATION_CONTEXT_H_
18 #define TIZENAPIS_TIZEN_JS_APPLICATION_CONTEXT_H_
19
20 #include <JavaScriptCore/JavaScript.h>
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <dpl/shared_ptr.h>
23 #include <API/Application/ApplicationContext.h>
24
25 namespace TizenApis {
26 namespace Tizen1_0 {
27 namespace Application {
28
29 typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationContextPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationContextPriv;
30
31 class JSApplicationContext {
32 public:
33         /*
34         * This initializes this JS class in the JS Engine.
35         */
36         static JSClassRef getClassRef();
37
38         static JSValueRef createJSObject(JSContextRef context,
39                         const std::string &appId,
40                         const std::string &contextId);
41
42         static bool isObjectOfClass(JSContextRef context, JSValueRef value);
43
44         static Api::Application::ApplicationContextPtr 
45                 getApplicationContext(JSContextRef context, JSValueRef value);
46
47 private:
48    /**
49         * The callback invoked when an object is first created.
50         */
51         static void initialize(JSContextRef context, JSObjectRef object);
52
53    /**
54         * The callback invoked when an object is finalized.
55         */
56         static void finalize(JSObjectRef object);
57
58    /**
59         * This structure contains properties and callbacks that define a type of object.
60         */
61         static JSClassDefinition m_classInfo;
62
63    /**
64         * This structure describes a statically declared function property.
65         */
66         static JSStaticFunction m_functions[];
67
68         /**
69          * This member variable contains the initialization values for the static properties of this class.
70          * The values are given according to the data structure JSPropertySpec
71          */
72         static JSStaticValue m_property[];
73
74         static JSClassRef m_classRef;
75
76         static Api::Application::ApplicationContextPtr getPrivData(JSObjectRef object);
77
78         static JSValueRef getAppId(JSContextRef context,
79                         JSObjectRef object,
80                         JSStringRef propertyName,
81                         JSValueRef* exception);
82
83         static bool setAppId(JSContextRef context,
84                         JSObjectRef object,
85                         JSStringRef propertyName,
86                         JSValueRef appId,
87                         JSValueRef* exception);
88
89         static JSValueRef getContextId(JSContextRef context,
90                         JSObjectRef object,
91                         JSStringRef propertyName,
92                         JSValueRef* exception);
93
94         static bool setContextId(JSContextRef context,
95                         JSObjectRef object,
96                         JSStringRef propertyName,
97                         JSValueRef contextId,
98                         JSValueRef* exception);
99
100 };
101
102 }
103 }
104 }
105 #endif