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_WaitingLoopImpl.h
19 * @brief This is the header file for the %_WaitingLoopImpl class.
21 * This file contains the declarations of the %_WaitingLoopImpl class.
24 #ifndef _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_
25 #define _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_
28 #include <FBaseObject.h>
29 #include <FBaseRtThread.h>
30 #include <FBaseRtTimer.h>
31 #include <FBaseRtITimerEventListener.h>
33 namespace Tizen { namespace Base { namespace Runtime
37 class IWaitingLoopCondition;
39 * @class _WaitingLoopImpl
40 * @brief This class allows developers to make the current thread wait for callback events. This class should be used only for test codes and don't use this class for commercial applications
43 * @final This class is not intended for extension.
45 class _OSP_EXPORT_ _WaitingLoopImpl
46 : public Tizen::Base::Object
47 , public Tizen::Base::Runtime::ITimerEventListener
51 * This is the destructor for this class.
55 virtual ~_WaitingLoopImpl(void);
58 * Gets the WaitingLoop instance.
62 * @return A pointer to the WaitingLoop instance, @n
63 * else @c null if it fails
65 static WaitingLoop* GetInstanceN(void);
68 * Starts the waiting loop and Waits until the time is expired.
72 * @param[in] timeout The timeout period in milliseconds
73 * @exception E_SUCCESS The method is successful.
74 * @exception E_TIMEOUT The time is expired.
75 * @exception E_INVALID_STATE The waiting loop has already been waiting on a callback event. In order to wait again, you must quit the waiting loop.
76 * @remarks The timeout set to min(timeout, maximum), where the maximum is set using SetMaxTimeoutForWaiting().
77 * @see Notify(), SetMaxTimoutForWaiting()
79 result Wait(int timeout);
82 * Starts the waiting loop and Waits until the expiring condition occurs.
86 * @param[in] condition The expiring condition
87 * @exception E_SUCCESS The method is successful.
88 * @exception E_INVALID_STATE The waiting loop has already been waiting on a callback event. In order to wait again, you must quit the waiting loop.
89 * @remarks In order to use this method correctly, you have to implement a class inheriting from %IWaitingLoopCondition.
91 result Wait(IWaitingLoopCondition& condition);
94 * Starts the waiting loop and Waits until either the expiring condition occurs or the time is expired.
98 * @param[in] timeout The timeout period in milliseconds
99 * @param[in] condition The expiring condition
100 * @exception E_TIMEOUT The time is expired.
101 * @exception E_INVALID_STATE The waiting loop is waiting on a thread. In order to wait again, you must quit the waiting loop.
102 * @remarks If the timeout is over the maximum, the expired time goes together with the maximum timeout. In order to use this method correctly, you have to implement a class inheriting from %IWaitingLoopCondition interface
104 result Wait(int timeout, IWaitingLoopCondition& condition);
107 * Notify the waiting thread that the related callback has completed the job.
111 * @remarks This method is recommended to use when the waiting condition is not explicitly specified with Wait().
116 * Called when the timer is expired.
120 * @param[in] timer The expired timer instance
122 virtual void OnTimerExpired(Timer& timer);
125 * This default constructor is intentionally declared as private to implement the %Singleton semantic.
129 * @return A boolean value
131 bool IsSameThread(void);
134 * Sets the maximum timeout for waiting.
138 * @param[in] timeout The timeout period in milliseconds
140 * @remarks If the timeout is considered as a small number, it will be replaced with the specified number provided by platform.
142 void SetMaxTimeoutForWaiting(int timeout);
146 // This default constructor is intentionally declared as private to implement the %Singleton semantic.
150 _WaitingLoopImpl(void);
153 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
157 _WaitingLoopImpl(const _WaitingLoopImpl& rhs);
160 // The implementation of this copy assignment operator is intentionally blank and delcared as private to prohibit copying of objects.
164 _WaitingLoopImpl& operator =(const _WaitingLoopImpl& rhs);
167 // Constructs the instance of this class.
171 // @return An error code
172 // @exception E_SUCCESS The method is successful.
174 result Construct(void);
181 WAIT_TIMEOUT_CONDITION
190 Tizen::Base::Runtime::Timer* __pTimer;
193 Tizen::Base::Runtime::ThreadType __threadType;
194 GMainContext* __pGmainContext;
196 WaitStatus __waitStatus;
197 IWaitingLoopCondition* __pWaitingLoopCondition;
198 int __timerCalledCount;
201 }; // _WaitingLoopImpl
203 } } } // Tizen::Base::Runtime
205 #endif // _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_