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