40f8f8eec6fc6b826cadae84d4b4e71349ed8770
[framework/web/wrt-plugins-tizen.git] / src / Common / GlobalContextManager.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_COMMON_GLOBALCONTEXTMANAGER_
19 #define _TIZEN_COMMON_GLOBALCONTEXTMANAGER_
20
21 #include <JavaScriptCore/JavaScript.h>
22 #include <map>
23
24 namespace DeviceAPI {
25 namespace Common{
26
27
28 /**
29  * @brief Manage and tracking global context handle
30  */
31 class GlobalContextManager{
32     public :
33         /**
34          *  @breif Gets global context from local context
35          *
36          * @param ctx local context
37          * @return The global context reference or NULL if function has failed
38          */
39         JSContextRef getGlobalContext(JSContextRef ctx);
40
41         /**
42          *  @breif Add global context in manager
43          *
44          * @param ctx The global context to add
45          */
46         void addGlobalContext(JSContextRef ctx);
47
48         /**
49          *  @breif Remove global context in manager
50          *
51          * @param ctx The global context to remove
52          */
53         void removeGlobalContext(JSContextRef ctx);
54
55         /**
56          *  @breif Check the validation of global context
57          *
58          * @param ctx The global context to check
59          * @return true : the global context is alive, false : the global context was released
60          */
61         bool isAliveGlobalContext(JSContextRef ctx);
62
63         /**
64          *  @breif Gets singletone handle
65          *
66          * @return GlobalContextManager handle
67          */
68         static GlobalContextManager* getInstance();
69
70     private:
71         GlobalContextManager();
72         typedef std::map<JSObjectRef, JSContextRef> ContextMapT;
73         std::map<JSObjectRef, JSContextRef> mContexts;
74 };
75
76 }
77 }
78 #endif //_TIZEN_COMMON_GLOBALCONTEXTMANAGER_