2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file JSCallbackManager.h
18 * @author Lukasz Marek (l.marel@samsung.com)
22 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_MANAGER_H_
23 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_MANAGER_H_
25 #include <dpl/shared_ptr.h>
26 #include <Commons/IEvent.h>
27 #include <JavaScriptCore/JavaScript.h>
29 namespace WrtDeviceApis {
30 namespace CommonsJavaScript {
32 class JSCallbackManager;
33 typedef DPL::SharedPtr<JSCallbackManager> JSCallbackManagerPtr;
35 class JSCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
43 * Used to create JSCallbackManagerPtr object by factory method createObject
45 JSCallbackManager(JSContextRef context,
46 JSObjectRef onSuccess,
51 //JSCallbackManager( JSContextRef context, JSValueRef onSuccess, JSValueRef onError );
54 * Create JSCallbackManagerPtr object witch checking callback parameters
55 * if callbacks are NULL it was programmer intention to not use callback and no exception will be rised
56 * if callbacks are some object but not a function it will rise exception
57 * @param[in] context - global context
58 * @param[in] onSuccess - success callback (may be NULL if not needed)
59 * @param[in] onError - error callback (may be NULL if not needed)
60 * @param[in] acceptJSNullAsOnSuccess - converts JSNull on onSuccess to NULL when true
61 * @param[in] acceptJSNullAsOnError - converts JSNull on onError to NULL when true
62 * @throw Commons::InvalidArgumentException - if callback is not null and is not a js function
64 static JSCallbackManagerPtr createObject(
66 JSValueRef onSuccess = NULL,
67 JSValueRef onError = NULL,
68 bool acceptJSNullAsOnSuccess = false,
69 bool acceptJSNullAsOnError = false);
71 virtual ~JSCallbackManager();
73 void setContext(JSContextRef context);
75 JSContextRef getContext() const
80 void setOnSuccess(JSValueRef onSuccess);
81 JSValueRef getOnSuccess() const;
82 void setOnError(JSValueRef onError);
83 JSValueRef getOnError() const;
84 void setObject(JSObjectRef object);
85 JSObjectRef getObject() const;
88 void callOnSuccess(JSValueRef obj);
89 void callOnSuccess(JSValueRef obj[], int paramCount);
92 void callOnError(JSValueRef obj);
93 void callOnError(JSValueRef obj[], int paramCount);
96 void makeCallback(JSContextRef context,
102 JSObjectRef m_onSuccess;
103 JSObjectRef m_onError;
104 JSContextRef m_context;
105 JSObjectRef m_object;
108 bool isCallback(JSContextRef ctx,
110 JSValueRef* exception);
114 #endif // WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_CALLBACK_MANAGER_H_