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 generic_event_call.h
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of generic event call
22 #ifndef DPL_GENERIC_EVENT_CALL_H
23 #define DPL_GENERIC_EVENT_CALL_H
25 #include <dpl/event/abstract_event_call.h>
26 #include <dpl/event/event_listener.h>
27 #include <dpl/noncopyable.h>
28 #include <dpl/fast_delegate.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
37 template<typename EventType, typename SupportDataType>
38 class GenericEventCall
39 : public AbstractEventCall
42 typedef EventListener<EventType> EventListenerType;
43 typedef FastDelegate1<const EventType &> DelegateType;
46 SupportDataType m_supportData;
47 EventListenerType *m_eventListener;
48 DelegateType m_delegate;
52 template<typename OtherEventType, typename OtherSupportType>
55 typedef GenericEventCall<OtherEventType, OtherSupportType> Other;
58 GenericEventCall(SupportDataType supportData,
59 EventListenerType *eventListener,
60 DelegateType delegate,
61 const EventType &event)
62 : m_supportData(supportData),
63 m_eventListener(eventListener),
69 virtual ~GenericEventCall()
71 Assert(m_supportData == NULL &&
72 "Call method hasn't been called"
73 " (support data wasn't destroyed)");
78 LogPedantic("Calling generic event call");
80 m_supportData->CallAndDestroy(m_event, m_eventListener, m_delegate);
82 // Now m_supportData points to invalid object. Marking it as NULL.
85 LogPedantic("Generic event called");
88 virtual void DisableEvent()
90 LogPedantic("Disabling this EventCall");
91 m_supportData->Reset();
93 // TODO: In the future, event should be completely removed
94 // from the event queue (not just marked "disabled")
101 #endif // DPL_GENERIC_EVENT_CALL_H