[SRUK] Initial copy from Tizen 2.2 version
[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 Flora License, Version 1.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://floralicense.org/license/
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 <dali/internal/event/common/thread-local-storage.h>
19
20 // EXTERNAL INCLUDES
21 #include <boost/thread/tss.hpp>
22
23 // INTERNAL INCLUDES
24 #include <dali/internal/common/core-impl.h>
25 #include <dali/internal/update/manager/update-manager.h>
26 #include <dali/internal/render/common/render-manager.h>
27 #include <dali/integration-api/platform-abstraction.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/math/vector2.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace
38 {
39 boost::thread_specific_ptr<ThreadLocalStorage> threadLocal;
40 }
41
42 ThreadLocalStorage::ThreadLocalStorage(Core* core)
43 :mCore(core)
44 {
45   DALI_ASSERT_ALWAYS( threadLocal.get() == NULL && "Cannot create more than one ThreadLocalStorage object" );
46
47   // reset is used to store a new value associated with this thread
48   threadLocal.reset(this);
49
50 }
51
52 ThreadLocalStorage::~ThreadLocalStorage()
53 {
54 }
55
56 void ThreadLocalStorage::Remove()
57 {
58   threadLocal.reset();
59 }
60
61 ThreadLocalStorage& ThreadLocalStorage::Get()
62 {
63   ThreadLocalStorage* tls = threadLocal.get();
64
65   DALI_ASSERT_ALWAYS(tls);
66
67   return *tls;
68 }
69
70 bool ThreadLocalStorage::Created()
71 {
72   // see if the TLS has been set yet
73   return (threadLocal.get() != NULL);
74 }
75
76 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
77 {
78   return mCore->GetPlatform();
79 }
80
81 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
82 {
83   return mCore->GetUpdateManager();
84 }
85
86 NotificationManager& ThreadLocalStorage::GetNotificationManager()
87 {
88   return mCore->GetNotificationManager();
89 }
90
91 ResourceManager& ThreadLocalStorage::GetResourceManager()
92 {
93   return mCore->GetResourceManager();
94 }
95
96 ResourceClient& ThreadLocalStorage::GetResourceClient()
97 {
98   return mCore->GetResourceClient();
99 }
100
101 ImageFactory& ThreadLocalStorage::GetImageFactory()
102 {
103   return mCore->GetImageFactory();
104 }
105
106 ModelFactory& ThreadLocalStorage::GetModelFactory()
107 {
108   return mCore->GetModelFactory();
109 }
110
111 FontFactory& ThreadLocalStorage::GetFontFactory()
112 {
113   return mCore->GetFontFactory();
114 }
115
116 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
117 {
118   return mCore->GetShaderFactory();
119 }
120
121 StagePtr ThreadLocalStorage::GetCurrentStage()
122 {
123   return mCore->GetCurrentStage();
124 }
125
126 EventToUpdate& ThreadLocalStorage::GetEventToUpdate()
127 {
128   return GetUpdateManager().GetEventToUpdate();
129 }
130
131 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
132 {
133   return mCore->GetGestureEventProcessor();
134 }
135
136 } // namespace Internal
137
138 } // namespace Dali