2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "framework.h"
26 #ifdef OVER_TIZEN_SDK_2_2
27 #include <system_info.h>
28 #include <app_control_internal.h>
31 #include <dali/integration-api/debug.h>
34 #include <callback-manager.h>
48 /// Application Status Enum
64 } // Unnamed namespace
67 * Impl to hide EFL data members
69 struct Framework::Impl
74 : mAbortCallBack( NULL ),
75 mCallbackManager( NULL )
77 mEventCallback.create = AppCreate;
78 mEventCallback.terminate = AppTerminate;
79 mEventCallback.pause = AppPause;
80 mEventCallback.resume = AppResume;
81 #ifndef OVER_TIZEN_SDK_2_2
82 mEventCallback.service = AppService;
84 mEventCallback.low_memory = NULL;
85 mEventCallback.low_battery = NULL;
86 mEventCallback.device_orientation = AppDeviceRotated;
87 mEventCallback.language_changed = AppLanguageChanged;
88 mEventCallback.region_format_changed = NULL;
91 mEventCallback.app_control = AppControl;
93 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, data);
94 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, data);
95 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, data);
96 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, data);
97 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, data);
101 mCallbackManager = CallbackManager::New();
106 delete mAbortCallBack;
108 // we're quiting the main loop so
109 // mCallbackManager->RemoveAllCallBacks() does not need to be called
110 // to delete our abort handler
111 delete mCallbackManager;
116 CallbackBase* mAbortCallBack;
117 CallbackManager *mCallbackManager;
119 #ifndef OVER_TIZEN_SDK_2_2
120 app_event_callback_s mEventCallback;
122 ui_app_lifecycle_callback_s mEventCallback;
123 app_event_handler_h handlers[5];
127 * Called by AppCore on application creation.
129 static bool AppCreate(void *data)
131 return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);
135 * Called by AppCore when the application should terminate.
137 static void AppTerminate(void *data)
139 static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);
143 * Called by AppCore when the application is paused.
145 static void AppPause(void *data)
147 static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);
151 * Called by AppCore when the application is resumed.
153 static void AppResume(void *data)
155 static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);
158 static void ProcessBundle(Framework* framework, bundle *bundleData)
160 if(bundleData == NULL)
166 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
167 if(bundleName != NULL)
169 framework->SetBundleName(bundleName);
173 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
176 framework->SetBundleId(bundleId);
180 #ifndef OVER_TIZEN_SDK_2_2
182 * Called by AppCore when the application is launched from another module (e.g. homescreen).
183 * @param[in] b the bundle data which the launcher module sent
185 static void AppService(service_h service, void *data)
187 Framework* framework = static_cast<Framework*>(data);
189 if(framework == NULL)
193 bundle *bundleData = NULL;
195 service_to_bundle(service, &bundleData);
196 ProcessBundle(framework, bundleData);
198 framework->AppStatusHandler(APP_RESET, NULL);
201 static void AppLanguageChanged(void* user_data)
203 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
206 static void AppDeviceRotated(app_device_orientation_e orientation, void *user_data)
208 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
214 * Called by AppCore when the application is launched from another module (e.g. homescreen).
215 * @param[in] b the bundle data which the launcher module sent
217 static void AppControl(app_control_h app_control, void *data)
219 Framework* framework = static_cast<Framework*>(data);
220 if(framework == NULL)
224 bundle *bundleData = NULL;
226 app_control_to_bundle(app_control, &bundleData);
227 ProcessBundle(framework, bundleData);
229 framework->AppStatusHandler(APP_RESET, NULL);
230 framework->AppStatusHandler(APP_CONTROL, app_control);
233 static void AppLanguageChanged(app_event_info_h event_info, void *user_data)
235 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
238 static void AppDeviceRotated(app_event_info_h event_info, void *user_data)
240 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
243 static void AppRegionChanged(app_event_info_h event_info, void *user_data)
245 static_cast<Framework*>(user_data)->AppStatusHandler(APP_REGION_CHANGED, NULL);
248 static void AppBatteryLow(app_event_info_h event_info, void *user_data)
250 static_cast<Framework*>(user_data)->AppStatusHandler(APP_BATTERY_LOW, NULL);
253 static void AppMemoryLow(app_event_info_h event_info, void *user_data)
255 static_cast<Framework*>(user_data)->AppStatusHandler(APP_MEMORY_LOW, NULL);
262 Impl( const Impl& impl );
265 Impl& operator=( const Impl& impl );
268 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv )
269 : mObserver(observer),
276 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
280 #ifdef OVER_TIZEN_SDK_2_2
281 bool featureFlag = true;
282 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
284 if( featureFlag == false )
286 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
287 throw Dali::DaliException( "", "OpenGL ES 2.0 is not supported." );
292 mImpl = new Impl(this);
295 Framework::~Framework()
305 void Framework::Run()
309 #ifndef OVER_TIZEN_SDK_2_2
310 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
313 int ret = ui_app_main(*mArgc, *mArgv, &mImpl->mEventCallback, this);
314 if (ret != APP_ERROR_NONE)
316 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
323 void Framework::Quit()
328 bool Framework::IsMainLoopRunning()
333 void Framework::AddAbortCallback( CallbackBase* callback )
335 mImpl->mAbortCallBack = callback;
338 std::string Framework::GetBundleName() const
343 void Framework::SetBundleName(const std::string& name)
348 std::string Framework::GetBundleId() const
353 void Framework::SetBundleId(const std::string& id)
358 void Framework::AbortCallback( )
360 // if an abort call back has been installed run it.
361 if (mImpl->mAbortCallBack)
363 CallbackBase::Execute( *mImpl->mAbortCallBack );
371 bool Framework::AppStatusHandler(int type, void *bundleData)
379 // Connect to abnormal exit signals
380 mAbortHandler.AbortOnSignal( SIGINT );
381 mAbortHandler.AbortOnSignal( SIGQUIT );
382 mAbortHandler.AbortOnSignal( SIGKILL );
383 mAbortHandler.AbortOnSignal( SIGTERM );
384 mAbortHandler.AbortOnSignal( SIGHUP );
398 mObserver.OnResume();
404 mObserver.OnTerminate();
416 mObserver.OnAppControl(bundleData);
420 case APP_LANGUAGE_CHANGE:
422 mObserver.OnLanguageChanged();
426 case APP_REGION_CHANGED:
428 mObserver.OnRegionChanged();
432 case APP_BATTERY_LOW:
434 mObserver.OnBatteryLow();
440 mObserver.OnMemoryLow();
451 } // namespace Adaptor
453 } // namespace Internal