Added SingletonService, removed Singleton APIs from Adaptor & removed Application...
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / singleton-service.h
1 #ifndef __DALI_SINGELTON_SERVICE_H__
2 #define __DALI_SINGELTON_SERVICE_H__
3
4 /*
5  * Copyright (c) 2014 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 DALI_IMPORT_API
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 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    * @brief Retrieves a handle to the SingletonService.
56    *
57    * @return A handle to the SingletonService if it is available. This will be an empty handle if
58    *         the service is not available.
59    */
60   static SingletonService Get();
61
62   /**
63    * @brief Destructor
64    *
65    * This is non-virtual since derived Handle types must not contain data or virtual methods.
66    */
67   ~SingletonService();
68
69   /**
70    * @brief Registers the singleton of Dali handle with its type info.
71    *
72    * The singleton will be kept alive for the life time of the service.
73    *
74    * @note This is not intended for application developers.
75    * @param[in] info The type info of the Dali handle generated by the compiler.
76    * @param[in] singleton The Dali handle to be registered
77    */
78   void Register( const std::type_info& info, BaseHandle singleton );
79
80   /**
81    * @brief Gets the singleton for the given type.
82    *
83    * @note This is not intended for application developers.
84    * @param[in] info The type info of the given type.
85    * @return the Dali handle if it is registered as a singleton or an uninitialized handle.
86    */
87   BaseHandle GetSingleton( const std::type_info& info ) const;
88
89 public: // Not intended for application developers
90
91   /**
92    * @brief This constructor is used by SingletonService::Get().
93    * @param[in] singletonService A pointer to the internal singleton-service object.
94    */
95   SingletonService( Internal::Adaptor::SingletonService* singletonService );
96 };
97
98 } // namespace Dali
99
100 #endif // __DALI_SINGELTON_SERVICE_H__