tizen 2.4 release
[framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / JSLifeManager.h
1 /*
2  * Copyright (c) 2014 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
18 #ifndef JS_LIFE_MANAGER_H_
19 #define JS_LIFE_MANAGER_H_
20
21 #include <JavaScriptCore/JavaScript.h>
22
23 namespace WrtDeviceApis {
24 namespace CommonsJavaScript {
25
26 class JSLifeManagerImpl;
27 class JSLifeManager{
28     public:
29         void JSValueProtect(JSContextRef ctx, JSValueRef value);
30         void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
31         void ReleaseContext(JSContextRef ctx);
32         void AddGlobalContext(JSContextRef ctx);
33         bool IsAvailableContext(JSContextRef ctx);
34         static JSLifeManager& GetInstance();
35     private:
36         JSLifeManager();
37         ~JSLifeManager();
38         JSLifeManager(const JSLifeManager&) = delete;
39         JSLifeManager& operator=(const JSLifeManager&) = delete;
40         JSLifeManagerImpl *mImpl;
41 };
42 } // CommonsJavaScript
43 } // WrtDeviceApis
44
45
46 #define JSValueSafeProtect(ctx,value) \
47     do {\
48         WrtDeviceApis::CommonsJavaScript::JSLifeManager::GetInstance().JSValueProtect(ctx,value); \
49     }while(0)
50
51
52 #define JSValueSafeUnprotect(ctx,value) \
53     do {\
54         WrtDeviceApis::CommonsJavaScript::JSLifeManager::GetInstance().JSValueUnprotect(ctx,value); \
55     }while(0)
56
57
58 #endif