2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseRt_EventManager.h
20 * @brief This is the header file for the _EventManager class.
22 * This file contains the declarations of _EventManager.
25 #ifndef _FBASE_RT_INTERNAL_EVENT_MANAGER_H_
26 #define _FBASE_RT_INTERNAL_EVENT_MANAGER_H_
31 #include <FOspConfig.h>
32 #include <FBaseResult.h>
33 #include <FBaseObject.h>
34 #include <FBaseColLinkedListT.h>
35 #include <FBaseColArrayListT.h>
37 #include "FBase_HandleT.h"
39 namespace Tizen { namespace Base { namespace Runtime
48 * @class _EventManager
49 * @brief This class provides methods for managingasynchronous event.
52 * This class provides methods for managing asynchronous event.
55 : public Tizen::Base::Object
59 * This is the default constructor for this class.
67 * This is the destructor for this class
70 virtual ~_EventManager(void);
73 * Initializes this instanc of %_EventManager.
77 * @return An error code
78 * @param[in] pGmainContext A GMainLoopContext
79 * @exception E_SUCCESS The method is successful.
80 * @exception E_SYSTEM A system error has occurred.
82 result Construct(GMainContext* pGmainContext);
88 * @return An error code
89 * @param[in] event The handle of an event to register
90 * @exception E_SUCCESS The method is successful.
91 * @exception E_OBJ_ALREADY_EXIST The event has already been registered.
92 * @exception E_SYSTEM A system error has occurred.
94 result RegisterEvent(const _HandleT< _Event >& event);
97 * Unregisters an event.
101 * @return An error code
102 * @param[in] event The handle of an event to unregister
103 * @exception E_SUCCESS The method is successful.
104 * @exception E_OBJ_NOT_FOUND The event has not been registered.
106 result UnregisterEvent(const _HandleT< _Event >& event);
109 * Returns the %_EventManager of current thread.
113 * @return The pointer to _EventManager
115 * @remark null will be returned if this is called by a worker thread.
117 static _EventManager* GetCurrentEventManager(void);
120 * Sends an event asynchronously.
124 * @return An error code
125 * @param[in] event The event to send
126 * @param[in] arg The event arg
127 * @exception E_SUCCESS The method is successful.
128 * @remark This takes ownership of the arg. Therefore the caller must not delete the arg instance.
130 result FireEventAsync(const _HandleT< _Event >& event, std::tr1::shared_ptr< IEventArg > arg);
133 * Calls a listener added to an event asynchronously.
137 * @return An error code
138 * @param[in] event The event
139 * @param[in] arg The event arg
140 * @param[in] listener The listener to call
141 * @exception E_SUCCESS The method is successful.
142 * @remark This takes ownership of the arg. Therefore the caller must not delete the arg instance.
144 result CallListenerAsync(const _HandleT< _Event >& event, std::tr1::shared_ptr< IEventArg > arg, const _HandleT< IEventListener >& listener);
147 * Clears all pending event messages of an event.
150 * @param[in] event The event to clear
152 void ClearAllPendingEventMessages(const _HandleT< _Event >& event);
158 * @param[in] event The event to clear
160 _HandleT< _EventManager > GetHandle(void) const;
163 * Gets _EventManager using given handle
167 * @param[in] handle The handle of _EventManager
169 static _EventManager* GetEventManagerByHandle(const _HandleT< _EventManager >& handle);
172 * Gets object manager for _EventManager
176 static _ObjectManagerT< _EventManager >& GetEventManagerObjectManager(void);
179 * Gets object manager for _Event
183 static _ObjectManagerT< _Event >& GetEventObjectManager(void);
186 * Gets object manager for IEventListener
190 static _ObjectManagerT< IEventListener >& GetEventListenerObjectManager(void);
193 _EventManager(const _EventManager& rhs);
194 _EventManager& operator =(const _EventManager& rhs);
196 static gboolean OnEventReceived(GIOChannel* pChannel, GIOCondition condition, gpointer data);
201 MESSAGE_TYPE_FIRE_EVENT,
202 MESSAGE_TYPE_CALL_LISTENER
209 , type(MESSAGE_TYPE_FIRE_EVENT)
215 _HandleT< _Event > event;
216 std::tr1::shared_ptr< IEventArg > arg;
217 _HandleT< IEventListener > listener;
219 bool operator ==(const _EventMessage& rhs) const;
220 bool operator !=(const _EventMessage& rhs) const;
222 _EventMessage& operator =(const _EventMessage& rhs);
228 GIOChannel* __pChannel;
229 GMainContext* __pGmainContext;
230 _HandleT< _EventManager > __handle;
231 Tizen::Base::Collection::LinkedListT< _HandleT< _Event > > __events;
232 Tizen::Base::Collection::ArrayListT< _EventMessage > __messages1;
233 Tizen::Base::Collection::ArrayListT< _EventMessage > __messages2;
234 Tizen::Base::Collection::ArrayListT< _EventMessage >* __pActive;
235 Tizen::Base::Collection::ArrayListT< _EventMessage >* __pReady;
238 } } } // Tizen::Base::Runtime
240 #endif // _FBASE_RT_INTERNAL_EVENT_MANAGER_H_