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 #ifndef TIZEN_SDK_2_2_COMPATIBILITY
27 #include <system_info.h>
28 #include <app_control_internal.h>
29 #include <bundle_internal.h>
32 #include <dali/integration-api/debug.h>
35 #include <callback-manager.h>
49 /// Application Status Enum
65 } // Unnamed namespace
68 * Impl to hide EFL data members
70 struct Framework::Impl
75 : mAbortCallBack( NULL ),
76 mCallbackManager( NULL )
78 mEventCallback.create = AppCreate;
79 mEventCallback.terminate = AppTerminate;
80 mEventCallback.pause = AppPause;
81 mEventCallback.resume = AppResume;
83 #ifdef TIZEN_SDK_2_2_COMPATIBILITY
84 mEventCallback.service = AppService;
86 mEventCallback.low_memory = NULL;
87 mEventCallback.low_battery = NULL;
88 mEventCallback.device_orientation = AppDeviceRotated;
89 mEventCallback.language_changed = AppLanguageChanged;
90 mEventCallback.region_format_changed = NULL;
93 mEventCallback.app_control = AppControl;
95 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, data);
96 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, data);
97 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, data);
98 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, data);
99 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, data);
102 mCallbackManager = CallbackManager::New();
107 delete mAbortCallBack;
109 // we're quiting the main loop so
110 // mCallbackManager->RemoveAllCallBacks() does not need to be called
111 // to delete our abort handler
112 delete mCallbackManager;
117 CallbackBase* mAbortCallBack;
118 CallbackManager *mCallbackManager;
120 #ifdef TIZEN_SDK_2_2_COMPATIBILITY
121 app_event_callback_s mEventCallback;
123 ui_app_lifecycle_callback_s mEventCallback;
124 app_event_handler_h handlers[5];
128 * Called by AppCore on application creation.
130 static bool AppCreate(void *data)
132 return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);
136 * Called by AppCore when the application should terminate.
138 static void AppTerminate(void *data)
140 static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);
144 * Called by AppCore when the application is paused.
146 static void AppPause(void *data)
148 static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);
152 * Called by AppCore when the application is resumed.
154 static void AppResume(void *data)
156 static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);
159 static void ProcessBundle(Framework* framework, bundle *bundleData)
161 if(bundleData == NULL)
167 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
168 if(bundleName != NULL)
170 framework->SetBundleName(bundleName);
174 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
177 framework->SetBundleId(bundleId);
181 #ifdef TIZEN_SDK_2_2_COMPATIBILITY
183 * Called by AppCore when the application is launched from another module (e.g. homescreen).
184 * @param[in] b the bundle data which the launcher module sent
186 static void AppService(service_h service, void *data)
188 Framework* framework = static_cast<Framework*>(data);
190 if(framework == NULL)
194 bundle *bundleData = NULL;
196 service_to_bundle(service, &bundleData);
197 ProcessBundle(framework, bundleData);
199 framework->AppStatusHandler(APP_RESET, NULL);
202 static void AppLanguageChanged(void* user_data)
204 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
207 static void AppDeviceRotated(app_device_orientation_e orientation, void *user_data)
209 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
213 * Called by AppCore when the application is launched from another module (e.g. homescreen).
214 * @param[in] b the bundle data which the launcher module sent
216 static void AppControl(app_control_h app_control, void *data)
218 Framework* framework = static_cast<Framework*>(data);
219 if(framework == NULL)
223 bundle *bundleData = NULL;
225 app_control_to_bundle(app_control, &bundleData);
226 ProcessBundle(framework, bundleData);
228 framework->AppStatusHandler(APP_RESET, NULL);
229 framework->AppStatusHandler(APP_CONTROL, app_control);
232 static void AppLanguageChanged(app_event_info_h event_info, void *user_data)
234 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
237 static void AppDeviceRotated(app_event_info_h event_info, void *user_data)
239 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
242 static void AppRegionChanged(app_event_info_h event_info, void *user_data)
244 static_cast<Framework*>(user_data)->AppStatusHandler(APP_REGION_CHANGED, NULL);
247 static void AppBatteryLow(app_event_info_h event_info, void *user_data)
249 static_cast<Framework*>(user_data)->AppStatusHandler(APP_BATTERY_LOW, NULL);
252 static void AppMemoryLow(app_event_info_h event_info, void *user_data)
254 static_cast<Framework*>(user_data)->AppStatusHandler(APP_MEMORY_LOW, NULL);
260 Impl( const Impl& impl );
263 Impl& operator=( const Impl& impl );
266 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv )
267 : mObserver(observer),
274 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
278 #ifndef TIZEN_SDK_2_2_COMPATIBILITY
279 bool featureFlag = true;
280 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
282 if( featureFlag == false )
284 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
285 throw Dali::DaliException( "", "OpenGL ES 2.0 is not supported." );
290 mImpl = new Impl(this);
293 Framework::~Framework()
303 void Framework::Run()
307 #ifdef TIZEN_SDK_2_2_COMPATIBILITY
308 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
310 int ret = ui_app_main(*mArgc, *mArgv, &mImpl->mEventCallback, this);
311 if (ret != APP_ERROR_NONE)
313 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
320 void Framework::Quit()
322 #ifdef TIZEN_SDK_2_2_COMPATIBILITY
329 bool Framework::IsMainLoopRunning()
334 void Framework::AddAbortCallback( CallbackBase* callback )
336 mImpl->mAbortCallBack = callback;
339 std::string Framework::GetBundleName() const
344 void Framework::SetBundleName(const std::string& name)
349 std::string Framework::GetBundleId() const
354 void Framework::SetBundleId(const std::string& id)
359 void Framework::AbortCallback( )
361 // if an abort call back has been installed run it.
362 if (mImpl->mAbortCallBack)
364 CallbackBase::Execute( *mImpl->mAbortCallBack );
372 bool Framework::AppStatusHandler(int type, void *bundleData)
392 mObserver.OnResume();
398 mObserver.OnTerminate();
410 mObserver.OnAppControl(bundleData);
414 case APP_LANGUAGE_CHANGE:
416 mObserver.OnLanguageChanged();
420 case APP_REGION_CHANGED:
422 mObserver.OnRegionChanged();
426 case APP_BATTERY_LOW:
428 mObserver.OnBatteryLow();
434 mObserver.OnMemoryLow();
445 } // namespace Adaptor
447 } // namespace Internal