(Automated Tests) Changes required after removal of time getters from PlatformAbstraction
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-singleton-service.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 #include "toolkit-singleton-service.h"
19
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/signals/dali-signal.h>
24
25 namespace Dali
26 {
27
28
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33
34 /**
35  * Stub for the SingletonService
36  */
37 class SingletonService : public Dali::BaseObject
38 {
39 public:
40   static Dali::SingletonService New();
41   static Dali::SingletonService Get();
42   void Register( const std::type_info& info, BaseHandle singleton );
43   void UnregisterAll();
44   BaseHandle GetSingleton( const std::type_info& info ) const;
45
46 private:
47   SingletonService();
48   virtual ~SingletonService();
49
50   // Undefined
51   SingletonService( const SingletonService& );
52   SingletonService& operator=( SingletonService& );
53
54 private:
55
56   typedef std::pair<std::string, BaseHandle> SingletonPair;
57   typedef std::map<std::string, BaseHandle>  SingletonContainer;
58   typedef SingletonContainer::const_iterator SingletonConstIter;
59
60   SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
61
62   static Dali::SingletonService mToolkitSingletonService;
63 };
64
65 Dali::SingletonService SingletonService::mToolkitSingletonService;
66
67 Dali::SingletonService SingletonService::New()
68 {
69   return Get();
70 }
71
72 Dali::SingletonService SingletonService::Get()
73 {
74   if( ! mToolkitSingletonService )
75   {
76     mToolkitSingletonService = Dali::SingletonService( new Dali::Internal::Adaptor::SingletonService );
77   }
78   return mToolkitSingletonService;
79 }
80
81 void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
82 {
83   if( singleton )
84   {
85     mSingletonContainer.insert( SingletonPair( info.name(), singleton ) );
86   }
87 }
88
89 void SingletonService::UnregisterAll()
90 {
91   mSingletonContainer.clear();
92 }
93
94 BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
95 {
96   BaseHandle object;
97
98   SingletonConstIter iter = mSingletonContainer.find(info.name());
99   if( iter != mSingletonContainer.end() )
100   {
101     object = ( *iter ).second;
102   }
103
104   return object;
105 }
106
107 SingletonService::SingletonService()
108 : mSingletonContainer()
109 {
110 }
111
112 SingletonService::~SingletonService()
113 {
114 }
115
116 } // namespace Adaptor
117 } // namespace Internal
118
119 ////////////////////////////////////////////////////////////////////////////////////////////////////
120
121 Internal::Adaptor::SingletonService& GetImplementation(Dali::SingletonService& player)
122 {
123   DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
124
125   BaseObject& handle = player.GetBaseObject();
126
127   return static_cast<Internal::Adaptor::SingletonService&>(handle);
128 }
129
130 const Internal::Adaptor::SingletonService& GetImplementation(const Dali::SingletonService& player)
131 {
132   DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
133
134   const BaseObject& handle = player.GetBaseObject();
135
136   return static_cast<const Internal::Adaptor::SingletonService&>(handle);
137 }
138
139 SingletonService::SingletonService()
140 {
141 }
142
143 SingletonService SingletonService::New()
144 {
145   return Internal::Adaptor::SingletonService::New();
146 }
147
148 SingletonService SingletonService::Get()
149 {
150   return Internal::Adaptor::SingletonService::Get();
151 }
152
153 SingletonService::~SingletonService()
154 {
155 }
156
157 void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
158 {
159   GetImplementation( *this ).Register( info, singleton );
160 }
161
162 void SingletonService::UnregisterAll()
163 {
164   GetImplementation( *this ).UnregisterAll();
165 }
166
167 BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
168 {
169   return GetImplementation( *this ).GetSingleton( info );
170 }
171
172 SingletonService::SingletonService( Internal::Adaptor::SingletonService* singletonService )
173 : BaseHandle( singletonService )
174 {
175 }
176
177 } // namespace Dali