Changed dynamics variable and UTC tests to use pkgconfig
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
1 /*
2  * Copyright (c) 2014 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 // CLASS HEADER
19 #include <dali/internal/event/common/thread-local-storage.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/core-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace
32 {
33 __thread ThreadLocalStorage* threadLocal = NULL;
34 }
35
36 ThreadLocalStorage::ThreadLocalStorage(Core* core)
37 : mCore( core )
38 #ifdef DALI_DYNAMICS_SUPPORT
39 , mDynamicsWorldInstance( NULL )
40 #endif
41 {
42   DALI_ASSERT_ALWAYS( threadLocal == NULL && "Cannot create more than one ThreadLocalStorage object" );
43
44   // reset is used to store a new value associated with this thread
45   threadLocal = this;
46 }
47
48 ThreadLocalStorage::~ThreadLocalStorage()
49 {
50 }
51
52 void ThreadLocalStorage::Remove()
53 {
54 #ifdef DALI_DYNAMICS_SUPPORT
55   if( mDynamicsWorldInstance )
56   {
57     mDynamicsWorldInstance.Reset();
58   }
59 #endif
60   threadLocal = NULL;
61 }
62
63 ThreadLocalStorage& ThreadLocalStorage::Get()
64 {
65   DALI_ASSERT_ALWAYS(threadLocal);
66
67   return *threadLocal;
68 }
69
70 bool ThreadLocalStorage::Created()
71 {
72   // see if the TLS has been set yet
73   return (threadLocal != NULL);
74 }
75
76 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
77 {
78   return threadLocal;
79 }
80
81 #ifdef DALI_DYNAMICS_SUPPORT
82 Dali::Internal::DynamicsWorldPtr ThreadLocalStorage::GetDynamicsWorldInstance()
83 {
84   if( !mDynamicsWorldInstance )
85   {
86     // Create the instance if it doesn't exist.
87     mDynamicsWorldInstance = DynamicsWorld::New();
88   }
89   return mDynamicsWorldInstance;
90 }
91 #endif
92
93 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
94 {
95   return mCore->GetPlatform();
96 }
97
98 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
99 {
100   return mCore->GetUpdateManager();
101 }
102
103 NotificationManager& ThreadLocalStorage::GetNotificationManager()
104 {
105   return mCore->GetNotificationManager();
106 }
107
108 ResourceManager& ThreadLocalStorage::GetResourceManager()
109 {
110   return mCore->GetResourceManager();
111 }
112
113 ResourceClient& ThreadLocalStorage::GetResourceClient()
114 {
115   return mCore->GetResourceClient();
116 }
117
118 ImageFactory& ThreadLocalStorage::GetImageFactory()
119 {
120   return mCore->GetImageFactory();
121 }
122
123 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
124 {
125   return mCore->GetShaderFactory();
126 }
127
128 StagePtr ThreadLocalStorage::GetCurrentStage()
129 {
130   return mCore->GetCurrentStage();
131 }
132
133 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
134 {
135   return mCore->GetGestureEventProcessor();
136 }
137
138 RelayoutController& ThreadLocalStorage::GetRelayoutController()
139 {
140   return mCore->GetRelayoutController();
141 }
142
143 } // namespace Internal
144
145 } // namespace Dali