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