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 #include <dali/integration-api/debug.h>
29 #include <callback-manager.h>
43 /// Application Status Enum
59 } // Unnamed namespace
62 * Impl to hide EFL data members
64 struct Framework::Impl
69 : mAbortCallBack( NULL ),
70 mCallbackManager( NULL )
72 mEventCallback.create = AppCreate;
73 mEventCallback.terminate = AppTerminate;
74 mEventCallback.pause = AppPause;
75 mEventCallback.resume = AppResume;
76 #ifndef OVER_TIZEN_SDK_2_2
77 mEventCallback.service = AppService;
79 mEventCallback.low_memory = NULL;
80 mEventCallback.low_battery = NULL;
81 mEventCallback.device_orientation = AppDeviceRotated;
82 mEventCallback.language_changed = AppLanguageChanged;
83 mEventCallback.region_format_changed = NULL;
86 mEventCallback.app_control = AppControl;
88 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, data);
89 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, data);
90 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, data);
91 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, data);
92 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, data);
96 mCallbackManager = CallbackManager::New();
101 delete mAbortCallBack;
103 // we're quiting the main loop so
104 // mCallbackManager->RemoveAllCallBacks() does not need to be called
105 // to delete our abort handler
106 delete mCallbackManager;
111 CallbackBase* mAbortCallBack;
112 CallbackManager *mCallbackManager;
114 #ifndef OVER_TIZEN_SDK_2_2
115 app_event_callback_s mEventCallback;
117 ui_app_lifecycle_callback_s mEventCallback;
118 app_event_handler_h handlers[5];
122 * Called by AppCore on application creation.
124 static bool AppCreate(void *data)
126 return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);
130 * Called by AppCore when the application should terminate.
132 static void AppTerminate(void *data)
134 static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);
138 * Called by AppCore when the application is paused.
140 static void AppPause(void *data)
142 static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);
146 * Called by AppCore when the application is resumed.
148 static void AppResume(void *data)
150 static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);
153 static void ProcessBundle(Framework* framework, bundle *bundleData)
155 if(bundleData == NULL)
161 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
162 if(bundleName != NULL)
164 framework->SetBundleName(bundleName);
168 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
171 framework->SetBundleId(bundleId);
175 #ifndef OVER_TIZEN_SDK_2_2
177 * Called by AppCore when the application is launched from another module (e.g. homescreen).
178 * @param[in] b the bundle data which the launcher module sent
180 static void AppService(service_h service, void *data)
182 Framework* framework = static_cast<Framework*>(data);
184 if(framework == NULL)
188 bundle *bundleData = NULL;
190 service_to_bundle(service, &bundleData);
191 ProcessBundle(framework, bundleData);
193 framework->AppStatusHandler(APP_RESET, NULL);
196 static void AppLanguageChanged(void* user_data)
198 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
201 static void AppDeviceRotated(app_device_orientation_e orientation, void *user_data)
203 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
209 * Called by AppCore when the application is launched from another module (e.g. homescreen).
210 * @param[in] b the bundle data which the launcher module sent
212 static void AppControl(app_control_h app_control, void *data)
214 Framework* framework = static_cast<Framework*>(data);
215 if(framework == NULL)
219 bundle *bundleData = NULL;
221 app_control_to_bundle(app_control, &bundleData);
222 ProcessBundle(framework, bundleData);
224 framework->AppStatusHandler(APP_RESET, NULL);
225 framework->AppStatusHandler(APP_CONTROL, app_control);
228 static void AppLanguageChanged(app_event_info_h event_info, void *user_data)
230 static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
233 static void AppDeviceRotated(app_event_info_h event_info, void *user_data)
235 static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
238 static void AppRegionChanged(app_event_info_h event_info, void *user_data)
240 static_cast<Framework*>(user_data)->AppStatusHandler(APP_REGION_CHANGED, NULL);
243 static void AppBatteryLow(app_event_info_h event_info, void *user_data)
245 static_cast<Framework*>(user_data)->AppStatusHandler(APP_BATTERY_LOW, NULL);
248 static void AppMemoryLow(app_event_info_h event_info, void *user_data)
250 static_cast<Framework*>(user_data)->AppStatusHandler(APP_MEMORY_LOW, NULL);
257 Framework::Framework(Framework::Observer& observer, int *argc, char ***argv, const std::string& name)
258 : mObserver(observer),
266 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
270 mImpl = new Impl(this);
273 Framework::~Framework()
283 void Framework::Run()
287 #ifndef OVER_TIZEN_SDK_2_2
288 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
291 int ret = ui_app_main(*mArgc, *mArgv, &mImpl->mEventCallback, this);
292 if (ret != APP_ERROR_NONE)
294 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
301 void Framework::Quit()
306 bool Framework::IsMainLoopRunning()
311 void Framework::AddAbortCallback( CallbackBase* callback )
313 mImpl->mAbortCallBack = callback;
316 std::string Framework::GetBundleName() const
321 void Framework::SetBundleName(const std::string& name)
326 std::string Framework::GetBundleId() const
331 void Framework::SetBundleId(const std::string& id)
336 void Framework::AbortCallback( )
338 // if an abort call back has been installed run it.
339 if (mImpl->mAbortCallBack)
341 CallbackBase::Execute( *mImpl->mAbortCallBack );
349 bool Framework::AppStatusHandler(int type, void *bundleData)
357 // Connect to abnormal exit signals
358 mAbortHandler.AbortOnSignal( SIGINT );
359 mAbortHandler.AbortOnSignal( SIGQUIT );
360 mAbortHandler.AbortOnSignal( SIGKILL );
374 mObserver.OnResume();
380 mObserver.OnTerminate();
392 mObserver.OnAppControl(bundleData);
396 case APP_LANGUAGE_CHANGE:
398 mObserver.OnLanguageChanged();
402 case APP_REGION_CHANGED:
404 mObserver.OnRegionChanged();
408 case APP_BATTERY_LOW:
410 mObserver.OnBatteryLow();
416 mObserver.OnMemoryLow();
427 } // namespace Adaptor
429 } // namespace Internal