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 #include <system_info.h>
27 #include <app_control_internal.h>
28 #include <bundle_internal.h>
29 #ifdef APPCORE_WATCH_AVAILABLE
30 #include <appcore-watch/watch_app.h>
33 #include <dali/integration-api/debug.h>
36 #include <callback-manager.h>
48 * Impl to hide EFL data members
50 struct Framework::Impl
53 Impl(void* data, Type type )
54 : mAbortCallBack( NULL ),
55 mCallbackManager( NULL )
57 mFramework = static_cast<Framework*>(data);
59 #ifndef APPCORE_WATCH_AVAILABLE
62 throw Dali::DaliException( "", "Watch Application is not supported." );
65 mApplicationType = type;
66 mCallbackManager = CallbackManager::New();
71 delete mAbortCallBack;
73 // we're quiting the main loop so
74 // mCallbackManager->RemoveAllCallBacks() does not need to be called
75 // to delete our abort handler
76 delete mCallbackManager;
83 if (mApplicationType == NORMAL)
85 ret = AppNormalMain();
96 if (mApplicationType == NORMAL)
108 Type mApplicationType;
109 CallbackBase* mAbortCallBack;
110 CallbackManager *mCallbackManager;
112 Framework* mFramework;
113 app_event_handler_h handlers[5];
114 ui_app_lifecycle_callback_s mEventCallback;
115 #ifdef APPCORE_WATCH_AVAILABLE
116 watch_app_lifecycle_callback_s mWatchCallback;
119 static bool AppCreate(void *data)
121 return static_cast<Framework*>(data)->Create();
124 static void AppTerminate(void *data)
126 Observer *observer = &static_cast<Framework*>(data)->mObserver;
128 observer->OnTerminate();
131 static void AppPause(void *data)
133 Observer *observer = &static_cast<Framework*>(data)->mObserver;
138 static void AppResume(void *data)
140 Observer *observer = &static_cast<Framework*>(data)->mObserver;
142 observer->OnResume();
145 static void ProcessBundle(Framework* framework, bundle *bundleData)
147 if(bundleData == NULL)
153 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
154 if(bundleName != NULL)
156 framework->SetBundleName(bundleName);
160 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
163 framework->SetBundleId(bundleId);
168 * Called by AppCore when the application is launched from another module (e.g. homescreen).
169 * @param[in] b the bundle data which the launcher module sent
171 static void AppControl(app_control_h app_control, void *data)
173 Framework* framework = static_cast<Framework*>(data);
174 Observer *observer = &framework->mObserver;
175 bundle *bundleData = NULL;
177 app_control_to_bundle(app_control, &bundleData);
178 ProcessBundle(framework, bundleData);
181 observer->OnAppControl(app_control);
188 mEventCallback.create = AppCreate;
189 mEventCallback.terminate = AppTerminate;
190 mEventCallback.pause = AppPause;
191 mEventCallback.resume = AppResume;
192 mEventCallback.app_control = AppControl;
194 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
195 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
196 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
197 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
198 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
200 ret = ui_app_main(*mFramework->mArgc, *mFramework->mArgv, &mEventCallback, mFramework);
210 #ifdef APPCORE_WATCH_AVAILABLE
211 static bool AppCreateWatch(int width, int height, void *data)
213 return static_cast<Framework*>(data)->Create();
216 static void AppTimeTick(watch_time_h time, void *data)
218 Observer *observer = &static_cast<Framework*>(data)->mObserver;
219 WatchTime curTime(time);
221 observer->OnTimeTick(curTime);
224 static void AppAmbientTick(watch_time_h time, void *data)
226 Observer *observer = &static_cast<Framework*>(data)->mObserver;
227 WatchTime curTime(time);
229 observer->OnAmbientTick(curTime);
232 static void AppAmbientChanged(bool ambient, void *data)
234 Observer *observer = &static_cast<Framework*>(data)->mObserver;
236 observer->OnAmbientChanged(ambient);
244 #ifdef APPCORE_WATCH_AVAILABLE
245 mWatchCallback.create = AppCreateWatch;
246 mWatchCallback.app_control = AppControl;
247 mWatchCallback.terminate = AppTerminate;
248 mWatchCallback.pause = AppPause;
249 mWatchCallback.resume = AppResume;
250 mWatchCallback.time_tick = AppTimeTick;
251 mWatchCallback.ambient_tick = AppAmbientTick;
252 mWatchCallback.ambient_changed = AppAmbientChanged;
254 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
255 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
256 watch_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
257 watch_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
259 ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
266 #ifdef APPCORE_WATCH_AVAILABLE
271 static void AppLanguageChanged(app_event_info_h event, void *data)
273 Observer *observer = &static_cast<Framework*>(data)->mObserver;
275 observer->OnLanguageChanged();
278 static void AppDeviceRotated(app_event_info_h event_info, void *data)
282 static void AppRegionChanged(app_event_info_h event, void *data)
284 Observer *observer = &static_cast<Framework*>(data)->mObserver;
286 observer->OnRegionChanged();
289 static void AppBatteryLow(app_event_info_h event, void *data)
291 Observer *observer = &static_cast<Framework*>(data)->mObserver;
293 observer->OnBatteryLow();
296 static void AppMemoryLow(app_event_info_h event, void *data)
298 Observer *observer = &static_cast<Framework*>(data)->mObserver;
300 observer->OnMemoryLow();
305 Impl( const Impl& impl );
308 Impl& operator=( const Impl& impl );
311 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
312 : mObserver(observer),
319 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
322 bool featureFlag = true;
323 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
325 if( featureFlag == false )
327 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
331 mImpl = new Impl(this, type);
334 Framework::~Framework()
344 bool Framework::Create()
351 void Framework::Run()
356 ret = mImpl->AppMain();
357 if (ret != APP_ERROR_NONE)
359 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
364 void Framework::Quit()
369 bool Framework::IsMainLoopRunning()
374 void Framework::AddAbortCallback( CallbackBase* callback )
376 mImpl->mAbortCallBack = callback;
379 std::string Framework::GetBundleName() const
384 void Framework::SetBundleName(const std::string& name)
389 std::string Framework::GetBundleId() const
394 void Framework::SetBundleId(const std::string& id)
399 void Framework::AbortCallback( )
401 // if an abort call back has been installed run it.
402 if (mImpl->mAbortCallBack)
404 CallbackBase::Execute( *mImpl->mAbortCallBack );
412 } // namespace Adaptor
414 } // namespace Internal