tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Application / JSApplicationEventCallbackManager.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 _TIZEN_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_
19 #define _TIZEN_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_
20
21 #include <dpl/shared_ptr.h>
22 #include <Commons/IEvent.h>
23 #include <JavaScriptCore/JavaScript.h>
24 #include <Security.h>
25
26 namespace DeviceAPI {
27 namespace Application {
28
29 class JSApplicationEventCallbackManager;
30 typedef DPL::SharedPtr<JSApplicationEventCallbackManager> JSApplicationEventCallbackManagerPtr;
31
32 class JSApplicationEventCallbackManager :
33     public WrtDeviceApis::Commons::IEventPrivateData,
34     public DeviceAPI::Common::SecurityAccessor
35 {
36 private:
37     JSApplicationEventCallbackManager() {}
38     JSApplicationEventCallbackManager( JSContextRef context,
39             JSObjectRef onInstalled = NULL,
40             JSObjectRef onUpdated = NULL,
41             JSObjectRef onUninstalled = NULL,
42             JSObjectRef onError = NULL );
43
44 public:
45     static JSApplicationEventCallbackManagerPtr createObject(JSContextRef context);
46
47     virtual ~JSApplicationEventCallbackManager();
48
49     void    setContext( JSContextRef context );
50     JSContextRef getContext() const { return m_context; }
51
52     void    setOnInstalled( JSValueRef onInstalled );
53     JSValueRef getOnInstalled() const;
54     void    setOnUpdated( JSValueRef onUpdated );
55     JSValueRef getOnUpdated() const;
56     void    setOnUninstalled( JSValueRef onUninstalled );
57     JSValueRef getOnUninstalled() const;
58     void    setOnError( JSValueRef onError );
59     JSValueRef getOnError() const;
60     void    setObject( JSObjectRef object );
61     JSObjectRef getObject() const;
62
63     void    callOnInstalled( JSValueRef contacts );
64     void    callOnUpdated( JSValueRef contacts );
65     void    callOnUninstalled( JSValueRef contactIds );
66     void    callOnError( JSValueRef error );
67
68 private:
69     void    makeCallback(JSContextRef context,
70             JSObjectRef object,
71             JSObjectRef callback,
72             const char *szName,
73             JSValueRef argv[],
74             unsigned argc);
75
76     JSObjectRef  m_onInstalled;
77     JSObjectRef  m_onUpdated;
78     JSObjectRef  m_onUninstalled;
79     JSObjectRef  m_onError;
80     JSContextRef m_context;
81     JSObjectRef  m_object;
82 };
83
84 } // Application
85 } // DeviceAPI
86
87 #endif // _TIZEN_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_