2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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.
18 * @file FBaseRt_EventManager.h
19 * @brief This is the header file for the _EventManager class.
21 * This file contains the declarations of _EventManager.
24 #ifndef _FBASE_RT_INTERNAL_EVENT_MANAGER_H_
25 #define _FBASE_RT_INTERNAL_EVENT_MANAGER_H_
30 #include <FOspConfig.h>
31 #include <FBaseResult.h>
32 #include <FBaseObject.h>
33 #include <FBaseColLinkedListT.h>
34 #include <FBaseColArrayListT.h>
36 #include "FBase_HandleT.h"
38 namespace Tizen { namespace Base { namespace Runtime
47 * @class _EventManager
48 * @brief This class provides methods for managingasynchronous event.
51 * This class provides methods for managing asynchronous event.
54 : public Tizen::Base::Object
58 * This is the default constructor for this class.
66 * This is the destructor for this class
69 virtual ~_EventManager(void);
72 * Initializes this instanc of %_EventManager.
76 * @return An error code
77 * @param[in] pGmainContext A GMainLoopContext
78 * @exception E_SUCCESS The method is successful.
79 * @exception E_SYSTEM A system error has occurred.
81 result Construct(GMainContext* pGmainContext);
87 * @return An error code
88 * @param[in] event The handle of an event to register
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_OBJ_ALREADY_EXIST The event has already been registered.
91 * @exception E_SYSTEM A system error has occurred.
93 result RegisterEvent(const _HandleT< _Event >& event);
96 * Unregisters an event.
100 * @return An error code
101 * @param[in] event The handle of an event to unregister
102 * @exception E_SUCCESS The method is successful.
103 * @exception E_OBJ_NOT_FOUND The event has not been registered.
105 result UnregisterEvent(const _HandleT< _Event >& event);
108 * Returns the %_EventManager of current thread.
112 * @return The pointer to _EventManager
114 * @remark null will be returned if this is called by a worker thread.
116 static _EventManager* GetCurrentEventManager(void);
119 * Sends an event asynchronously.
123 * @return An error code
124 * @param[in] event The event to send
125 * @param[in] arg The event arg
126 * @exception E_SUCCESS The method is successful.
127 * @remark This takes ownership of the arg. Therefore the caller must not delete the arg instance.
129 result FireEventAsync(const _HandleT< _Event >& event, std::tr1::shared_ptr< IEventArg > arg);
132 * Calls a listener added to an event asynchronously.
136 * @return An error code
137 * @param[in] event The event
138 * @param[in] arg The event arg
139 * @param[in] listener The listener to call
140 * @exception E_SUCCESS The method is successful.
141 * @remark This takes ownership of the arg. Therefore the caller must not delete the arg instance.
143 result CallListenerAsync(const _HandleT< _Event >& event, std::tr1::shared_ptr< IEventArg > arg, const _HandleT< IEventListener >& listener);
146 * Clears all pending event messages of an event.
149 * @param[in] event The event to clear
151 void ClearAllPendingEventMessages(const _HandleT< _Event >& event);
157 * @param[in] event The event to clear
159 _HandleT< _EventManager > GetHandle(void) const;
162 * Gets _EventManager using given handle
166 * @param[in] handle The handle of _EventManager
168 static _EventManager* GetEventManagerByHandle(const _HandleT< _EventManager >& handle);
171 * Gets object manager for _EventManager
175 static _ObjectManagerT< _EventManager >& GetEventManagerObjectManager(void);
178 * Gets object manager for _Event
182 static _ObjectManagerT< _Event >& GetEventObjectManager(void);
185 * Gets object manager for IEventListener
189 static _ObjectManagerT< IEventListener >& GetEventListenerObjectManager(void);
192 _EventManager(const _EventManager& rhs);
193 _EventManager& operator =(const _EventManager& rhs);
195 static gboolean OnEventReceived(GIOChannel* pChannel, GIOCondition condition, gpointer data);
200 MESSAGE_TYPE_FIRE_EVENT,
201 MESSAGE_TYPE_CALL_LISTENER
208 , type(MESSAGE_TYPE_FIRE_EVENT)
214 _HandleT< _Event > event;
215 std::tr1::shared_ptr< IEventArg > arg;
216 _HandleT< IEventListener > listener;
218 bool operator ==(const _EventMessage& rhs) const;
219 bool operator !=(const _EventMessage& rhs) const;
221 _EventMessage& operator =(const _EventMessage& rhs);
227 GIOChannel* __pChannel;
228 GMainContext* __pGmainContext;
229 _HandleT< _EventManager > __handle;
230 Tizen::Base::Collection::LinkedListT< _HandleT< _Event > > __events;
231 Tizen::Base::Collection::ArrayListT< _EventMessage > __messages1;
232 Tizen::Base::Collection::ArrayListT< _EventMessage > __messages2;
233 Tizen::Base::Collection::ArrayListT< _EventMessage >* __pActive;
234 Tizen::Base::Collection::ArrayListT< _EventMessage >* __pReady;
237 } } } // Tizen::Base::Runtime
239 #endif // _FBASE_RT_INTERNAL_EVENT_MANAGER_H_