Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / CommonsJavaScript / Utils.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  * @author          Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
18  */
19
20 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
21 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
22
23 #include <dpl/shared_ptr.h>
24 #include <Commons/IEvent.h>
25 #include <CommonsJavaScript/JSPendingOperation.h>
26 #include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
27
28 namespace WrtDeviceApis {
29 namespace CommonsJavaScript {
30 /**
31  * Creates pending operation object.
32  * @param context Global context.
33  * @param event Event or other object enclosed in shared ptr and convertible
34  *              to @see WrtDeviceApis::Commons::IEventController.
35  * @return Pending operation object.
36  */
37 template<typename EventType>
38 JSObjectRef makePendingOperation(JSContextRef context,
39                                  const DPL::SharedPtr<EventType>& event)
40 {
41     Commons::IEventControllerPtr eventController =
42         DPL::StaticPointerCast<Commons::IEventController>(event);
43     IJSPendingOperationPrivateObject* pendingOperation =
44         new IJSPendingOperationPrivateObject(eventController);
45     return JSObjectMake(context,
46                         JSPendingOperation::getClassRef(), pendingOperation);
47 }
48
49 template<typename EventType>
50 JSObjectRef makeExtCancelSupportedPendingOperation(
51     JSContextRef context,
52     const DPL::SharedPtr<EventType>& event,
53     const DPL::SharedPtr<Commons::IExternEventCanceler<EventType> >&
54     cancel)
55 {
56     IJSPendingOperationPrivateObject* pendingOperation =
57         new IJSExtCancelPendingOperationPrivateObject<EventType>(event, cancel);
58
59     return JSObjectMake(context,
60                         JSPendingOperation::getClassRef(),
61                         pendingOperation);
62 }
63 } // CommonsJavaScript
64 } // WrtDeviceApis
65
66 #endif // WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_