Reduced the amount of AccessibilityAdaptor copy 'n' paste
[platform/core/uifw/dali-adaptor.git] / adaptors / ubuntu / accessibility-adaptor-impl-ubuntu.cpp
1 /*
2  * Copyright (c) 2015 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 // CLASS HEADER
19 #include "accessibility-adaptor-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 // INTERNAL INCLUDES
25 #include <singleton-service-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 namespace // unnamed namespace
37 {
38
39 BaseHandle Create()
40 {
41   BaseHandle handle( AccessibilityAdaptor::Get() );
42
43   if ( !handle )
44   {
45     Dali::SingletonService service( SingletonService::Get() );
46     if ( service )
47     {
48       Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
49       service.Register( typeid( adaptor ), adaptor );
50       handle = adaptor;
51     }
52   }
53
54   return handle;
55 }
56
57 TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
58
59 } // unnamed namespace
60
61 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
62 {
63   Dali::AccessibilityAdaptor adaptor;
64
65   Dali::SingletonService service( SingletonService::Get() );
66   if ( service )
67   {
68     // Check whether the singleton is already created
69     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
70     if(handle)
71     {
72       // If so, downcast the handle
73       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
74     }
75   }
76
77   return adaptor;
78 }
79
80 void AccessibilityAdaptor::OnDestroy()
81 {
82   // Nothing to do here
83 }
84
85 } // namespace Adaptor
86
87 } // namespace Internal
88
89 } // namespace Dali