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
23 #ifndef DPL_MAIN_EVENT_DISPATCHER_H
24 #define DPL_MAIN_EVENT_DISPATCHER_H
26 #include <dpl/event/abstract_event_dispatcher.h>
27 #include <dpl/event/abstract_event_call.h>
28 #include <dpl/waitable_event.h>
29 #include <dpl/exception.h>
30 #include <dpl/singleton.h>
31 #include <dpl/framework_efl.h>
37 class MainEventDispatcher :
38 public AbstractEventDispatcher
44 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
45 DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
46 DECLARE_EXCEPTION_TYPE(Base, AddEventFailed)
47 DECLARE_EXCEPTION_TYPE(Base, AddTimedEventFailed)
51 struct WrappedEventCall
53 AbstractEventCall *abstractEventCall;
57 WrappedEventCall(AbstractEventCall *abstractEventCallArg,
60 abstractEventCall(abstractEventCallArg),
66 typedef std::list<WrappedEventCall> WrappedEventCallList;
68 // Cross thread send support
69 WrappedEventCallList m_wrappedCrossEventCallList;
70 std::mutex m_crossEventCallMutex;
71 WaitableEvent* m_crossEventCallInvoker;
73 Ecore_Event_Handler *m_eventCallHandler;
74 Ecore_Fd_Handler *m_crossEventCallHandler;
78 // Timed event support
79 struct TimedEventStruct
81 AbstractEventCall *abstractEventCall;
82 MainEventDispatcher *This;
84 TimedEventStruct(AbstractEventCall *abstractEventCallArg,
85 MainEventDispatcher *ThisArg) :
86 abstractEventCall(abstractEventCallArg),
91 void InternalAddEvent(AbstractEventCall *abstractEventCall,
95 static void StaticDeleteEvent(void *data, void *event);
96 static Eina_Bool StaticDispatchEvent(void *data, int type, void *event);
97 static Eina_Bool StaticDispatchTimedEvent(void *event);
98 static Eina_Bool StaticDispatchCrossInvoker(void *data,
99 Ecore_Fd_Handler *fd_handler);
101 void DeleteEvent(AbstractEventCall *abstractEventCall);
102 void DispatchEvent(AbstractEventCall *abstractEventCall);
103 void DispatchTimedEvent(AbstractEventCall *abstractEventCall);
104 void DispatchCrossInvoker();
107 explicit MainEventDispatcher();
108 virtual ~MainEventDispatcher();
110 virtual void AddEventCall(AbstractEventCall *abstractEventCall);
111 virtual void AddTimedEventCall(AbstractEventCall *abstractEventCall,
113 virtual void ResetCrossEventCallHandler();
116 MainEventDispatcher& GetMainEventDispatcherInstance();
120 #endif // DPL_MAIN_EVENT_DISPATCHER_H