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 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
21 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_
23 #include <dpl/shared_ptr.h>
24 #include <Commons/IEvent.h>
25 #include <CommonsJavaScript/JSPendingOperation.h>
26 #include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
28 namespace WrtDeviceApis {
29 namespace CommonsJavaScript {
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.
37 template<typename EventType>
38 JSObjectRef makePendingOperation(JSContextRef context,
39 const DPL::SharedPtr<EventType>& event)
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);
49 template<typename EventType>
50 JSObjectRef makeExtCancelSupportedPendingOperation(
52 const DPL::SharedPtr<EventType>& event,
53 const DPL::SharedPtr<Commons::IExternEventCanceler<EventType> >&
56 IJSPendingOperationPrivateObject* pendingOperation =
57 new IJSExtCancelPendingOperationPrivateObject<EventType>(event, cancel);
59 return JSObjectMake(context,
60 JSPendingOperation::getClassRef(),
63 } // CommonsJavaScript
66 #endif // WRTDEVICEAPIS_COMMONSJAVASCRIPT_UTILS_H_