Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / Commons / EventListener.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 #ifndef WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_H_
17 #define WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_H_
18
19 #include <dpl/shared_ptr.h>
20 #include <Commons/ThreadPool.h>
21 #include <Commons/EventReceiver.h>
22
23 namespace WrtDeviceApis {
24 namespace Commons {
25 /**
26  * Base class for listeners.
27  * Object that is to act as listener should dervie from this class and implement
28  * OnAnswerReceived() function.
29  */
30 template<class TemplateEvent>
31 class EventListener : private EventReceiver<TemplateEvent>
32 {
33   public:
34     EventListener(ThreadEnum::Enumeration threadType) :
35         EventReceiver<TemplateEvent>(threadType)
36     {}
37
38     virtual void onAnswerReceived(const DPL::SharedPtr<TemplateEvent>& event) =
39         0;
40
41     void postAnswer(const DPL::SharedPtr<TemplateEvent>& event)
42     {
43         DPL::Event::ControllerEventHandler<DPL::SharedPtr<TemplateEvent> >::
44             PostEvent(
45             event);
46     }
47
48   protected:
49     void OnEventReceived(const DPL::SharedPtr<TemplateEvent> &event)
50     {
51         onAnswerReceived(event);
52     }
53 };
54 }
55 } // WrtDeviceApisCommon
56
57 #endif /* WRTDEVICEAPIS_COMMONS_EVENT_LISTENER_H_ */