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 FBaseRtEvent.h
20 * @brief This is the header file for the %Event class.
22 * This file contains the declarations of the %Event class.
25 #ifndef _FBASE_RT_EVENT_H_
26 #define _FBASE_RT_EVENT_H_
28 #include <FBaseObject.h>
30 namespace Tizen { namespace Base { namespace Runtime
37 * @brief This class provides methods for delivering an event with an argument synchronously and asynchronously.
44 * using namespace Tizen::Base::Runtime;
46 * class MyEventArg : public IEventArg
53 * MyEventArg::MyEventArg(int t)
58 * class MyEventListener : public IEventListener
61 * void OnEventReceived(const IEventArg& arg);
65 * MyEventListener::OnEventReceived(const IEventArg& arg)
67 * const MyEventArg* myarg = dynamic_cast<const MyEventArg*> (&arg);
70 * class MyEvent : public Event
73 * virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
77 * MyEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
79 * MyEventListener* plistener = dynamic_cast<MyEventListener*> (&listener);
80 * plistener->OnEventReceived(arg);
84 * MyApplication::Test Code(void)
86 * MyEventListener* mylistener = new MyEventListener();
87 * MyEvent* my = new MyEvent();
88 * MyEventArg* myarg = new MyEventArg(3);
89 * my->AddListener(*mylistener);
95 class _OSP_EXPORT_ Event
96 : virtual public Tizen::Base::Object
100 * This is the default constructor for this class.
107 * This is the destructor for this class.
111 virtual ~Event(void);
114 * Adds the listener object.
115 * The added listener can listen to events when they are fired.
119 * @return An error code
120 * @param[in] listener Listener to add
121 * @param[in] calledByCallerThread true, to call the listener on the caller thread of this method
122 * false, to call the listener on the thread in which the event is fired.
123 * @exception E_SUCCESS This method is successful.
124 * @exception E_OBJ_ALREADY_EXIST The listener already exists.
125 * @exception E_INVALID_OPERATION calledByCallerThread is set to true but the caller thread is a worker thread.
127 result AddListener(IEventListener& listener, bool calledByCallerThread = true);
130 * Removes the listener object.
131 * The removed listener cannot listen to events when they are fired.
135 * @return An error code
136 * @param[in] listener Listener to remove
137 * @exception E_SUCCESS This method is successful.
138 * @exception E_OBJ_NOT_FOUND The listener is not found.
140 result RemoveListener(IEventListener& listener);
143 * Fires the event with an argument.
147 * @return An error code
148 * @param[in] arg The event argument.
149 * @exception E_SUCCESS This method is successful.
150 * @exception E_INVALID_STATE This event has not been initialized.
152 * @remark This takes the ownership of @c arg. So arg should be created on a heap and should not be deleted by caller.
154 result Fire(IEventArg& arg);
158 * Implement to call the corresponding event listener's method.
162 * @param[in] listener The listener instance which is currently processing
163 * @param[in] arg The event argument that is fired
165 * @remark A derived class must override this method.
167 virtual void FireImpl(IEventListener& listener, const IEventArg& arg) = 0;
170 friend class _EventImpl;
171 class _EventImpl* __pEventImpl;
175 } } } // Tizen::Base::Runtime
177 #endif // _FBASE_RT_EVENT_H_