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 main_event_dispatcher.h
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of main event dispatcher for EFL
22 #ifndef DPL_MAIN_EVENT_DISPATCHER_H
23 #define DPL_MAIN_EVENT_DISPATCHER_H
25 #include <dpl/event/abstract_event_dispatcher.h>
26 #include <dpl/event/abstract_event_call.h>
27 #include <dpl/waitable_event.h>
28 #include <dpl/exception.h>
29 #include <dpl/singleton.h>
30 #include <dpl/mutex.h>
31 #include <dpl/framework_efl.h>
39 class MainEventDispatcher
40 : public AbstractEventDispatcher
46 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
47 DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
48 DECLARE_EXCEPTION_TYPE(Base, AddEventFailed)
49 DECLARE_EXCEPTION_TYPE(Base, AddTimedEventFailed)
53 struct WrappedEventCall
55 AbstractEventCall *abstractEventCall;
59 WrappedEventCall(AbstractEventCall *abstractEventCallArg,
62 : abstractEventCall(abstractEventCallArg),
69 typedef std::list<WrappedEventCall> WrappedEventCallList;
71 // Cross thread send support
72 WrappedEventCallList m_wrappedCrossEventCallList;
73 Mutex m_crossEventCallMutex;
74 WaitableEvent m_crossEventCallInvoker;
76 Ecore_Event_Handler *m_eventCallHandler;
77 Ecore_Fd_Handler *m_crossEventCallHandler;
81 // Timed event support
82 struct TimedEventStruct
84 AbstractEventCall *abstractEventCall;
85 MainEventDispatcher *This;
87 TimedEventStruct(AbstractEventCall *abstractEventCallArg,
88 MainEventDispatcher *ThisArg)
89 : abstractEventCall(abstractEventCallArg),
95 void InternalAddEvent(AbstractEventCall *abstractEventCall, bool timed, double dueTime);
97 static void StaticDeleteEvent(void *data, void *event);
98 static Eina_Bool StaticDispatchEvent(void *data, int type, void *event);
99 static Eina_Bool StaticDispatchTimedEvent(void *event);
100 static Eina_Bool StaticDispatchCrossInvoker(void *data, Ecore_Fd_Handler *fd_handler);
102 void DeleteEvent(AbstractEventCall *abstractEventCall);
103 void DispatchEvent(AbstractEventCall *abstractEventCall);
104 void DispatchTimedEvent(AbstractEventCall *abstractEventCall);
105 void DispatchCrossInvoker();
108 explicit MainEventDispatcher();
109 virtual ~MainEventDispatcher();
111 virtual void AddEventCall(AbstractEventCall *abstractEventCall);
112 virtual void AddTimedEventCall(AbstractEventCall *abstractEventCall, double dueTime);
115 MainEventDispatcher& GetMainEventDispatcherInstance();
120 #endif // DPL_MAIN_EVENT_DISPATCHER_H