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 FBaseRtEvent.h
19 * @brief This is the header file for the %Event class.
21 * This file contains the declarations of the %Event class.
24 #ifndef _FBASE_RT_EVENT_H_
25 #define _FBASE_RT_EVENT_H_
27 #include <FBaseObject.h>
29 namespace Tizen { namespace Base { namespace Runtime
36 * @brief This class provides methods for delivering an event with an argument synchronously and asynchronously.
43 * using namespace Tizen::Base::Runtime;
45 * class MyEventArg : public IEventArg
52 * MyEventArg::MyEventArg(int t)
57 * class MyEventListener : public IEventListener
60 * void OnEventReceived(const IEventArg& arg);
64 * MyEventListener::OnEventReceived(const IEventArg& arg)
66 * const MyEventArg* myarg = dynamic_cast<const MyEventArg*> (&arg);
69 * class MyEvent : public Event
72 * virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
76 * MyEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
78 * MyEventListener* plistener = dynamic_cast<MyEventListener*> (&listener);
79 * plistener->OnEventReceived(arg);
83 * MyApplication::Test Code(void)
85 * MyEventListener* mylistener = new MyEventListener();
86 * MyEvent* my = new MyEvent();
87 * MyEventArg* myarg = new MyEventArg(3);
88 * my->AddListener(*mylistener);
94 class _OSP_EXPORT_ Event
95 : virtual public Tizen::Base::Object
99 * This is the default constructor for this class.
106 * This is the destructor for this class.
110 virtual ~Event(void);
113 * Adds the listener object.
114 * The added listener can listen to events when they are fired.
118 * @return An error code
119 * @param[in] listener Listener to add
120 * @param[in] calledByCallerThread true, to call the listener on the caller thread of this method
121 * false, to call the listener on the thread in which the event is fired.
122 * @exception E_SUCCESS This method is successful.
123 * @exception E_OBJ_ALREADY_EXIST The listener already exists.
124 * @exception E_INVALID_OPERATION calledByCallerThread is set to true but the caller thread is a worker thread.
126 result AddListener(IEventListener& listener, bool calledByCallerThread = true);
129 * Removes the listener object.
130 * The removed listener cannot listen to events when they are fired.
134 * @return An error code
135 * @param[in] listener Listener to remove
136 * @exception E_SUCCESS This method is successful.
137 * @exception E_OBJ_NOT_FOUND The listener is not found.
139 result RemoveListener(IEventListener& listener);
142 * Fires the event with an argument.
146 * @return An error code
147 * @param[in] arg The event argument.
148 * @exception E_SUCCESS This method is successful.
149 * @exception E_INVALID_STATE This event has not been initialized.
151 * @remark This takes the ownership of @c arg. So arg should be created on a heap and should not be deleted by caller.
153 result Fire(IEventArg& arg);
157 * Implement to call the corresponding event listener's method.
161 * @param[in] listener The listener instance which is currently processing
162 * @param[in] arg The event argument that is fired
164 * @remark A derived class must override this method.
166 virtual void FireImpl(IEventListener& listener, const IEventArg& arg) = 0;
169 friend class _EventImpl;
170 class _EventImpl* __pEventImpl;
174 } } } // Tizen::Base::Runtime
176 #endif // _FBASE_RT_EVENT_H_