5156f459046c7060f9c980f9bba5587d93699ba2
[platform/core/uifw/dali-adaptor.git] / adaptors / devel-api / adaptor-framework / singleton-service.h
1 #ifndef __DALI_SINGELTON_SERVICE_H__
2 #define __DALI_SINGELTON_SERVICE_H__
3
4 /*
5  * Copyright (c) 2015 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 namespace Adaptor
31 {
32 class SingletonService;
33 }
34 }
35
36 /**
37  * @brief Allows the registration of a class as a singleton
38  *
39  * @note This class is created by the Application class and is destroyed when the Application class is destroyed.
40  *
41  * @see Application
42  */
43 class DALI_IMPORT_API SingletonService : public BaseHandle
44 {
45 public:
46
47   /**
48    * @brief Create an uninitialized handle.
49    *
50    * This can be initialized by calling SingletonService::Get().
51    */
52   SingletonService();
53
54   /**
55    * Create a SingletonService.
56    * This should only be called once by the Application class.
57    * @return A newly created SingletonService.
58    */
59   static Dali::SingletonService New();
60
61   /**
62    * @brief Retrieves a handle to the SingletonService.
63    *
64    * @return A handle to the SingletonService if it is available. This will be an empty handle if
65    *         the service is not available.
66    */
67   static SingletonService Get();
68
69   /**
70    * @brief Destructor
71    *
72    * This is non-virtual since derived Handle types must not contain data or virtual methods.
73    */
74   ~SingletonService();
75
76   /**
77    * @brief Registers the singleton of Dali handle with its type info.
78    *
79    * The singleton will be kept alive for the lifetime of the service.
80    *
81    * @note This is not intended for application developers.
82    * @param[in] info The type info of the Dali handle generated by the compiler.
83    * @param[in] singleton The Dali handle to be registered
84    */
85   void Register( const std::type_info& info, BaseHandle singleton );
86
87   /**
88    * @brief Unregisters all singletons.
89    *
90    * @note This is not intended for application developers.
91    */
92   void UnregisterAll();
93
94   /**
95    * @brief Gets the singleton for the given type.
96    *
97    * @note This is not intended for application developers.
98    * @param[in] info The type info of the given type.
99    * @return the Dali handle if it is registered as a singleton or an uninitialized handle.
100    */
101   BaseHandle GetSingleton( const std::type_info& info ) const;
102
103 public: // Not intended for application developers
104
105   /**
106    * @brief This constructor is used by SingletonService::Get().
107    * @param[in] singletonService A pointer to the internal singleton-service object.
108    */
109   explicit DALI_INTERNAL SingletonService( Internal::Adaptor::SingletonService* singletonService );
110 };
111
112 } // namespace Dali
113
114 #endif // __DALI_SINGELTON_SERVICE_H__