9d023155c908359e5e260f2848b8ea2e370221fb
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRtWaitingLoop.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FBaseRtWaitingLoop.cpp
20  * @brief       This is the implementation for the %WaitingLoop class.
21  *
22  */
23
24 #include <FBaseRtWaitingLoop.h>
25 #include "FBaseRt_WaitingLoopImpl.h"
26
27 namespace Tizen { namespace Base { namespace Runtime
28 {
29
30 WaitingLoop::WaitingLoop(void)
31         : __pWaitingLoopImpl(null)
32 {
33 }
34
35
36 WaitingLoop::~WaitingLoop(void)
37 {
38         delete __pWaitingLoopImpl;
39 }
40
41 WaitingLoop* 
42 WaitingLoop::GetInstance(void)
43 {
44         static WaitingLoop* pWaitingLoop = null;
45         if (pWaitingLoop == null)
46         {
47                 pWaitingLoop = _WaitingLoopImpl::GetInstanceN();
48         }
49         else
50         {
51                 if (pWaitingLoop->__pWaitingLoopImpl->IsSameThread() == false)
52                 {
53                         pWaitingLoop->__pWaitingLoopImpl->Notify();
54                         delete pWaitingLoop;
55                         
56                         pWaitingLoop = _WaitingLoopImpl::GetInstanceN();        
57                 }
58         }
59
60         return pWaitingLoop;
61 }
62
63 result 
64 WaitingLoop::Wait(int timeout)
65 {
66         return __pWaitingLoopImpl->Wait(timeout);
67 }
68
69 result 
70 WaitingLoop::Wait(IWaitingLoopCondition& condition)
71 {
72         return __pWaitingLoopImpl->Wait(condition);
73 }
74
75 result 
76 WaitingLoop::Wait(int timeout, IWaitingLoopCondition& condition)
77 {
78         return __pWaitingLoopImpl->Wait(timeout, condition);
79 }
80
81 void 
82 WaitingLoop::Notify(void)
83 {
84         __pWaitingLoopImpl->Notify();
85 }
86
87 void 
88 WaitingLoop::SetMaxTimeoutForWaiting(int timeout)
89 {
90         WaitingLoop* pWaitingLoop = WaitingLoop::GetInstance();
91                 
92         if (pWaitingLoop != null)
93         {
94                 pWaitingLoop->__pWaitingLoopImpl->SetMaxTimeoutForWaiting(timeout);
95         }
96 }
97
98 }}} // Tizen::Base::Runtime