7c0567c5fc05563205bf610a862205978b182e99
[platform/framework/web/wrt-commons.git] / modules / event / include / dpl / event / generic_event_call.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  * @file        generic_event_call.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of generic event call
21  */
22 #ifndef DPL_GENERIC_EVENT_CALL_H
23 #define DPL_GENERIC_EVENT_CALL_H
24
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>
31
32 namespace DPL
33 {
34 namespace Event
35 {
36
37 template<typename EventType, typename SupportDataType>
38 class GenericEventCall
39     : public AbstractEventCall
40 {
41 public:
42     typedef EventListener<EventType> EventListenerType;
43     typedef FastDelegate1<const EventType &> DelegateType;
44
45 protected:
46     SupportDataType m_supportData;
47     EventListenerType *m_eventListener;
48     DelegateType m_delegate;
49     EventType m_event;
50
51 public:
52     template<typename OtherEventType, typename OtherSupportType>
53     struct Rebind
54     {
55         typedef GenericEventCall<OtherEventType, OtherSupportType> Other;
56     };
57
58     GenericEventCall(SupportDataType supportData,
59                      EventListenerType *eventListener,
60                      DelegateType delegate,
61                      const EventType &event)
62         : m_supportData(supportData),
63           m_eventListener(eventListener),
64           m_delegate(delegate),
65           m_event(event)
66     {
67     }
68
69     virtual ~GenericEventCall()
70     {
71         Assert(m_supportData == NULL &&
72                "Call method hasn't been called"
73                " (support data wasn't destroyed)");
74     }
75
76     virtual void Call()
77     {
78         LogPedantic("Calling generic event call");
79
80         m_supportData->CallAndDestroy(m_event, m_eventListener, m_delegate);
81
82         // Now m_supportData points to invalid object. Marking it as NULL.
83         m_supportData = NULL;
84
85         LogPedantic("Generic event called");
86     }
87
88     virtual void DisableEvent()
89     {
90         LogPedantic("Disabling this EventCall");
91         m_supportData->Reset();
92
93         // TODO: In the future, event should be completely removed
94         // from the event queue (not just marked "disabled")
95     }
96 };
97
98 }
99 } // namespace DPL
100
101 #endif // DPL_GENERIC_EVENT_CALL_H