[dali_1.9.1] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / common / singleton-service.h
1 #ifndef DALI_SINGELTON_SERVICE_H
2 #define DALI_SINGELTON_SERVICE_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <typeinfo>
23 #include <dali/public-api/object/base-handle.h>
24
25 namespace Dali
26 {
27
28 namespace Internal DALI_INTERNAL
29 {
30 class ThreadLocalStorage;
31 }
32
33 /**
34  * @brief Allows the registration of a class as a singleton
35  *
36  * @note This class is created by the Application class and is destroyed when the Application class is destroyed.
37  *
38  * @see Application
39  */
40 class DALI_CORE_API SingletonService : public BaseHandle
41 {
42 public:
43
44   /**
45    * @brief Create an uninitialized handle.
46    *
47    * This can be initialized by calling SingletonService::Get().
48    */
49   SingletonService();
50
51   /**
52    * @brief Retrieves a handle to the SingletonService.
53    *
54    * @return A handle to the SingletonService if it is available. This will be an empty handle if
55    *         the service is not available.
56    */
57   static SingletonService Get();
58
59   /**
60    * @brief Destructor
61    *
62    * This is non-virtual since derived Handle types must not contain data or virtual methods.
63    */
64   ~SingletonService();
65
66   /**
67    * @brief Registers the singleton of Dali handle with its type info.
68    *
69    * The singleton will be kept alive for the lifetime of the service.
70    *
71    * @note This is not intended for application developers.
72    * @param[in] info The type info of the Dali handle generated by the compiler.
73    * @param[in] singleton The Dali handle to be registered
74    */
75   void Register( const std::type_info& info, BaseHandle singleton );
76
77   /**
78    * @brief Unregisters all singletons.
79    *
80    * @note This is not intended for application developers.
81    */
82   void UnregisterAll();
83
84   /**
85    * @brief Gets the singleton for the given type.
86    *
87    * @note This is not intended for application developers.
88    * @param[in] info The type info of the given type.
89    * @return the Dali handle if it is registered as a singleton or an uninitialized handle.
90    */
91   BaseHandle GetSingleton( const std::type_info& info ) const;
92
93 public: // Not intended for application developers
94
95   /**
96    * @brief This constructor is used by SingletonService::Get().
97    * @param[in] singletonService A pointer to the internal singleton-service object.
98    */
99   explicit DALI_INTERNAL SingletonService( Internal::ThreadLocalStorage* singletonService );
100 };
101
102 } // namespace Dali
103
104 #endif // DALI_SINGELTON_SERVICE_H