b8f44a483b7e441fbf78952baa06120e3bae97bf
[platform/framework/native/appfw.git] / inc / FBaseRtWaitingLoop.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /*
18  * @file        FBaseRtWaitingLoop.h
19  * @brief       This is the header file for the %WaitingLoop class.
20  *
21  * This file contains the declarations of the %WaitingLoop class.
22  */
23
24 #ifndef _FBASE_RT_WAITING_LOOP_H_
25 #define _FBASE_RT_WAITING_LOOP_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseRtIWaitingLoopCondition.h>
29
30 namespace Tizen { namespace Base { namespace Runtime
31 {
32
33 class IWaitingLoopCondition;
34 /*
35  * @class WaitingLoop
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 don't use this class for commercial applications
37  * @since 2.0
38  *
39  * @final This class is not intended for extension.
40  */
41 class _OSP_EXPORT_ WaitingLoop
42         : public Tizen::Base::Object
43 {
44 public:
45         /*
46          * Gets the WaitingLoop instance.
47          *
48          * @since 2.0
49          *
50          * @return      A pointer to the WaitingLoop instance, @n
51          *                              else @c null if it fails   
52          * @remarks Once the WaitingLoop instance has been created, you must not use the instance between threads. Especially, the methods for waiting should be called on the thread you get the instance at first time.
53          */
54         static WaitingLoop* GetInstance(void);
55
56         /*
57          * Starts the waiting loop and waits until the time is expired.
58          *
59          * @since 2.0
60          *
61          * @param[in] timeout   The timeout period in milliseconds  
62          * @exception E_SUCCESS    The method is successful.
63          * @exception E_TIMEOUT    The time is expired.
64          * @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.
65          * @remarks The timeout set to min(timeout, maximum), where the maximum is set using SetMaxTimeoutForWaiting().
66          * @see Notify()
67          * @see SetMaxTimoutForWaiting()
68          */
69         result Wait(int timeout);
70
71         /*
72          * Starts the waiting loop and waits until the specified condition is met.
73          *
74          * @since 2.0
75          *
76          * @param[in] condition The expiring condition  
77          * @exception E_SUCCESS    The method is successful.
78          * @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.
79          * @remarks In order to use this method correctly, you have to implement a class inheriting from %IWaitingLoopCondition. 
80          */
81         result Wait(IWaitingLoopCondition& condition);
82
83         /*
84          * Starts the waiting loop and waits until either the expiring condition occurs or the time is expired.
85          *
86          * @since 2.0
87          *
88          * @param[in] timeout   The timeout period in milliseconds  
89          * @param[in] condition The expiring condition  
90          * @exception E_TIMEOUT    The time is expired.
91          * @exception E_INVALID_STATE    The waiting loop is waiting on a thread. In order to wait again, you must quit the waiting loop.
92          * @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
93          */
94         result Wait(int timeout, IWaitingLoopCondition& condition);
95
96         /*
97          * Notify the waiting thread that the related callback has completed the job.
98          *
99          * @since 2.0
100          *
101          * @remarks This method is recommended to use when the waiting condition is not explicitly specified with Wait().
102          */
103         void Notify(void);
104
105         /*
106          * Sets the maximum timeout for waiting.
107          *
108          * @since 2.0
109          *
110          * @param[in] timeout    The timeout period in milliseconds
111          *                              else @c false
112          * @remarks If the timeout is considered as a small number, it will be replaced with the specified number provided by platform.
113          */
114         static void SetMaxTimeoutForWaiting(int timeout);
115
116 private:
117         //
118         // This default constructor is intentionally declared as private to implement the %Singleton semantic.
119         //
120         // @since 2.0
121         //
122         WaitingLoop(void);
123
124         //
125         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
126         //
127         // @since 2.0
128         //
129         WaitingLoop(const WaitingLoop& rhs);
130
131         //
132         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
133         //
134         // @since 2.0
135         //
136         WaitingLoop& operator =(const WaitingLoop& rhs);
137
138         //
139         // This destructor is intentionally declared as private to implement the %Singleton semantic.
140         //
141         // @since 2.0
142         //
143         virtual ~WaitingLoop(void);
144
145         friend class _WaitingLoopImpl;
146         class _WaitingLoopImpl* __pWaitingLoopImpl;
147 }; // WaitingLoop
148
149 } } } // Tizen::Base::Runtime
150
151 #endif // _FBASE_RT_WAITING_LOOP_H_