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 FBaseRtWaitingLoop.h
19 * @brief This is the header file for the %WaitingLoop class.
21 * This file contains the declarations of the %WaitingLoop class.
24 #ifndef _FBASE_RT_WAITING_LOOP_H_
25 #define _FBASE_RT_WAITING_LOOP_H_
27 #include <FBaseObject.h>
28 #include <FBaseRtIWaitingLoopCondition.h>
30 namespace Tizen { namespace Base { namespace Runtime
33 class IWaitingLoopCondition;
36 * @brief This class allows developers to make the current thread wait for callback events. This class should be used only for test codes and not for commercial applications.
39 * @final This class is not intended for extension.
41 class _OSP_EXPORT_ WaitingLoop
42 : public Tizen::Base::Object
46 * Gets a pointer to the %WaitingLoop instance.
50 * @return A pointer to a WaitingLoop instance, @n
51 * else @c null if it fails
52 * @remarks Once the WaitingLoop instance has been created, the instance between the threads must not be used. @n
53 * Especially, the methods that are waiting should be called on the thread where the instance is obtained for the first time.
55 static WaitingLoop* GetInstance(void);
58 * Starts the waiting loop and waits until the time is expired.
62 * @param[in] timeout The timeout period in milliseconds
63 * @exception E_SUCCESS The method is successful.
64 * @exception E_TIMEOUT The time has expired.
65 * @exception E_INVALID_STATE The waiting loop has already been waiting on a callback event. @n
66 * In order to wait again, quit the waiting loop.
67 * @remarks The timeout is set to min(timeout, maximum), where the maximum is set using SetMaxTimeoutForWaiting().
70 result Wait(int timeout);
73 * Starts the waiting loop and waits until the specified condition is met.
77 * @param[in] condition The expiring condition
78 * @exception E_SUCCESS The method is successful.
79 * @exception E_INVALID_STATE The waiting loop has already been waiting on a callback event. @n
80 * In order to wait again, quit the waiting loop.
81 * @remarks In order to use this method correctly, you have to implement a class inheriting from IWaitingLoopCondition.
83 result Wait(IWaitingLoopCondition& condition);
86 * Starts the waiting loop and waits until either the expiring condition occurs or the time expires.
90 * @param[in] timeout The timeout period in milliseconds
91 * @param[in] condition The expiring condition
92 * @exception E_TIMEOUT The time has expired.
93 * @exception E_INVALID_STATE The waiting loop is waiting on a thread. @n
94 * In order to wait again, quit the waiting loop.
95 * @remarks If the timeout has crossed the maximum value, the expired time goes along with the maximum timeout. @n
96 * In order to use this method correctly, implement a class inheriting from the IWaitingLoopCondition interface
98 result Wait(int timeout, IWaitingLoopCondition& condition);
101 * Notifies the waiting thread that the related callback has completed the job.
105 * @remarks This method is recommended when the waiting condition is not explicitly specified by Wait().
110 * Sets the maximum timeout for waiting.
114 * @param[in] timeout The timeout period in milliseconds
116 * @remarks If the timeout is considered as a small number, it is replaced with the specified number provided by the platform.
118 static void SetMaxTimeoutForWaiting(int timeout);
122 // This default constructor is intentionally declared as private to implement the %Singleton semantic.
129 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
133 WaitingLoop(const WaitingLoop& rhs);
136 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
140 WaitingLoop& operator =(const WaitingLoop& rhs);
143 // This destructor is intentionally declared as private to implement the %Singleton semantic.
147 virtual ~WaitingLoop(void);
149 friend class _WaitingLoopImpl;
150 class _WaitingLoopImpl* __pWaitingLoopImpl;
153 } } } // Tizen::Base::Runtime
155 #endif // _FBASE_RT_WAITING_LOOP_H_