Changed Atlas manager to use Dali::Texture instead of Dali::Atlas
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-event-thread-callback.cpp
1 /*
2  * Copyright (c) 2015 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 // CLASS HEADER
18 #include "toolkit-event-thread-callback.h"
19
20 // EXTERNAL INCLUDES
21 #include <cstddef>
22 #include <semaphore.h>
23 #include <math.h>
24 #include <climits>
25
26 namespace Dali
27 {
28
29 namespace
30 {
31 EventThreadCallback* gEventThreadCallback = NULL;
32 }
33
34 struct EventThreadCallback::Impl
35 {
36   CallbackBase* callback;
37   unsigned int triggeredCount;
38   unsigned int expectedCount;
39   sem_t mySemaphore;
40 };
41
42 EventThreadCallback::EventThreadCallback( CallbackBase* callback )
43 : mImpl( new Impl() )
44 {
45   mImpl->callback = callback;
46   mImpl->triggeredCount = 0u;
47   mImpl->expectedCount = UINT_MAX;
48   sem_init( &(mImpl->mySemaphore), 0, 0 );
49   gEventThreadCallback = this;
50 }
51
52 EventThreadCallback::~EventThreadCallback()
53 {
54   delete mImpl;
55 }
56
57 void EventThreadCallback::Trigger()
58 {
59   mImpl->triggeredCount++;
60   if(  mImpl->triggeredCount >= mImpl->expectedCount )
61   {
62     sem_post( &(mImpl->mySemaphore) );
63   }
64 }
65
66 void EventThreadCallback::WaitingForTrigger(unsigned int count)
67 {
68   if(  mImpl->triggeredCount >= count )
69   {
70     return;
71   }
72   mImpl->expectedCount = count;
73   sem_wait( &(mImpl->mySemaphore) );
74 }
75
76 CallbackBase* EventThreadCallback::GetCallback()
77 {
78   return mImpl->callback;
79 }
80
81 EventThreadCallback* EventThreadCallback::Get()
82 {
83   return gEventThreadCallback;
84 }
85
86 }