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_WaitingLoopImpl.h
20 * @brief This is the header file for the %_WaitingLoopImpl class.
22 * This file contains the declarations of the %_WaitingLoopImpl class.
25 #ifndef _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_
26 #define _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_
29 #include <FBaseObject.h>
30 #include <FBaseRtThread.h>
31 #include <FBaseRtTimer.h>
32 #include <FBaseRtITimerEventListener.h>
34 namespace Tizen { namespace Base { namespace Runtime
38 class IWaitingLoopCondition;
40 * @class _WaitingLoopImpl
41 * @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
44 * @final This class is not intended for extension.
46 class _OSP_EXPORT_ _WaitingLoopImpl
47 : public Tizen::Base::Object
48 , public Tizen::Base::Runtime::ITimerEventListener
52 * This is the destructor for this class.
56 virtual ~_WaitingLoopImpl(void);
59 * Gets the WaitingLoop instance.
63 * @return A pointer to the WaitingLoop instance, @n
64 * else @c null if it fails
66 static WaitingLoop* GetInstanceN(void);
69 * Starts the waiting loop and Waits until the time is expired.
73 * @param[in] timeout The timeout period in milliseconds
74 * @exception E_SUCCESS The method is successful.
75 * @exception E_TIMEOUT The time is expired.
76 * @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.
77 * @remarks The timeout set to min(timeout, maximum), where the maximum is set using SetMaxTimeoutForWaiting().
78 * @see Notify(), SetMaxTimoutForWaiting()
80 result Wait(int timeout);
83 * Starts the waiting loop and Waits until the expiring condition occurs.
87 * @param[in] condition The expiring condition
88 * @exception E_SUCCESS The method is successful.
89 * @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.
90 * @remarks In order to use this method correctly, you have to implement a class inheriting from %IWaitingLoopCondition.
92 result Wait(IWaitingLoopCondition& condition);
95 * Starts the waiting loop and Waits until either the expiring condition occurs or the time is expired.
99 * @param[in] timeout The timeout period in milliseconds
100 * @param[in] condition The expiring condition
101 * @exception E_TIMEOUT The time is expired.
102 * @exception E_INVALID_STATE The waiting loop is waiting on a thread. In order to wait again, you must quit the waiting loop.
103 * @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
105 result Wait(int timeout, IWaitingLoopCondition& condition);
108 * Notify the waiting thread that the related callback has completed the job.
112 * @remarks This method is recommended to use when the waiting condition is not explicitly specified with Wait().
117 * Called when the timer is expired.
121 * @param[in] timer The expired timer instance
123 virtual void OnTimerExpired(Timer& timer);
126 * This default constructor is intentionally declared as private to implement the %Singleton semantic.
130 * @return A boolean value
132 bool IsSameThread(void);
135 * Sets the maximum timeout for waiting.
139 * @param[in] timeout The timeout period in milliseconds
141 * @remarks If the timeout is considered as a small number, it will be replaced with the specified number provided by platform.
143 void SetMaxTimeoutForWaiting(int timeout);
147 // This default constructor is intentionally declared as private to implement the %Singleton semantic.
151 _WaitingLoopImpl(void);
154 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
158 _WaitingLoopImpl(const _WaitingLoopImpl& rhs);
161 // The implementation of this copy assignment operator is intentionally blank and delcared as private to prohibit copying of objects.
165 _WaitingLoopImpl& operator =(const _WaitingLoopImpl& rhs);
168 // Constructs the instance of this class.
172 // @return An error code
173 // @exception E_SUCCESS The method is successful.
175 result Construct(void);
182 WAIT_TIMEOUT_CONDITION
191 Tizen::Base::Runtime::Timer* __pTimer;
194 Tizen::Base::Runtime::ThreadType __threadType;
195 GMainContext* __pGmainContext;
197 WaitStatus __waitStatus;
198 IWaitingLoopCondition* __pWaitingLoopCondition;
199 int __timerCalledCount;
202 }; // _WaitingLoopImpl
204 } } } // Tizen::Base::Runtime
206 #endif // _FBASE_RT_INTERNAL_WAITING_LOOP_IMPL_H_