ba435379a95d6fcd3662a95fffd2637b73ae5c9e
[platform/core/uifw/dali-adaptor.git] / adaptors / common / lifecycle-controller-impl.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 // CLASS HEADER
19 #include "lifecycle-controller-impl.h"
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <adaptor-impl.h>
24 #include <singleton-service-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace Adaptor
33 {
34
35 namespace
36 {
37
38 BaseHandle Create()
39 {
40   BaseHandle handle( LifecycleController::Get() );
41
42   if ( !handle && Adaptor::IsAvailable() )
43   {
44     Dali::SingletonService service( SingletonService::Get() );
45     if ( service )
46     {
47       Dali::LifecycleController lifecycleController = Dali::LifecycleController( new LifecycleController() );
48       service.Register( typeid( lifecycleController ), lifecycleController );
49       handle = lifecycleController;
50     }
51   }
52
53   return handle;
54 }
55 TypeRegistration LIFECYCLE_CONTROLLER_TYPE( typeid(Dali::LifecycleController), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
56
57 } // unnamed namespace
58
59 Dali::LifecycleController LifecycleController::Get()
60 {
61   Dali::LifecycleController lifecycleController;
62
63   Dali::SingletonService service( SingletonService::Get() );
64   if ( service )
65   {
66     // Check whether the singleton is already created
67     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::LifecycleController ) );
68     if(handle)
69     {
70       // If so, downcast the handle
71       lifecycleController = Dali::LifecycleController( dynamic_cast< LifecycleController* >( handle.GetObjectPtr() ) );
72     }
73     else
74     {
75       lifecycleController = Dali::LifecycleController( new LifecycleController() );
76       service.Register( typeid( lifecycleController ), lifecycleController );
77     }
78   }
79
80   return lifecycleController;
81 }
82
83 LifecycleController::LifecycleController()
84 {
85 }
86
87 LifecycleController::~LifecycleController()
88 {
89 }
90
91 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::InitSignal()
92 {
93   return mInitSignal;
94 }
95
96 void LifecycleController::EmitInitSignal()
97 {
98   if( !mInitSignal.Empty() )
99   {
100     mInitSignal.Emit();
101   }
102 }
103
104 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::TerminateSignal()
105 {
106   return mTerminateSignal;
107 }
108
109 void LifecycleController::EmitTerminateSignal()
110 {
111   if( !mTerminateSignal.Empty() )
112   {
113     mTerminateSignal.Emit();
114   }
115 }
116
117 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::PauseSignal()
118 {
119   return mPauseSignal;
120 }
121
122 void LifecycleController::EmitPauseSignal()
123 {
124   if( !mPauseSignal.Empty() )
125   {
126     mPauseSignal.Emit();
127   }
128 }
129
130 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::ResumeSignal()
131 {
132   return mResumeSignal;
133 }
134
135 void LifecycleController::EmitResumeSignal()
136 {
137   if( !mResumeSignal.Empty() )
138   {
139     mResumeSignal.Emit();
140   }
141 }
142
143 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::ResetSignal()
144 {
145   return mResetSignal;
146 }
147
148 void LifecycleController::EmitResetSignal()
149 {
150   if( !mResetSignal.Empty() )
151   {
152     mResetSignal.Emit();
153   }
154 }
155
156 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::ResizeSignal()
157 {
158   return mResizeSignal;
159 }
160
161 void LifecycleController::EmitResizeSignal()
162 {
163   if( !mResizeSignal.Empty() )
164   {
165     mResizeSignal.Emit();
166   }
167 }
168
169 Dali::LifecycleController::LifecycleSignalV2& LifecycleController::LanguageChangedSignal()
170 {
171   return mLanguageChangedSignal;
172 }
173
174 void LifecycleController::EmitLanguageChangedSignal()
175 {
176   if( !mLanguageChangedSignal.Empty() )
177   {
178     mLanguageChangedSignal.Emit();
179   }
180 }
181
182 void LifecycleController::OnInit( Dali::Application& app )
183 {
184   EmitInitSignal();
185 }
186
187 void LifecycleController::OnTerminate( Dali::Application& app )
188 {
189   EmitTerminateSignal();
190 }
191
192 void LifecycleController::OnPause( Dali::Application& app )
193 {
194   EmitPauseSignal();
195 }
196
197 void LifecycleController::OnResume( Dali::Application& app )
198 {
199   EmitResumeSignal();
200 }
201
202 void LifecycleController::OnReset( Dali::Application& app )
203 {
204   EmitResetSignal();
205 }
206
207 void LifecycleController::OnLanguageChanged( Dali::Application& app )
208 {
209   EmitLanguageChangedSignal();
210 }
211
212 void LifecycleController::OnResize( Dali::Application& app )
213 {
214   EmitResizeSignal();
215 }
216
217 } // namespace Adaptor
218
219 } // namespace Internal
220
221 } // namespace Dali