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>
37 #include <watch-application-impl.h>
38 #include <watch-time.h>
50 * Impl to hide EFL data members
52 struct Framework::Impl
55 Impl(void* data, Type type )
56 : mAbortCallBack( NULL ),
57 mCallbackManager( NULL )
59 mFramework = static_cast<Framework*>(data);
61 #ifndef APPCORE_WATCH_AVAILABLE
64 throw Dali::DaliException( "", "Watch Application is not supported." );
67 mApplicationType = type;
68 mCallbackManager = CallbackManager::New();
73 delete mAbortCallBack;
75 // we're quiting the main loop so
76 // mCallbackManager->RemoveAllCallBacks() does not need to be called
77 // to delete our abort handler
78 delete mCallbackManager;
85 if (mApplicationType == NORMAL)
87 ret = AppNormalMain();
98 if (mApplicationType == NORMAL)
110 Type mApplicationType;
111 CallbackBase* mAbortCallBack;
112 CallbackManager *mCallbackManager;
114 Framework* mFramework;
115 app_event_handler_h handlers[5];
116 ui_app_lifecycle_callback_s mEventCallback;
117 #ifdef APPCORE_WATCH_AVAILABLE
118 watch_app_lifecycle_callback_s mWatchCallback;
121 static bool AppCreate(void *data)
123 return static_cast<Framework*>(data)->Create();
126 static void AppTerminate(void *data)
128 Observer *observer = &static_cast<Framework*>(data)->mObserver;
130 observer->OnTerminate();
133 static void AppPause(void *data)
135 Observer *observer = &static_cast<Framework*>(data)->mObserver;
140 static void AppResume(void *data)
142 Observer *observer = &static_cast<Framework*>(data)->mObserver;
144 observer->OnResume();
147 static void ProcessBundle(Framework* framework, bundle *bundleData)
149 if(bundleData == NULL)
155 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
156 if(bundleName != NULL)
158 framework->SetBundleName(bundleName);
162 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
165 framework->SetBundleId(bundleId);
170 * Called by AppCore when the application is launched from another module (e.g. homescreen).
171 * @param[in] b the bundle data which the launcher module sent
173 static void AppControl(app_control_h app_control, void *data)
175 Framework* framework = static_cast<Framework*>(data);
176 Observer *observer = &framework->mObserver;
177 bundle *bundleData = NULL;
179 app_control_to_bundle(app_control, &bundleData);
180 ProcessBundle(framework, bundleData);
183 observer->OnAppControl(app_control);
190 mEventCallback.create = AppCreate;
191 mEventCallback.terminate = AppTerminate;
192 mEventCallback.pause = AppPause;
193 mEventCallback.resume = AppResume;
194 mEventCallback.app_control = AppControl;
196 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
197 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
198 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
199 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
200 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
202 ret = ui_app_main(*mFramework->mArgc, *mFramework->mArgv, &mEventCallback, mFramework);
212 #ifdef APPCORE_WATCH_AVAILABLE
213 static bool AppCreateWatch(int width, int height, void *data)
215 return static_cast<Framework*>(data)->Create();
218 static void AppTimeTick(watch_time_h time, void *data)
220 Observer *observer = &static_cast<Framework*>(data)->mObserver;
221 WatchTime curTime(time);
223 observer->OnTimeTick(curTime);
226 static void AppAmbientTick(watch_time_h time, void *data)
228 Observer *observer = &static_cast<Framework*>(data)->mObserver;
229 WatchTime curTime(time);
231 observer->OnAmbientTick(curTime);
234 static void AppAmbientChanged(bool ambient, void *data)
236 Observer *observer = &static_cast<Framework*>(data)->mObserver;
238 observer->OnAmbientChanged(ambient);
246 #ifdef APPCORE_WATCH_AVAILABLE
247 mWatchCallback.create = AppCreateWatch;
248 mWatchCallback.app_control = AppControl;
249 mWatchCallback.terminate = AppTerminate;
250 mWatchCallback.pause = AppPause;
251 mWatchCallback.resume = AppResume;
252 mWatchCallback.time_tick = AppTimeTick;
253 mWatchCallback.ambient_tick = AppAmbientTick;
254 mWatchCallback.ambient_changed = AppAmbientChanged;
256 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
257 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
258 watch_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
259 watch_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
261 ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
268 #ifdef APPCORE_WATCH_AVAILABLE
273 static void AppLanguageChanged(app_event_info_h event, void *data)
275 Observer *observer = &static_cast<Framework*>(data)->mObserver;
277 observer->OnLanguageChanged();
280 static void AppDeviceRotated(app_event_info_h event_info, void *data)
284 static void AppRegionChanged(app_event_info_h event, void *data)
286 Observer *observer = &static_cast<Framework*>(data)->mObserver;
288 observer->OnRegionChanged();
291 static void AppBatteryLow(app_event_info_h event, void *data)
293 Observer *observer = &static_cast<Framework*>(data)->mObserver;
295 observer->OnBatteryLow();
298 static void AppMemoryLow(app_event_info_h event, void *data)
300 Observer *observer = &static_cast<Framework*>(data)->mObserver;
302 observer->OnMemoryLow();
307 Impl( const Impl& impl );
310 Impl& operator=( const Impl& impl );
313 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
314 : mObserver(observer),
321 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
324 bool featureFlag = true;
325 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
327 if( featureFlag == false )
329 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
330 throw Dali::DaliException( "", "OpenGL ES 2.0 is not supported." );
334 mImpl = new Impl(this, type);
337 Framework::~Framework()
347 bool Framework::Create()
354 void Framework::Run()
359 ret = mImpl->AppMain();
360 if (ret != APP_ERROR_NONE)
362 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
367 void Framework::Quit()
372 bool Framework::IsMainLoopRunning()
377 void Framework::AddAbortCallback( CallbackBase* callback )
379 mImpl->mAbortCallBack = callback;
382 std::string Framework::GetBundleName() const
387 void Framework::SetBundleName(const std::string& name)
392 std::string Framework::GetBundleId() const
397 void Framework::SetBundleId(const std::string& id)
402 void Framework::AbortCallback( )
404 // if an abort call back has been installed run it.
405 if (mImpl->mAbortCallBack)
407 CallbackBase::Execute( *mImpl->mAbortCallBack );
415 } // namespace Adaptor
417 } // namespace Internal