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 Karol Majewski (k.majewski@samsung.com)
22 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDING_OPERATION_PRIVATE_OBJECT_H_
23 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_PENDING_OPERATION_PRIVATE_OBJECT_H_
26 #include <dpl/log/log.h>
27 #include <dpl/shared_ptr.h>
28 #include <Commons/EventReceiver.h>
29 #include <Commons/IExternEventCanceler.h>
30 #include <Commons/IEvent.h>
32 namespace WrtDeviceApis {
33 namespace CommonsJavaScript {
34 class IJSPendingOperationPrivateObject
37 explicit IJSPendingOperationPrivateObject(
38 const DPL::SharedPtr<Commons::IEventController>
42 assert(NULL != m_event);
47 LogDebug("PendingOperation tries to cancel the request");
48 return m_event->cancelRequest();
51 virtual ~IJSPendingOperationPrivateObject()
56 DPL::SharedPtr<Commons::IEventController> m_event;
60 * This class implements private object for JavaScript PendingOperation
61 * with support to external cancel function.
63 * When the cancel() method is invoked on PendingOperation,
64 * the OnCancelEvent(<EventType>) method is invoked on user object
65 * with apropriate * arguments.
66 * It allows user to perform an additional action when PendingOperation
69 * The Object which want to handle OnCancelEvent have to inherit from
70 * Platform::IExternEventCanceler<EventType>.
72 * The cancel's handler have to be passed as second argument
74 template<class TemplateEvent>
75 class IJSExtCancelPendingOperationPrivateObject :
76 public IJSPendingOperationPrivateObject
79 IJSExtCancelPendingOperationPrivateObject(
80 const DPL::SharedPtr< TemplateEvent> &event,
82 Commons::IExternEventCanceler<TemplateEvent> > & cancel) :
83 IJSPendingOperationPrivateObject(
84 DPL::StaticPointerCast<Commons::IEventController>(event)),
87 assert(NULL != m_canceler);
92 bool result = IJSPendingOperationPrivateObject::cancel();
94 LogDebug("Controller can not cancel event, trying platform cancel");
100 LogDebug("Calling extern cancel");
101 m_canceler->OnCancelEvent(
102 DPL::StaticPointerCast<TemplateEvent>(m_event));
108 virtual ~IJSExtCancelPendingOperationPrivateObject()
113 DPL::SharedPtr< Commons::IExternEventCanceler<TemplateEvent> > m_canceler;
117 #endif /* _JS_WAC_PENDING_OPERATION_PRIVATE_OBJECT_H_ */