2 * Copyright (c) 2017 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>
30 // CONDITIONAL INCLUDES
31 #ifdef APPCORE_WATCH_AVAILABLE
32 #include <appcore-watch/watch_app.h>
34 #ifdef DALI_ELDBUS_AVAILABLE
36 #endif // DALI_ELDBUS_AVAILABLE
38 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
39 #include <tzplatform_config.h>
40 #endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
42 #include <dali/integration-api/debug.h>
45 #include <callback-manager.h>
56 #if defined(DEBUG_ENABLED)
59 Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New( Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS" );
60 } // anonymous namespace
64 * Impl to hide EFL data members
66 struct Framework::Impl
69 Impl(void* data, Type type )
70 : mAbortCallBack( NULL ),
71 mCallbackManager( NULL )
73 mFramework = static_cast<Framework*>(data);
75 #ifndef APPCORE_WATCH_AVAILABLE
78 throw Dali::DaliException( "", "Watch Application is not supported." );
81 mApplicationType = type;
82 mCallbackManager = CallbackManager::New();
87 delete mAbortCallBack;
89 // we're quiting the main loop so
90 // mCallbackManager->RemoveAllCallBacks() does not need to be called
91 // to delete our abort handler
92 delete mCallbackManager;
99 if (mApplicationType == NORMAL)
101 ret = AppNormalMain();
105 ret = AppWatchMain();
112 if (mApplicationType == NORMAL)
124 Type mApplicationType;
125 CallbackBase* mAbortCallBack;
126 CallbackManager *mCallbackManager;
128 Framework* mFramework;
129 app_event_handler_h handlers[5];
130 ui_app_lifecycle_callback_s mEventCallback;
131 #ifdef APPCORE_WATCH_AVAILABLE
132 watch_app_lifecycle_callback_s mWatchCallback;
135 static bool AppCreate(void *data)
137 return static_cast<Framework*>(data)->Create();
140 static void AppTerminate(void *data)
142 Observer *observer = &static_cast<Framework*>(data)->mObserver;
144 observer->OnTerminate();
147 static void AppPause(void *data)
149 Observer *observer = &static_cast<Framework*>(data)->mObserver;
154 static void AppResume(void *data)
156 Observer *observer = &static_cast<Framework*>(data)->mObserver;
158 observer->OnResume();
161 static void ProcessBundle(Framework* framework, bundle *bundleData)
163 if(bundleData == NULL)
169 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
170 if(bundleName != NULL)
172 framework->SetBundleName(bundleName);
176 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
179 framework->SetBundleId(bundleId);
184 * Called by AppCore when the application is launched from another module (e.g. homescreen).
185 * @param[in] b the bundle data which the launcher module sent
187 static void AppControl(app_control_h app_control, void *data)
189 Framework* framework = static_cast<Framework*>(data);
190 Observer *observer = &framework->mObserver;
191 bundle *bundleData = NULL;
193 app_control_to_bundle(app_control, &bundleData);
194 ProcessBundle(framework, bundleData);
197 observer->OnAppControl(app_control);
204 mEventCallback.create = AppCreate;
205 mEventCallback.terminate = AppTerminate;
206 mEventCallback.pause = AppPause;
207 mEventCallback.resume = AppResume;
208 mEventCallback.app_control = AppControl;
210 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
211 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
212 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
213 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
214 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
216 ret = ui_app_main(*mFramework->mArgc, *mFramework->mArgv, &mEventCallback, mFramework);
226 #ifdef APPCORE_WATCH_AVAILABLE
227 static bool AppCreateWatch(int width, int height, void *data)
229 return static_cast<Framework*>(data)->Create();
232 static void AppTimeTick(watch_time_h time, void *data)
234 Observer *observer = &static_cast<Framework*>(data)->mObserver;
235 WatchTime curTime(time);
237 observer->OnTimeTick(curTime);
240 static void AppAmbientTick(watch_time_h time, void *data)
242 Observer *observer = &static_cast<Framework*>(data)->mObserver;
243 WatchTime curTime(time);
245 observer->OnAmbientTick(curTime);
248 static void AppAmbientChanged(bool ambient, void *data)
250 Observer *observer = &static_cast<Framework*>(data)->mObserver;
252 observer->OnAmbientChanged(ambient);
260 #ifdef APPCORE_WATCH_AVAILABLE
261 mWatchCallback.create = AppCreateWatch;
262 mWatchCallback.app_control = AppControl;
263 mWatchCallback.terminate = AppTerminate;
264 mWatchCallback.pause = AppPause;
265 mWatchCallback.resume = AppResume;
266 mWatchCallback.time_tick = AppTimeTick;
267 mWatchCallback.ambient_tick = AppAmbientTick;
268 mWatchCallback.ambient_changed = AppAmbientChanged;
270 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
271 watch_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
272 watch_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
273 watch_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
275 ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
282 #ifdef APPCORE_WATCH_AVAILABLE
287 static void AppLanguageChanged(app_event_info_h event, void *data)
289 Observer *observer = &static_cast<Framework*>(data)->mObserver;
291 observer->OnLanguageChanged();
294 static void AppDeviceRotated(app_event_info_h event_info, void *data)
298 static void AppRegionChanged(app_event_info_h event, void *data)
300 Observer *observer = &static_cast<Framework*>(data)->mObserver;
302 observer->OnRegionChanged();
305 static void AppBatteryLow(app_event_info_h event, void *data)
307 Observer *observer = &static_cast<Framework*>(data)->mObserver;
309 observer->OnBatteryLow();
312 static void AppMemoryLow(app_event_info_h event, void *data)
314 Observer *observer = &static_cast<Framework*>(data)->mObserver;
316 observer->OnMemoryLow();
321 Impl( const Impl& impl );
324 Impl& operator=( const Impl& impl );
327 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
328 : mObserver(observer),
335 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
338 bool featureFlag = true;
339 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
341 if( featureFlag == false )
343 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
345 #ifdef DALI_ELDBUS_AVAILABLE
346 // Initialize ElDBus.
347 DALI_LOG_INFO( gDBusLogging, Debug::General, "Starting DBus Initialization\n" );
352 mImpl = new Impl(this, type);
355 Framework::~Framework()
362 #ifdef DALI_ELDBUS_AVAILABLE
364 DALI_LOG_INFO( gDBusLogging, Debug::General, "Shutting down DBus\n" );
371 bool Framework::Create()
378 void Framework::Run()
383 ret = mImpl->AppMain();
384 if (ret != APP_ERROR_NONE)
386 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
391 void Framework::Quit()
396 bool Framework::IsMainLoopRunning()
401 void Framework::AddAbortCallback( CallbackBase* callback )
403 mImpl->mAbortCallBack = callback;
406 std::string Framework::GetBundleName() const
411 void Framework::SetBundleName(const std::string& name)
416 std::string Framework::GetBundleId() const
421 std::string Framework::GetResourcePath()
423 std::string resourcePath = "";
424 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
425 resourcePath = app_get_resource_path();
426 #else // For backwards compatibility with older Tizen versions
428 // "DALI_APPLICATION_PACKAGE" is used to get the already configured Application package path.
429 const char* environmentVariable = "DALI_APPLICATION_PACKAGE";
430 char* value = getenv( environmentVariable );
433 resourcePath = value;
435 #endif //TIZEN_PLATFORM_CONFIG_SUPPORTED
440 void Framework::SetBundleId(const std::string& id)
445 void Framework::AbortCallback( )
447 // if an abort call back has been installed run it.
448 if (mImpl->mAbortCallBack)
450 CallbackBase::Execute( *mImpl->mAbortCallBack );
458 } // namespace Adaptor
460 } // namespace Internal