2 * Copyright (c) 2015 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>
29 // To be removed when 2.2 is no longer supported.
30 #ifndef TIZEN_2_2_COMPATIBILITY
31 #include <bundle_internal.h>
35 #include <dali/integration-api/debug.h>
38 #include <callback-manager.h>
52 /// Application Status Enum
68 } // Unnamed namespace
71 * Impl to hide EFL data members
73 struct Framework::Impl
78 : mAbortCallBack( NULL ),
79 mCallbackManager( NULL )
81 mEventCallback.create = AppCreate;
82 mEventCallback.terminate = AppTerminate;
83 mEventCallback.pause = AppPause;
84 mEventCallback.resume = AppResume;
85 #ifndef OVER_TIZEN_SDK_2_2
86 mEventCallback.service = AppService;
88 mEventCallback.low_memory = NULL;
89 mEventCallback.low_battery = NULL;
90 mEventCallback.device_orientation = AppDeviceRotated;
91 mEventCallback.language_changed = AppLanguageChanged;
92 mEventCallback.region_format_changed = NULL;
95 mEventCallback.app_control = AppControl;
97 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, data);
98 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, data);
99 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, data);
100 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, data);
101 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, data);
105 mCallbackManager = CallbackManager::New();
110 delete mAbortCallBack;
112 // we're quiting the main loop so
113 // mCallbackManager->RemoveAllCallBacks() does not need to be called
114 // to delete our abort handler
115 delete mCallbackManager;
120 CallbackBase* mAbortCallBack;
121 CallbackManager *mCallbackManager;
123 #ifndef OVER_TIZEN_SDK_2_2
124 app_event_callback_s mEventCallback;
126 ui_app_lifecycle_callback_s mEventCallback;
127 app_event_handler_h handlers[5];
131 * Called by AppCore on application creation.
133 static bool AppCreate(void *data)
135 return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);
139 * Called by AppCore when the application should terminate.
141 static void AppTerminate(void *data)
143 static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);
147 * Called by AppCore when the application is paused.
149 static void AppPause(void *data)
151 static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);
155 * Called by AppCore when the application is resumed.
157 static void AppResume(void *data)
159 static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);
162 static void ProcessBundle(Framework* framework, bundle *bundleData)
164 if(bundleData == NULL)
170 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
171 if(bundleName != NULL)
173 framework->SetBundleName(bundleName);
177 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
180 framework->SetBundleId(bundleId);
184 #ifndef OVER_TIZEN_SDK_2_2
186 * Called by AppCore when the application is launched from another module (e.g. homescreen).
187 * @param[in] b the bundle data which the launcher module sent
189 static void AppService(service_h service, void *data)
191 Framework* framework = static_cast<Framework*>(data);
193 if(framework == NULL)
197 bundle *bundleData = NULL;
199 service_to_bundle(service, &bundleData);
200 ProcessBundle(framework, bundleData);
202 framework->AppStatusHandler(APP_RESET, NULL);
205 static void AppLanguageChanged(void* user_data)
207 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
210 static void AppDeviceRotated(app_device_orientation_e orientation, void *user_data)
212 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
218 * Called by AppCore when the application is launched from another module (e.g. homescreen).
219 * @param[in] b the bundle data which the launcher module sent
221 static void AppControl(app_control_h app_control, void *data)
223 Framework* framework = static_cast<Framework*>(data);
224 if(framework == NULL)
228 bundle *bundleData = NULL;
230 app_control_to_bundle(app_control, &bundleData);
231 ProcessBundle(framework, bundleData);
233 framework->AppStatusHandler(APP_RESET, NULL);
234 framework->AppStatusHandler(APP_CONTROL, app_control);
237 static void AppLanguageChanged(app_event_info_h event_info, void *user_data)
239 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
242 static void AppDeviceRotated(app_event_info_h event_info, void *user_data)
244 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
247 static void AppRegionChanged(app_event_info_h event_info, void *user_data)
249 static_cast<Framework*>(user_data)->AppStatusHandler(APP_REGION_CHANGED, NULL);
252 static void AppBatteryLow(app_event_info_h event_info, void *user_data)
254 static_cast<Framework*>(user_data)->AppStatusHandler(APP_BATTERY_LOW, NULL);
257 static void AppMemoryLow(app_event_info_h event_info, void *user_data)
259 static_cast<Framework*>(user_data)->AppStatusHandler(APP_MEMORY_LOW, NULL);
266 Impl( const Impl& impl );
269 Impl& operator=( const Impl& impl );
272 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv )
273 : mObserver(observer),
280 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
284 #ifdef OVER_TIZEN_SDK_2_2
285 bool featureFlag = true;
286 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
288 if( featureFlag == false )
290 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
291 throw Dali::DaliException( "", "OpenGL ES 2.0 is not supported." );
296 mImpl = new Impl(this);
299 Framework::~Framework()
309 void Framework::Run()
313 #ifndef OVER_TIZEN_SDK_2_2
314 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
317 int ret = ui_app_main(*mArgc, *mArgv, &mImpl->mEventCallback, this);
318 if (ret != APP_ERROR_NONE)
320 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
327 void Framework::Quit()
329 #ifndef OVER_TIZEN_SDK_2_2
336 bool Framework::IsMainLoopRunning()
341 void Framework::AddAbortCallback( CallbackBase* callback )
343 mImpl->mAbortCallBack = callback;
346 std::string Framework::GetBundleName() const
351 void Framework::SetBundleName(const std::string& name)
356 std::string Framework::GetBundleId() const
361 void Framework::SetBundleId(const std::string& id)
366 void Framework::AbortCallback( )
368 // if an abort call back has been installed run it.
369 if (mImpl->mAbortCallBack)
371 CallbackBase::Execute( *mImpl->mAbortCallBack );
379 bool Framework::AppStatusHandler(int type, void *bundleData)
387 // Connect to abnormal exit signals
388 mAbortHandler.AbortOnSignal( SIGINT );
389 mAbortHandler.AbortOnSignal( SIGQUIT );
390 mAbortHandler.AbortOnSignal( SIGKILL );
391 mAbortHandler.AbortOnSignal( SIGTERM );
392 mAbortHandler.AbortOnSignal( SIGHUP );
406 mObserver.OnResume();
412 mObserver.OnTerminate();
424 mObserver.OnAppControl(bundleData);
428 case APP_LANGUAGE_CHANGE:
430 mObserver.OnLanguageChanged();
434 case APP_REGION_CHANGED:
436 mObserver.OnRegionChanged();
440 case APP_BATTERY_LOW:
442 mObserver.OnBatteryLow();
448 mObserver.OnMemoryLow();
459 } // namespace Adaptor
461 } // namespace Internal