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.Get());
47 LogDebug("PendingOperation tries to cancel the request");
48 return m_event->cancelRequest();
51 virtual ~IJSPendingOperationPrivateObject()
55 DPL::SharedPtr<Commons::IEventController> m_event;
59 * This class implements private object for JavaScript PendingOperation
60 * with support to external cancel function.
62 * When the cancel() method is invoked on PendingOperation,
63 * the OnCancelEvent(<EventType>) method is invoked on user object
64 * with apropriate * arguments.
65 * It allows user to perform an additional action when PendingOperation
68 * The Object which want to handle OnCancelEvent have to inherit from
69 * Platform::IExternEventCanceler<EventType>.
71 * The cancel's handler have to be passed as second argument
73 template<class TemplateEvent>
74 class IJSExtCancelPendingOperationPrivateObject :
75 public IJSPendingOperationPrivateObject
78 IJSExtCancelPendingOperationPrivateObject(
79 const DPL::SharedPtr< TemplateEvent> &event,
81 Commons::IExternEventCanceler<TemplateEvent> > & cancel) :
82 IJSPendingOperationPrivateObject(
83 DPL::StaticPointerCast<Commons::IEventController>(event)),
86 assert(NULL != m_canceler);
91 bool result = IJSPendingOperationPrivateObject::cancel();
93 LogDebug("Controller can not cancel event, trying platform cancel");
99 LogDebug("Calling extern cancel");
100 m_canceler->OnCancelEvent(
101 DPL::StaticPointerCast<TemplateEvent>(m_event));
107 virtual ~IJSExtCancelPendingOperationPrivateObject()
111 DPL::SharedPtr< Commons::IExternEventCanceler<TemplateEvent> > m_canceler;
115 #endif /* _JS_WAC_PENDING_OPERATION_PRIVATE_OBJECT_H_ */