2 * Copyright (c) 2022 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 <dali/internal/adaptor/common/framework.h>
22 #include <app_common.h>
23 #include <app_control_internal.h>
25 #include <bundle_internal.h>
28 #include <system_info.h>
29 #include <system_settings.h>
30 #include <widget_base.h>
31 #include <app_core_ui_base.hh>
32 #include <app_event_internal.hh>
34 // CONDITIONAL INCLUDES
35 #ifdef APPCORE_WATCH_AVAILABLE
36 #include <appcore-watch/watch_app.h>
38 #ifdef DALI_ELDBUS_AVAILABLE
40 #endif // DALI_ELDBUS_AVAILABLE
42 #if defined(TIZEN_PLATFORM_CONFIG_SUPPORTED) && TIZEN_PLATFORM_CONFIG_SUPPORTED
43 #include <tzplatform_config.h>
44 #endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
46 #ifdef COMPONENT_APPLICATION_SUPPORT
47 #include <component_based_app_base.h>
50 #include <dali/integration-api/debug.h>
51 #include <dali/integration-api/trace.h>
54 #include <dali/internal/system/common/callback-manager.h>
55 #include <dali/internal/system/linux/dali-ecore.h>
57 using namespace tizen_cpp;
67 #if defined(DEBUG_ENABLED)
68 Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS");
70 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FRAMEWORK, true);
72 bool IsWidgetFeatureEnabled()
74 static bool feature = false;
75 static bool retrieved = false;
83 ret = system_info_get_platform_bool("http://tizen.org/feature/shell.appwidget", &feature);
84 if(ret != SYSTEM_INFO_ERROR_NONE)
86 DALI_LOG_ERROR("failed to get system info");
94 // Note : tizen appfw don't consider zero-arguments case.
95 // If framework argc & argv is nullptr, We should add at least one argv.
96 const int gTizenDummyArgc = 1;
97 const char* gTizenDummyArgv[1] = {"dali-tizen-app"};
99 } // anonymous namespace
105 LOW_MEMORY, //< The low memory event
106 LOW_BATTERY, //< The low battery event
107 LANGUAGE_CHANGED, //< The system language changed event
108 DEVICE_ORIENTATION_CHANGED, //< The device orientation changed event
109 REGION_FORMAT_CHANGED, //< The region format changed event
110 SUSPENDED_STATE_CHANGED, //< The suspended state changed event of the application
111 UPDATE_REQUESTED, //< The update requested event. This event can occur when an app needs to be updated. It is dependent on target devices.
114 static int AppEventConverter[APPCORE_BASE_EVENT_MAX] =
116 [LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
117 [LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
118 [LANGUAGE_CHANGED] = APPCORE_BASE_EVENT_LANG_CHANGE,
119 [DEVICE_ORIENTATION_CHANGED] = APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED,
120 [REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
121 [SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
130 typedef struct AppEventInfo* AppEventInfoPtr;
132 typedef void (*AppEventCallback)(AppEventInfoPtr eventInfo, void* userData);
134 struct AppEventHandler
142 typedef struct AppEventHandler* AppEventHandlerPtr;
144 int EventCallback(void* event, void* data)
146 AppEventHandlerPtr handler = static_cast<AppEventHandlerPtr>(data);
148 struct AppEventInfo appEvent;
150 appEvent.type = handler->type;
151 appEvent.value = event;
154 handler->cb(&appEvent, handler->data);
159 int AppAddEventHandler(AppEventHandlerPtr* eventHandler, AppEventType eventType, AppEventCallback callback, void* userData)
161 AppEventHandlerPtr handler;
163 handler = static_cast<AppEventHandlerPtr>(calloc(1, sizeof(struct AppEventHandler)));
166 DALI_LOG_ERROR("failed to create handler");
167 return TIZEN_ERROR_UNKNOWN;
171 handler->type = eventType;
172 handler->cb = callback;
173 handler->data = userData;
174 handler->raw = appcore_base_add_event(static_cast<appcore_base_event>(AppEventConverter[static_cast<int>(eventType)]), EventCallback, handler);
176 *eventHandler = handler;
178 return TIZEN_ERROR_NONE;
182 DeviceStatus::Memory::Status GetMemoryStatus(app_event_low_memory_status_e memoryStatus)
186 case APP_EVENT_LOW_MEMORY_SOFT_WARNING: // 0x02
188 return Dali::DeviceStatus::Memory::Status::LOW;
190 case APP_EVENT_LOW_MEMORY_HARD_WARNING: // 0x04
192 return Dali::DeviceStatus::Memory::Status::CRITICALLY_LOW;
194 default: // APP_EVENT_LOW_MEMORY_NORMAL 0x01
196 return Dali::DeviceStatus::Memory::Status::NORMAL;
201 DeviceStatus::Battery::Status GetBatteryStatus(app_event_low_battery_status_e batteryStatus)
203 switch(batteryStatus)
205 case APP_EVENT_LOW_BATTERY_POWER_OFF: // 1
207 return Dali::DeviceStatus::Battery::Status::POWER_OFF;
209 case APP_EVENT_LOW_BATTERY_CRITICAL_LOW: // 2
211 return Dali::DeviceStatus::Battery::Status::CRITICALLY_LOW;
215 return Dali::DeviceStatus::Battery::Status::NORMAL;
220 DeviceStatus::Orientation::Status GetOrientationStatus(app_device_orientation_e orientationStatus)
222 switch(orientationStatus)
224 case APP_DEVICE_ORIENTATION_0:
226 return Dali::DeviceStatus::Orientation::Status::ORIENTATION_0;
228 case APP_DEVICE_ORIENTATION_90:
230 return Dali::DeviceStatus::Orientation::Status::ORIENTATION_90;
232 case APP_DEVICE_ORIENTATION_180:
234 return Dali::DeviceStatus::Orientation::Status::ORIENTATION_180;
236 case APP_DEVICE_ORIENTATION_270:
238 return Dali::DeviceStatus::Orientation::Status::ORIENTATION_270;
242 return Dali::DeviceStatus::Orientation::Status::ORIENTATION_0;
247 } // namespace AppCore
250 * Impl to hide EFL data members
252 struct Framework::Impl
254 class UiAppContext : public AppCoreUiBase
257 class Task : public AppCoreTaskBase
260 explicit Task(Framework* framework)
261 : mFramework(framework),
262 mNewBatteryStatus(Dali::DeviceStatus::Battery::Status::NORMAL),
263 mNewMemoryStatus(Dali::DeviceStatus::Memory::NORMAL),
264 mNewDeviceOrientationStatus(Dali::DeviceStatus::Orientation::ORIENTATION_0)
272 int OnCreate() override
274 // On the main thread, the log functions are not set. So print_log() is used directly.
275 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnCreate() emitted", __MODULE__, __func__, __LINE__);
276 mFramework->mTaskObserver.OnTaskInit();
277 return AppCoreTaskBase::OnCreate();
280 int OnTerminate() override
282 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnTerminate() emitted", __MODULE__, __func__, __LINE__);
283 mFramework->mTaskObserver.OnTaskTerminate();
284 return AppCoreTaskBase::OnTerminate();
287 int OnControl(tizen_base::Bundle b) override
289 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnControl() emitted", __MODULE__, __func__, __LINE__);
290 AppCoreTaskBase::OnControl(b);
292 app_control_h appControl = nullptr;
294 auto* bundleData = b.GetHandle();
297 if(app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE)
299 print_log(DLOG_ERROR, "DALI", "%s: %s(%d) > Failed to create an app_control handle with Bundle", __MODULE__, __func__, __LINE__);
304 if(app_control_create(&appControl) != TIZEN_ERROR_NONE)
306 print_log(DLOG_ERROR, "DALI", "%s: %s(%d) > Failed to create an app_control handle", __MODULE__, __func__, __LINE__);
309 mFramework->mTaskObserver.OnTaskAppControl(appControl);
311 app_control_destroy(appControl);
315 void OnUiEvent(AppCoreTaskBase::UiState state) override
317 // This event is emitted when the UI thread is paused or resumed.
318 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnUiEvent() emitted", __MODULE__, __func__, __LINE__);
320 // Note: This isn't implemented.
321 AppCoreTaskBase::OnUiEvent(state);
324 void OnLowMemory(AppCoreTaskBase::LowMemoryState state) override
326 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnLowMemory() emitted", __MODULE__, __func__, __LINE__);
328 mNewMemoryStatus = AppCore::GetMemoryStatus(static_cast<app_event_low_memory_status_e>(state));
331 [](gpointer userData) -> gboolean
333 auto* task = static_cast<Task*>(userData);
334 auto* framework = static_cast<Framework*>(task->mFramework);
335 framework->mObserver.OnMemoryLow(task->mNewMemoryStatus);
336 return G_SOURCE_REMOVE;
338 mFramework->mTaskObserver.OnTaskMemoryLow(mNewMemoryStatus);
339 AppCoreTaskBase::OnLowMemory(state);
342 void OnDeviceOrientationChanged(AppCoreTaskBase::DeviceOrientationState state) override
344 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnDeviceOrientationChanged() emitted, orientation :%d", __MODULE__, __func__, __LINE__, state);
346 mNewDeviceOrientationStatus = AppCore::GetOrientationStatus(static_cast<app_device_orientation_e>(state));
349 [](gpointer userData) -> gboolean
351 auto* task = static_cast<Task*>(userData);
352 auto* framework = static_cast<Framework*>(task->mFramework);
353 framework->mObserver.OnDeviceOrientationChanged(task->mNewDeviceOrientationStatus);
354 return G_SOURCE_REMOVE;
357 mFramework->mTaskObserver.OnTaskDeviceOrientationChanged(mNewDeviceOrientationStatus);
359 AppCoreTaskBase::OnDeviceOrientationChanged(state);
361 void OnLowBattery(AppCoreTaskBase::LowBatteryState state) override
363 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnLowBattery() emitted", __MODULE__, __func__, __LINE__);
364 mNewBatteryStatus = AppCore::GetBatteryStatus(static_cast<app_event_low_battery_status_e>(state));
367 [](gpointer userData) -> gboolean
369 auto* task = static_cast<Task*>(userData);
370 auto* framework = static_cast<Framework*>(task->mFramework);
371 framework->mObserver.OnBatteryLow(task->mNewBatteryStatus);
372 return G_SOURCE_REMOVE;
374 mFramework->mTaskObserver.OnTaskBatteryLow(mNewBatteryStatus);
375 AppCoreTaskBase::OnLowBattery(state);
378 void OnLangChanged(const std::string& lang) override
380 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > OnLangChanged() emitted", __MODULE__, __func__, __LINE__);
382 mFramework->SetLanguage(mNewLanguage);
385 [](gpointer userData) -> gboolean
387 auto* task = static_cast<Task*>(userData);
388 auto* framework = static_cast<Framework*>(task->mFramework);
389 framework->mObserver.OnLanguageChanged();
390 return G_SOURCE_REMOVE;
393 mFramework->mTaskObserver.OnTaskLanguageChanged();
394 AppCoreTaskBase::OnLangChanged(lang);
397 void OnRegionChanged(const std::string& region) override
399 print_log(DLOG_INFO, "DALI", "%s: %s(%d) > nRegionChanged() emitted", __MODULE__, __func__, __LINE__);
401 mFramework->SetRegion(mNewRegion);
404 [](gpointer userData) -> gboolean
406 auto* task = static_cast<Task*>(userData);
407 auto* framework = static_cast<Framework*>(task->mFramework);
408 framework->mObserver.OnRegionChanged();
409 return G_SOURCE_REMOVE;
412 mFramework->mTaskObserver.OnTaskRegionChanged();
413 AppCoreTaskBase::OnRegionChanged(mNewRegion);
417 GMainContext* GetTizenGlibContext()
419 GMainContext* context;
420 const char* env = getenv("TIZEN_GLIB_CONTEXT");
423 context = (GMainContext*)strtoul(env, nullptr, 10);
433 void PostToUiThread(GSourceFunc func)
435 GSource* source = g_idle_source_new();
436 g_source_set_callback(source, func, this, nullptr);
437 g_source_attach(source, GetTizenGlibContext());
438 g_source_unref(source);
442 Framework* mFramework;
443 std::string mNewLanguage;
444 std::string mNewRegion;
445 Dali::DeviceStatus::Battery::Status mNewBatteryStatus;
446 Dali::DeviceStatus::Memory::Status mNewMemoryStatus;
447 Dali::DeviceStatus::Orientation::Status mNewDeviceOrientationStatus;
450 explicit UiAppContext(unsigned int hint, Framework* framework)
451 : AppCoreUiBase(hint),
452 mFramework(framework),
455 if(hint & AppCoreUiBase::HINT_DUAL_THREAD)
462 mLanguageChanged = std::make_shared<AppEvent>(IAppCore::IEvent::Type::LANG_CHANGE, OnLanguageChanged, this);
463 AddEvent(mLanguageChanged);
465 mDeviceOrientationChanged = std::make_shared<AppEvent>(IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED, OnDeviceOrientationChanged, this);
466 AddEvent(mDeviceOrientationChanged);
468 mRegionFormatChanged = std::make_shared<AppEvent>(IAppCore::IEvent::Type::REGION_CHANGE, OnRegionFormatChanged, this);
469 AddEvent(mRegionFormatChanged);
471 mLowMemory = std::make_shared<AppEvent>(IAppCore::IEvent::Type::LOW_MEMORY, OnLowMemory, this);
472 AddEvent(mLowMemory);
474 mLowBattery = std::make_shared<AppEvent>(IAppCore::IEvent::Type::LOW_BATTERY, OnLowBattery, this);
475 AddEvent(mLowBattery);
479 virtual ~UiAppContext()
483 RemoveEvent(mLowBattery);
484 RemoveEvent(mLowMemory);
485 RemoveEvent(mRegionFormatChanged);
486 RemoveEvent(mDeviceOrientationChanged);
487 RemoveEvent(mLanguageChanged);
491 std::unique_ptr<AppCoreTaskBase> CreateTask() override
493 return std::unique_ptr<AppCoreTaskBase>(
494 new Task(mFramework));
497 int OnCreate() override
499 AppCoreUiBase::OnCreate();
500 mFramework->Create();
504 int OnTerminate() override
506 AppCoreUiBase::OnTerminate();
507 auto* observer = &mFramework->mObserver;
508 observer->OnTerminate();
512 int OnPause() override
514 AppCoreUiBase::OnPause();
515 auto* observer = &mFramework->mObserver;
520 int OnResume() override
522 AppCoreUiBase::OnResume();
523 auto* observer = &mFramework->mObserver;
524 observer->OnResume();
528 int OnControl(tizen_base::Bundle b) override
530 AppCoreUiBase::OnControl(b);
532 app_control_h appControl = nullptr;
534 auto* bundleData = b.GetHandle();
537 if(app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE)
539 DALI_LOG_ERROR("Failed to create an app_control handle");
545 if(app_control_create(&appControl) != TIZEN_ERROR_NONE)
547 DALI_LOG_ERROR("Failed to create an app_control handle");
552 auto* observer = &mFramework->mObserver;
553 ProcessBundle(mFramework, bundleData);
555 observer->OnAppControl(appControl);
556 app_control_destroy(appControl);
560 void OnLoopInit(int argc, char** argv) override
562 #pragma GCC diagnostic push
563 #pragma GCC diagnostic ignored "-Wold-style-cast"
565 ecore_app_args_set(argc, (const char**)argv);
566 #pragma GCC diagnostic pop
568 #ifdef DALI_ELDBUS_AVAILABLE
569 // Initialize ElDBus.
570 DALI_LOG_INFO(gDBusLogging, Debug::General, "Starting DBus Initialization\n");
575 void OnLoopFinish() override
579 if(getenv("AUL_LOADER_INIT"))
581 setenv("AUL_LOADER_INIT", "0", 1);
585 #ifdef DALI_ELDBUS_AVAILABLE
587 DALI_LOG_INFO(gDBusLogging, Debug::General, "Shutting down DBus\n");
592 void OnLoopRun() override
594 ecore_main_loop_begin();
597 void OnLoopExit() override
599 ecore_main_loop_quit();
603 static void OnLanguageChanged(app_event_info_h event_info, void* user_data)
605 auto* context = static_cast<UiAppContext*>(user_data);
606 auto* framework = context->mFramework;
607 Observer* observer = &framework->mObserver;
609 char* lang = nullptr;
610 auto appEventReturn = app_event_get_language(event_info, &lang);
611 if(appEventReturn == APP_ERROR_NONE && lang)
613 framework->SetLanguage(std::string(lang));
614 observer->OnLanguageChanged();
619 DALI_LOG_ERROR("NULL pointer in Language changed event. Error code : %d\n", static_cast<int>(appEventReturn));
623 static void OnRegionFormatChanged(app_event_info_h event_info, void* user_data)
625 auto* context = static_cast<UiAppContext*>(user_data);
626 auto* framework = context->mFramework;
627 Observer* observer = &framework->mObserver;
629 char* region = nullptr;
630 auto appEventReturn = app_event_get_region_format(event_info, ®ion);
631 if(appEventReturn == APP_ERROR_NONE && region)
633 framework->SetRegion(std::string(region));
634 observer->OnRegionChanged();
639 DALI_LOG_ERROR("NULL pointer in Region changed event. Error code : %d\n", static_cast<int>(appEventReturn));
643 static void OnLowBattery(app_event_info_h event_info, void* user_data)
645 auto* context = static_cast<UiAppContext*>(user_data);
646 auto* framework = context->mFramework;
647 Observer* observer = &framework->mObserver;
649 app_event_low_battery_status_e status;
650 auto appEventReturn = app_event_get_low_battery_status(event_info, &status);
651 if(appEventReturn == APP_ERROR_NONE)
653 Dali::DeviceStatus::Battery::Status result = AppCore::GetBatteryStatus(status);
654 observer->OnBatteryLow(result);
658 DALI_LOG_ERROR("Fail to get low battery status event. Error code : %d\n", static_cast<int>(appEventReturn));
662 static void OnLowMemory(app_event_info_h event_info, void* user_data)
664 auto* context = static_cast<UiAppContext*>(user_data);
665 auto* framework = context->mFramework;
666 Observer* observer = &framework->mObserver;
668 app_event_low_memory_status_e status;
669 auto appEventReturn = app_event_get_low_memory_status(event_info, &status);
670 if(appEventReturn == APP_ERROR_NONE)
672 Dali::DeviceStatus::Memory::Status result = AppCore::GetMemoryStatus(status);
673 observer->OnMemoryLow(result);
677 DALI_LOG_ERROR("Fail to get low memory status event. Error code : %d\n", static_cast<int>(appEventReturn));
681 static void OnDeviceOrientationChanged(app_event_info_h event_info, void* user_data)
683 auto* context = static_cast<UiAppContext*>(user_data);
684 auto* framework = context->mFramework;
685 Observer* observer = &framework->mObserver;
687 app_device_orientation_e status;
688 auto appEventReturn = app_event_get_device_orientation(event_info, &status);
689 if(appEventReturn == APP_ERROR_NONE)
691 Dali::DeviceStatus::Orientation::Status result = AppCore::GetOrientationStatus(status);
692 observer->OnDeviceOrientationChanged(result);
696 DALI_LOG_ERROR("Fail to get device orientation event. Error code : %d\n", static_cast<int>(appEventReturn));
700 void ProcessBundle(Framework* framework, bundle* bundleData)
702 if(bundleData == nullptr)
708 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
709 if(bundleName != nullptr)
711 framework->SetBundleName(bundleName);
715 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
716 if(bundleId != nullptr)
718 framework->SetBundleId(bundleId);
723 Framework* mFramework;
724 std::shared_ptr<AppEvent> mLanguageChanged;
725 std::shared_ptr<AppEvent> mDeviceOrientationChanged;
726 std::shared_ptr<AppEvent> mRegionFormatChanged;
727 std::shared_ptr<AppEvent> mLowBattery;
728 std::shared_ptr<AppEvent> mLowMemory;
733 Impl(void* data, Type type, bool useUiThread)
734 : mAbortCallBack(NULL),
735 mCallbackManager(NULL),
736 handlers{nullptr, nullptr, nullptr, nullptr, nullptr},
737 mUseUiThread(useUiThread)
738 #ifdef APPCORE_WATCH_AVAILABLE
743 mFramework = static_cast<Framework*>(data);
745 #ifndef APPCORE_WATCH_AVAILABLE
748 throw Dali::DaliException("", "Watch Application is not supported.");
751 mApplicationType = type;
752 mCallbackManager = CallbackManager::New();
757 delete mAbortCallBack;
759 // we're quiting the main loop so
760 // mCallbackManager->RemoveAllCallBacks() does not need to be called
761 // to delete our abort handler
762 delete mCallbackManager;
767 // TODO: The app-core-cpp has to be applied to the other app types.
769 switch(mApplicationType)
773 ret = AppNormalMain();
778 ret = AppWidgetMain();
783 ret = AppWatchMain();
786 #ifdef COMPONENT_APPLICATION_SUPPORT
789 ret = AppComponentMain();
799 switch(mApplicationType)
816 #ifdef COMPONENT_APPLICATION_SUPPORT
826 void SetLanguage(const std::string& language)
828 mLanguage = language;
831 void SetRegion(const std::string& region)
836 std::string GetLanguage()
838 if(mLanguage.empty())
840 char* language = nullptr;
841 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &language);
843 if(language != nullptr)
845 mLanguage = std::string(language);
852 std::string GetRegion()
856 char* region = nullptr;
857 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, ®ion);
859 if(region != nullptr)
861 mRegion = std::string(region);
869 Type mApplicationType;
870 CallbackBase* mAbortCallBack;
871 CallbackManager* mCallbackManager;
872 std::string mLanguage{};
873 std::string mRegion{};
875 Framework* mFramework;
876 AppCore::AppEventHandlerPtr handlers[5];
877 std::unique_ptr<UiAppContext> mUiAppContext{nullptr};
878 bool mUseUiThread{false};
879 #ifdef APPCORE_WATCH_AVAILABLE
880 watch_app_lifecycle_callback_s mWatchCallback;
883 static void ProcessBundle(Framework* framework, bundle* bundleData)
885 if(bundleData == NULL)
891 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
892 if(bundleName != NULL)
894 framework->SetBundleName(bundleName);
898 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
901 framework->SetBundleId(bundleId);
905 static void AppInit(int argc, char** argv, void* data)
907 #pragma GCC diagnostic push
908 #pragma GCC diagnostic ignored "-Wold-style-cast"
910 ecore_app_args_set(argc, (const char**)argv);
911 #pragma GCC diagnostic pop
913 #ifdef DALI_ELDBUS_AVAILABLE
914 // Initialize ElDBus.
915 DALI_LOG_INFO(gDBusLogging, Debug::General, "Starting DBus Initialization\n");
920 static void AppFinish(void)
924 if(getenv("AUL_LOADER_INIT"))
926 setenv("AUL_LOADER_INIT", "0", 1);
930 #ifdef DALI_ELDBUS_AVAILABLE
932 DALI_LOG_INFO(gDBusLogging, Debug::General, "Shutting down DBus\n");
937 static void AppRun(void* data)
939 ecore_main_loop_begin();
942 static void AppExit(void* data)
944 ecore_main_loop_quit();
947 static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void* data)
949 Framework* framework = static_cast<Framework*>(data);
950 Observer* observer = &framework->mObserver;
952 if(event && event->value)
954 framework->SetLanguage(std::string(static_cast<const char*>(event->value)));
955 observer->OnLanguageChanged();
959 DALI_LOG_ERROR("NULL pointer in Language changed event\n");
963 static void AppRegionChanged(AppCore::AppEventInfoPtr event, void* data)
965 Framework* framework = static_cast<Framework*>(data);
966 Observer* observer = &framework->mObserver;
968 if(event && event->value)
970 framework->SetRegion(std::string(static_cast<const char*>(event->value)));
971 observer->OnRegionChanged();
975 DALI_LOG_ERROR("NULL pointer in Region changed event\n");
979 static void AppBatteryLow(AppCore::AppEventInfoPtr event, void* data)
981 Observer* observer = &static_cast<Framework*>(data)->mObserver;
982 int status = *static_cast<int*>(event->value);
983 Dali::DeviceStatus::Battery::Status result = Dali::DeviceStatus::Battery::Status::NORMAL;
985 // convert to dali battery status
990 result = Dali::DeviceStatus::Battery::POWER_OFF;
995 result = Dali::DeviceStatus::Battery::CRITICALLY_LOW;
1001 observer->OnBatteryLow(result);
1004 static void AppMemoryLow(AppCore::AppEventInfoPtr event, void* data)
1006 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1007 int status = *static_cast<int*>(event->value);
1008 Dali::DeviceStatus::Memory::Status result = Dali::DeviceStatus::Memory::Status::NORMAL;
1010 // convert to dali memmory status
1015 result = Dali::DeviceStatus::Memory::NORMAL;
1020 result = Dali::DeviceStatus::Memory::LOW;
1025 result = Dali::DeviceStatus::Memory::CRITICALLY_LOW;
1031 observer->OnMemoryLow(result);
1034 static void AppDeviceOrientationChanged(AppCore::AppEventInfoPtr event, void* data)
1036 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1037 int status = *static_cast<int*>(event->value);
1038 Dali::DeviceStatus::Orientation::Status result = Dali::DeviceStatus::Orientation::Status::ORIENTATION_0;
1042 case APP_DEVICE_ORIENTATION_0:
1044 result = Dali::DeviceStatus::Orientation::Status::ORIENTATION_0;
1047 case APP_DEVICE_ORIENTATION_90:
1049 result = Dali::DeviceStatus::Orientation::Status::ORIENTATION_90;
1052 case APP_DEVICE_ORIENTATION_180:
1054 result = Dali::DeviceStatus::Orientation::Status::ORIENTATION_180;
1057 case APP_DEVICE_ORIENTATION_270:
1059 result = Dali::DeviceStatus::Orientation::Status::ORIENTATION_270;
1066 observer->OnDeviceOrientationChanged(result);
1071 if(mUiAppContext.get() == nullptr)
1073 unsigned int hint = AppCoreUiBase::HINT_WINDOW_GROUP_CONTROL |
1074 AppCoreUiBase::HINT_WINDOW_STACK_CONTROL |
1075 AppCoreUiBase::HINT_BG_LAUNCH_CONTROL |
1076 AppCoreUiBase::HINT_HW_ACC_CONTROL |
1077 AppCoreUiBase::HINT_WINDOW_AUTO_CONTROL;
1079 // For testing UIThread model, This code turns on the UI Thread feature forcibly.
1080 // ex) app_launcher -e [APPID] __K_UI_THREAD enable
1081 // This code doesn't change mUseUiThread in Internal::Application
1082 bundle* b = bundle_import_from_argv(*mFramework->mArgc, *mFramework->mArgv);
1085 const char* val = bundle_get_val(b, "__K_UI_THREAD");
1086 if(val != nullptr && strcmp(val, "enable") == 0)
1088 mUseUiThread = true;
1096 hint |= AppCoreUiBase::HINT_DUAL_THREAD;
1099 mUiAppContext = std::make_unique<UiAppContext>(hint, mFramework);
1102 mUiAppContext->Run(*mFramework->mArgc, *mFramework->mArgv);
1103 return TIZEN_ERROR_NONE;
1106 void AppNormalExit()
1108 if(mUiAppContext.get() == nullptr)
1113 mUiAppContext->Exit();
1116 void AppWidgetExit()
1121 static int WidgetAppCreate(void* data)
1123 widget_base_on_create();
1124 return static_cast<int>(static_cast<Framework*>(data)->Create());
1127 static int WidgetAppTerminate(void* data)
1129 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1130 observer->OnTerminate();
1132 widget_base_on_terminate();
1138 if(!IsWidgetFeatureEnabled())
1140 DALI_LOG_ERROR("widget feature is not supported");
1144 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
1145 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
1146 AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceOrientationChanged, mFramework);
1147 AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
1148 AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
1150 widget_base_ops ops = widget_base_get_default_ops();
1152 /* override methods */
1153 ops.create = WidgetAppCreate;
1154 ops.terminate = WidgetAppTerminate;
1156 ops.finish = AppFinish;
1160 int result = widget_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework);
1167 #ifdef APPCORE_WATCH_AVAILABLE
1168 static bool WatchAppCreate(int width, int height, void* data)
1170 return static_cast<Framework*>(data)->Create();
1173 static void WatchAppTimeTick(watch_time_h time, void* data)
1175 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1176 WatchTime curTime(time);
1178 observer->OnTimeTick(curTime);
1181 static void WatchAppAmbientTick(watch_time_h time, void* data)
1183 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1184 WatchTime curTime(time);
1186 observer->OnAmbientTick(curTime);
1189 static void WatchAppAmbientChanged(bool ambient, void* data)
1191 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1193 observer->OnAmbientChanged(ambient);
1196 static void WatchAppControl(app_control_h app_control, void* data)
1198 Framework* framework = static_cast<Framework*>(data);
1199 Observer* observer = &framework->mObserver;
1200 bundle* bundleData = NULL;
1202 app_control_to_bundle(app_control, &bundleData);
1203 ProcessBundle(framework, bundleData);
1205 observer->OnReset();
1206 observer->OnAppControl(app_control);
1209 static void WatchAppTerminate(void* data)
1211 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1213 observer->OnTerminate();
1216 static void WatchAppPause(void* data)
1218 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1220 observer->OnPause();
1223 static void WatchAppResume(void* data)
1225 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1227 observer->OnResume();
1236 #ifdef APPCORE_WATCH_AVAILABLE
1237 mWatchCallback.create = WatchAppCreate;
1238 mWatchCallback.app_control = WatchAppControl;
1239 mWatchCallback.terminate = WatchAppTerminate;
1240 mWatchCallback.pause = WatchAppPause;
1241 mWatchCallback.resume = WatchAppResume;
1242 mWatchCallback.time_tick = WatchAppTimeTick;
1243 mWatchCallback.ambient_tick = WatchAppAmbientTick;
1244 mWatchCallback.ambient_changed = WatchAppAmbientChanged;
1246 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
1247 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
1248 AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
1249 AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
1251 ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
1258 #ifdef APPCORE_WATCH_AVAILABLE
1263 #ifdef COMPONENT_APPLICATION_SUPPORT
1264 int AppComponentMain()
1266 /*Crate component_based_app_base_lifecycle_callback*/
1267 component_based_app_base_lifecycle_callback_s callback;
1268 callback.init = AppInit;
1269 callback.run = AppRun;
1270 callback.exit = AppExit;
1271 callback.create = ComponentAppCreate;
1272 callback.terminate = ComponentAppTerminate;
1273 callback.fini = ComponentAppFinish;
1275 return component_based_app_base_main(*mFramework->mArgc, *mFramework->mArgv, &callback, mFramework);
1278 static void* ComponentAppCreate(void* data)
1280 Framework* framework = static_cast<Framework*>(data);
1281 Observer* observer = &framework->mObserver;
1284 return Dali::AnyCast<void*>(observer->OnCreate());
1287 static void ComponentAppTerminate(void* data)
1289 Observer* observer = &static_cast<Framework*>(data)->mObserver;
1290 observer->OnTerminate();
1293 static void ComponentAppFinish(void* data)
1297 if(getenv("AUL_LOADER_INIT"))
1299 setenv("AUL_LOADER_INIT", "0", 1);
1304 void AppComponentExit()
1306 component_based_app_base_exit();
1313 Impl(const Impl& impl);
1316 Impl& operator=(const Impl& impl);
1319 Framework::Framework(Framework::Observer& observer, Framework::TaskObserver& taskObserver, int* argc, char*** argv, Type type, bool useUiThread)
1320 : mObserver(observer),
1321 mTaskObserver(taskObserver),
1322 mInitialised(false),
1329 mAbortHandler(MakeCallback(this, &Framework::AbortCallback)),
1332 if(mArgc == nullptr || mArgv == nullptr)
1334 mArgc = const_cast<int*>(&gTizenDummyArgc);
1335 mArgv = const_cast<char***>(reinterpret_cast<const char***>(&gTizenDummyArgv));
1338 bool featureFlag = true;
1339 system_info_get_platform_bool("tizen.org/feature/opengles.version.2_0", &featureFlag);
1341 if(featureFlag == false)
1343 set_last_result(TIZEN_ERROR_NOT_SUPPORTED);
1348 mImpl = new Impl(this, type, useUiThread);
1351 Framework::~Framework()
1361 bool Framework::Create()
1363 mInitialised = true;
1368 void Framework::Run()
1373 DALI_TRACE_BEGIN(gTraceFilter, "DALI_APPMAIN");
1374 ret = mImpl->AppMain();
1375 DALI_TRACE_END(gTraceFilter, "DALI_APPMAIN");
1376 if(ret != APP_ERROR_NONE)
1378 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
1383 void Framework::Quit()
1388 bool Framework::IsMainLoopRunning()
1393 void Framework::AddAbortCallback(CallbackBase* callback)
1395 mImpl->mAbortCallBack = callback;
1398 std::string Framework::GetBundleName() const
1403 void Framework::SetBundleName(const std::string& name)
1408 std::string Framework::GetBundleId() const
1413 std::string Framework::GetResourcePath()
1415 std::string resourcePath = "";
1416 #if defined(TIZEN_PLATFORM_CONFIG_SUPPORTED) && TIZEN_PLATFORM_CONFIG_SUPPORTED
1417 char* app_rsc_path = app_get_resource_path();
1420 resourcePath = app_rsc_path;
1423 #else // For backwards compatibility with older Tizen versions
1425 // "DALI_APPLICATION_PACKAGE" is used to get the already configured Application package path.
1426 const char* environmentVariable = "DALI_APPLICATION_PACKAGE";
1427 char* value = getenv(environmentVariable);
1430 resourcePath = value;
1433 if(resourcePath.back() != '/')
1435 resourcePath += "/";
1438 #endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
1440 return resourcePath;
1443 std::string Framework::GetDataPath()
1446 char* dataPath = app_get_data_path();
1455 void Framework::SetBundleId(const std::string& id)
1460 void Framework::AbortCallback()
1462 // if an abort call back has been installed run it.
1463 if(mImpl->mAbortCallBack)
1465 CallbackBase::Execute(*mImpl->mAbortCallBack);
1473 void Framework::InitThreads()
1477 void Framework::SetLanguage(const std::string& language)
1479 mImpl->SetLanguage(language);
1482 void Framework::SetRegion(const std::string& region)
1484 mImpl->SetRegion(region);
1487 std::string Framework::GetLanguage() const
1489 return mImpl->GetLanguage();
1492 std::string Framework::GetRegion() const
1494 return mImpl->GetRegion();
1497 } // namespace Adaptor
1499 } // namespace Internal