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"
23 #include <aul_app_com.h>
24 #include <appcore_ui_base.h>
25 #include <appcore_multiwindow_base.h>
26 #include <app_control_internal.h>
27 #include <app_common.h>
29 #include <bundle_internal.h>
31 #include <screen_connector_provider.h>
32 #include <system_info.h>
36 #include <vconf-internal-keys.h>
38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wold-style-cast"
41 #pragma GCC diagnostic pop
43 // CONDITIONAL INCLUDES
44 #ifdef APPCORE_WATCH_AVAILABLE
45 #include <appcore-watch/watch_app.h>
47 #ifdef DALI_ELDBUS_AVAILABLE
49 #endif // DALI_ELDBUS_AVAILABLE
51 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
52 #include <tzplatform_config.h>
53 #endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
55 #include <dali/integration-api/debug.h>
58 #include <callback-manager.h>
60 #include <widget-impl.h>
61 #include <widget-data.h>
74 #if defined(DEBUG_ENABLED)
75 Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New( Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS" );
78 // TODO: remove these global variables
79 static bool gForegroundState;
81 static char* gPackageId;
82 static char* gViewerEndpoint;
84 } // anonymous namespace
91 LOW_MEMORY, //< The low memory event
92 LOW_BATTERY, //< The low battery event
93 LANGUAGE_CHANGED, //< The system language changed event
94 DEVICE_ORIENTATION_CHANGED, //< The device orientation changed event
95 REGION_FORMAT_CHANGED, //< The region format changed event
96 SUSPENDED_STATE_CHANGED, //< The suspended state changed event of the application
97 UPDATE_REQUESTED, //< The update requested event. This event can occur when an app needs to be updated. It is dependent on target devices.
100 static int AppEventConverter[APPCORE_BASE_EVENT_MAX] =
102 [LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
103 [LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
104 [LANGUAGE_CHANGED] = APPCORE_BASE_EVENT_LANG_CHANGE,
105 [DEVICE_ORIENTATION_CHANGED] = APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED,
106 [REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
107 [SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
116 typedef struct AppEventInfo *AppEventInfoPtr;
118 typedef void (*AppEventCallback)(AppEventInfoPtr eventInfo, void *userData);
120 struct AppEventHandler
128 typedef struct AppEventHandler *AppEventHandlerPtr;
130 int EventCallback(void *event, void *data)
132 AppEventHandlerPtr handler = static_cast<AppEventHandlerPtr>(data);
134 struct AppEventInfo appEvent;
136 appEvent.type = handler->type;
137 appEvent.value = event;
140 handler->cb(&appEvent, handler->data);
145 int AppAddEventHandler(AppEventHandlerPtr *eventHandler, AppEventType eventType, AppEventCallback callback, void *userData)
147 AppEventHandlerPtr handler;
149 handler = static_cast<AppEventHandlerPtr>( calloc(1, sizeof(struct AppEventHandler)) );
152 DALI_LOG_ERROR( "failed to create handler" );
153 return TIZEN_ERROR_UNKNOWN;
157 handler->type = eventType;
158 handler->cb = callback;
159 handler->data = userData;
160 handler->raw = appcore_base_add_event( static_cast<appcore_base_event>(AppEventConverter[static_cast<int>(eventType)]), EventCallback, handler);
162 *eventHandler = handler;
164 return TIZEN_ERROR_NONE;
168 } // namespace Appcore
171 * Impl to hide EFL data members
173 struct Framework::Impl
176 Impl(void* data, Type type )
177 : mAbortCallBack( NULL ),
178 mCallbackManager( NULL )
179 #ifdef APPCORE_WATCH_AVAILABLE
183 mFramework = static_cast<Framework*>(data);
184 gForegroundState = false;
186 #ifndef APPCORE_WATCH_AVAILABLE
189 throw Dali::DaliException( "", "Watch Application is not supported." );
192 mApplicationType = type;
193 mCallbackManager = CallbackManager::New();
198 delete mAbortCallBack;
200 // we're quiting the main loop so
201 // mCallbackManager->RemoveAllCallBacks() does not need to be called
202 // to delete our abort handler
203 delete mCallbackManager;
210 if (mApplicationType == NORMAL)
212 ret = AppNormalMain();
214 else if(mApplicationType == WIDGET)
216 ret = AppWidgetMain();
220 ret = AppWatchMain();
227 if (mApplicationType == NORMAL)
231 else if(mApplicationType == WIDGET)
243 Type mApplicationType;
244 CallbackBase* mAbortCallBack;
245 CallbackManager *mCallbackManager;
247 Framework* mFramework;
248 AppCore::AppEventHandlerPtr handlers[5];
250 #ifdef APPCORE_WATCH_AVAILABLE
251 watch_app_lifecycle_callback_s mWatchCallback;
252 app_event_handler_h watchHandlers[5];
255 static int AppCreate(void *data)
257 appcore_ui_base_on_create();
258 return static_cast<int>( static_cast<Framework*>(data)->Create() );
261 static int AppTerminate(void *data)
263 appcore_ui_base_on_terminate();
264 Observer *observer = &static_cast<Framework*>(data)->mObserver;
266 observer->OnTerminate();
271 static int AppPause(void *data)
273 appcore_ui_base_on_pause();
274 Observer *observer = &static_cast<Framework*>(data)->mObserver;
281 static int AppResume(void *data)
283 appcore_ui_base_on_resume();
284 Observer *observer = &static_cast<Framework*>(data)->mObserver;
286 observer->OnResume();
291 static void ProcessBundle(Framework* framework, bundle *bundleData)
293 if(bundleData == NULL)
299 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
300 if(bundleName != NULL)
302 framework->SetBundleName(bundleName);
306 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
309 framework->SetBundleId(bundleId);
314 * Called by AppCore when the application is launched from another module (e.g. homescreen).
315 * @param[in] b the bundle data which the launcher module sent
317 static int AppControl(bundle* bundleData, void *data)
319 app_control_h appControl = NULL;
321 appcore_ui_base_on_control(bundleData);
325 if (app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE)
327 DALI_LOG_ERROR("Failed to create an app_control handle");
332 if (app_control_create(&appControl) != TIZEN_ERROR_NONE)
334 DALI_LOG_ERROR("Failed to create an app_control handle");
338 Framework* framework = static_cast<Framework*>(data);
339 Observer *observer = &framework->mObserver;
341 ProcessBundle(framework, bundleData);
344 observer->OnAppControl(appControl);
346 app_control_destroy(appControl);
351 static void AppInit(int argc, char **argv, void *data)
353 #pragma GCC diagnostic push
354 #pragma GCC diagnostic ignored "-Wold-style-cast"
357 ecore_app_args_set( argc, (const char **)argv );
359 #pragma GCC diagnostic pop
362 static void AppFinish(void)
366 if(getenv("AUL_LOADER_INIT"))
368 unsetenv("AUL_LOADER_INIT");
373 static void AppRun(void *data)
375 ecore_main_loop_begin();
378 static void AppExit(void *data)
380 ecore_main_loop_quit();
383 static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void *data)
385 Observer *observer = &static_cast<Framework*>(data)->mObserver;
386 std::string language( static_cast<const char *>(event->value) );
387 observer->OnLanguageChanged(language);
390 static void AppDeviceRotated(AppCore::AppEventInfoPtr event_info, void *data)
394 static void AppRegionChanged(AppCore::AppEventInfoPtr event, void *data)
396 Observer *observer = &static_cast<Framework*>(data)->mObserver;
397 std::string region( static_cast<const char *>(event->value) );
398 observer->OnRegionChanged(region);
401 static void AppBatteryLow(AppCore::AppEventInfoPtr event, void *data)
403 Observer *observer = &static_cast<Framework*>(data)->mObserver;
404 int status = *static_cast<int *>(event->value);
405 Dali::DevelApplication::BatteryStatus::Type result = Dali::DevelApplication::BatteryStatus::NORMAL;
407 // convert to dali battery status
412 result = Dali::DevelApplication::BatteryStatus::POWER_OFF;
417 result = Dali::DevelApplication::BatteryStatus::CRITICAL_LOW;
423 observer->OnBatteryLow(result);
426 static void AppMemoryLow(AppCore::AppEventInfoPtr event, void *data)
428 Observer *observer = &static_cast<Framework*>(data)->mObserver;
429 int status = *static_cast<int *>(event->value);
430 Dali::DevelApplication::MemoryStatus::Type result = Dali::DevelApplication::MemoryStatus::NORMAL;
431 // convert to dali memmory status
436 result = Dali::DevelApplication::MemoryStatus::NORMAL;
441 result = Dali::DevelApplication::MemoryStatus::SOFT_WARNING;
446 result = Dali::DevelApplication::MemoryStatus::HARD_WARNING;
452 observer->OnMemoryLow(result);
460 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
461 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
462 AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
463 AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
464 AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
466 appcore_ui_base_ops ops = appcore_ui_base_get_default_ops();
468 /* override methods */
469 ops.base.create = AppCreate;
470 ops.base.control = AppControl;
471 ops.base.terminate = AppTerminate;
472 ops.pause = AppPause;
473 ops.resume = AppResume;
474 ops.base.init = AppInit;
475 ops.base.finish = AppFinish;
476 ops.base.run = AppRun;
477 ops.base.exit = AppExit;
479 ret = appcore_ui_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework, APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL |
480 APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL |
481 APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL |
482 APPCORE_UI_BASE_HINT_HW_ACC_CONTROL |
483 APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL );
485 if (ret != TIZEN_ERROR_NONE)
488 appcore_ui_base_fini();
490 return TIZEN_ERROR_NONE;
495 appcore_ui_base_exit();
500 if( !IsWidgetFeatureEnabled() )
502 DALI_LOG_ERROR("widget feature is not supported");
506 appcore_multiwindow_base_exit();
512 if( !IsWidgetFeatureEnabled() )
514 DALI_LOG_ERROR("widget feature is not supported");
518 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
519 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
520 AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
521 AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
522 AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
524 appcore_multiwindow_base_ops ops = appcore_multiwindow_base_get_default_ops();
526 /* override methods */
527 ops.base.create = WidgetAppCreate;
528 ops.base.control = WidgetAppControl;
529 ops.base.terminate = WidgetAppTerminate;
530 ops.base.receive = WidgetAppReceive;
531 ops.base.init = AppInit;
532 ops.base.finish = AppFinish;
533 ops.base.run = AppRun;
534 ops.base.exit = AppExit;
536 bundle *bundleFromArgv = bundle_import_from_argv(*mFramework->mArgc, *mFramework->mArgv);
538 char* viewerEndpoint = NULL;
542 bundle_get_str(bundleFromArgv, "__WIDGET_ENDPOINT__", &viewerEndpoint);
545 gViewerEndpoint = strdup(viewerEndpoint);
549 DALI_LOG_ERROR("endpoint is missing");
553 bundle_free(bundleFromArgv);
557 DALI_LOG_ERROR("failed to get launch argv");
561 appcore_multiwindow_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework);
562 appcore_multiwindow_base_fini();
563 return TIZEN_ERROR_NONE;
566 static void WidgetAppPoweroff(keynode_t *key, void *data)
570 val = vconf_keynode_get_int(key);
572 case VCONFKEY_SYSMAN_POWER_OFF_DIRECT:
573 case VCONFKEY_SYSMAN_POWER_OFF_RESTART:
575 static_cast<Internal::Adaptor::Framework::Impl*>(data)->AppWidgetExit();
578 case VCONFKEY_SYSMAN_POWER_OFF_NONE:
579 case VCONFKEY_SYSMAN_POWER_OFF_POPUP:
585 static int WidgetAppCreate(void *data)
587 char pkgid[256] = {0, };
589 appcore_multiwindow_base_on_create();
592 if(aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) == 0)
594 gPackageId = strdup(pkgid);
597 if(!gPackageId || !gAppId)
599 DALI_LOG_ERROR("package_id is NULL");
603 screen_connector_provider_init();
604 vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, WidgetAppPoweroff, data);
606 return static_cast<int>( static_cast<Framework*>(data)->Create() );
609 static int WidgetAppTerminate(void *data)
611 Observer *observer = &static_cast<Framework*>(data)->mObserver;
613 observer->OnTerminate();
615 vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, WidgetAppPoweroff);
616 screen_connector_provider_fini();
618 appcore_multiwindow_base_on_terminate();
622 static void WidgetAppInstResume(const char* classId, const char* id, appcore_multiwindow_base_instance_h context, void* data)
624 WidgetInstanceResume(classId, id, static_cast<bundle*>(data));
627 static void WidgetInstanceResume(const char* classId, const char* id, bundle* bundleData)
629 appcore_multiwindow_base_instance_h context;
631 context = appcore_multiwindow_base_instance_find(id);
635 DALI_LOG_ERROR("context not found: %s", id);
639 appcore_multiwindow_base_instance_resume(context);
641 SendUpdateStatus(classId, id, AUL_WIDGET_INSTANCE_EVENT_RESUME, NULL);
643 if(!gForegroundState)
645 aul_send_app_status_change_signal( getpid(), gAppId, gPackageId, "fg", "widgetapp" );
646 gForegroundState = true;
652 static int SendUpdateStatus(const char* classId, const char* instanceId, int status, bundle* extra )
656 bundle_raw *raw = NULL;
659 bundleData = bundle_create();
662 DALI_LOG_ERROR("out of memory");
666 bundle_add_str(bundleData, AUL_K_WIDGET_ID, classId);
667 bundle_add_str(bundleData, AUL_K_WIDGET_INSTANCE_ID, instanceId);
668 bundle_add_byte(bundleData, AUL_K_WIDGET_STATUS, &status, sizeof(int));
672 bundle_encode(extra, &raw, &length);
673 #pragma GCC diagnostic push
674 #pragma GCC diagnostic ignored "-Wold-style-cast"
675 bundle_add_str(bundleData, "__WIDGET_CONTENT_INFO__", (const char*)raw);
676 #pragma GCC diagnostic pop
678 aul_widget_instance_add(classId, instanceId);
681 aul_app_com_send(gViewerEndpoint, bundleData);
685 case AUL_WIDGET_INSTANCE_EVENT_CREATE:
686 lifecycle = Dali::Widget::WidgetLifecycleEventType::CREATE;
688 case AUL_WIDGET_INSTANCE_EVENT_DESTROY:
689 lifecycle = Dali::Widget::WidgetLifecycleEventType::DESTROY;
691 case AUL_WIDGET_INSTANCE_EVENT_PAUSE:
692 lifecycle = Dali::Widget::WidgetLifecycleEventType::PAUSE;
694 case AUL_WIDGET_INSTANCE_EVENT_RESUME:
695 lifecycle = Dali::Widget::WidgetLifecycleEventType::RESUME;
700 SendLifecycleEvent(classId, instanceId, lifecycle);
702 bundle_free(bundleData);
709 static int SendLifecycleEvent(const char* classId, const char* instanceId, int status)
711 bundle* bundleData = bundle_create();
714 if (bundleData == NULL)
716 DALI_LOG_ERROR("out of memory");
720 bundle_add_str(bundleData, AUL_K_WIDGET_ID, classId);
721 bundle_add_str(bundleData, AUL_K_WIDGET_INSTANCE_ID, instanceId);
722 bundle_add_byte(bundleData, AUL_K_WIDGET_STATUS, &status, sizeof(int));
723 bundle_add_str(bundleData, AUL_K_PKGID, gPackageId);
725 ret = aul_app_com_send("widget.status", bundleData);
728 DALI_LOG_ERROR("send lifecycle error:%d", ret);
730 bundle_free(bundleData);
735 static int WidgetAppReceive(aul_type type, bundle *bundleData, void *data)
737 appcore_multiwindow_base_on_receive(type, bundleData);
743 appcore_multiwindow_base_instance_foreach_full(WidgetAppInstResume, bundleData);
748 static_cast<Internal::Adaptor::Framework::Impl*>(data)->AppWidgetExit();
751 case AUL_WIDGET_CONTENT:
753 GetContent(bundleData);
762 static void GetContent( bundle* bundleData )
764 char* instanceId = NULL;
765 appcore_multiwindow_base_instance_h context;
766 const appcore_multiwindow_base_class *cls;
767 Internal::Adaptor::Widget *widgetInstance;
769 bundle_get_str(bundleData, AUL_K_WIDGET_INSTANCE_ID, &instanceId);
772 DALI_LOG_ERROR("instance id is NULL");
776 context = static_cast<appcore_multiwindow_base_instance_h>(appcore_multiwindow_base_instance_find(instanceId));
779 DALI_LOG_ERROR("could not find widget obj: %s", instanceId);
783 cls = appcore_multiwindow_base_instance_get_class(context);
786 DALI_LOG_ERROR("widget class is NULL");
790 widgetInstance = static_cast<Internal::Adaptor::Widget*>(cls->data);
793 DALI_LOG_ERROR("widget instance is NULL");
797 Dali::WidgetData *widgetData = widgetInstance->FindWidgetData( instanceId );
800 DALI_LOG_ERROR("widget extra is NULL");
804 char* widgetContent = widgetData->GetContent();
807 bundle_add_str(bundleData, AUL_K_WIDGET_CONTENT_INFO, widgetContent);
811 bundle_add_str(bundleData, AUL_K_WIDGET_CONTENT_INFO, "");
816 * Called by AppCore when the application is launched from another module (e.g. homescreen).
817 * @param[in] b the bundle data which the launcher module sent
819 static int WidgetAppControl(bundle* bundleData, void *data)
821 char *classId = NULL;
823 char *operation = NULL;
825 appcore_multiwindow_base_on_control(bundleData);
827 bundle_get_str(bundleData, AUL_K_WIDGET_ID, &classId);
828 bundle_get_str(bundleData, AUL_K_WIDGET_INSTANCE_ID, &id);
829 bundle_get_str(bundleData, "__WIDGET_OP__", &operation);
833 DALI_LOG_ERROR("operation is NULL");
837 if(strcmp(operation, "create") == 0)
839 InstanceCreate( classId, id, bundleData );
841 else if (strcmp(operation, "resize") == 0)
843 InstanceResize( classId, id, bundleData );
845 else if (strcmp(operation, "update") == 0)
847 InstanceUpdate( classId, id, bundleData );
849 else if (strcmp(operation, "destroy") == 0)
851 InstanceDestroy( classId, id, bundleData, data );
853 else if (strcmp(operation, "resume") == 0)
855 InstanceResume( classId, id, bundleData );
857 else if (strcmp(operation, "pause") == 0)
859 InstancePause( classId, id, bundleData );
861 else if (strcmp(operation, "terminate") == 0)
863 InstanceDestroy( classId, id, bundleData, data );
869 static void InstanceCreate(const char* classId, const char* id, bundle* bundleData)
871 appcore_multiwindow_base_instance_run(classId, id, bundle_dup(bundleData));
874 static void InstanceResize(const char *classId, const char *id, bundle *bundleData)
876 appcore_multiwindow_base_instance_h context;
877 Internal::Adaptor::Widget *widgetInstance;
878 const appcore_multiwindow_base_class *cls;
880 char *widthStr = NULL;
881 char *heightStr = NULL;
885 context = appcore_multiwindow_base_instance_find(id);
889 DALI_LOG_ERROR("context not found: %s", id);
893 cls = appcore_multiwindow_base_instance_get_class(context);
896 DALI_LOG_ERROR("widget class is NULL");
900 widgetInstance = static_cast<Internal::Adaptor::Widget*>(cls->data);
903 DALI_LOG_ERROR("widget instance is NULL");
907 bundle_get_str(bundleData, "__WIDGET_WIDTH__", &widthStr);
908 bundle_get_str(bundleData, "__WIDGET_HEIGHT__", &heightStr);
911 width = static_cast<uint32_t>(g_ascii_strtoll(widthStr, &remain, 10));
914 height = static_cast<uint32_t>(g_ascii_strtoll(heightStr, &remain, 10));
916 widgetInstance->OnResize( context, Dali::Widget::WindowSize(width,height) );
919 static void InstanceUpdate(const char* classId, const char* id, bundle* bundleData)
921 appcore_multiwindow_base_instance_h context;
925 appcore_multiwindow_base_instance_foreach(classId, UpdateCallback, bundleData);
929 context = appcore_multiwindow_base_instance_find(id);
933 DALI_LOG_ERROR("context not found: %s", id);
937 UpdateCallback(classId, id, context, bundleData);
940 static void UpdateCallback(const char* classId, const char* id, appcore_multiwindow_base_instance_h context, void* data)
942 Internal::Adaptor::Widget *widgetInstance;
943 const appcore_multiwindow_base_class *cls;
944 bundle* content = NULL;
945 char* contentRaw = NULL;
946 char* forceStr = NULL;
948 bundle* bundleData = static_cast<bundle*>(data);
952 DALI_LOG_ERROR("bundle is NULL");
956 cls = appcore_multiwindow_base_instance_get_class(context);
959 DALI_LOG_ERROR("class is NULL");
963 widgetInstance = static_cast<Internal::Adaptor::Widget*>(cls->data);
966 DALI_LOG_ERROR("widget instance is NULL");
970 bundle_get_str(bundleData, "__WIDGET_FORCE__", &forceStr);
972 if(forceStr && strcmp(forceStr, "true") == 0)
981 bundle_get_str(bundleData, "__WIDGET_CONTENT_INFO__", &contentRaw);
985 #pragma GCC diagnostic push
986 #pragma GCC diagnostic ignored "-Wold-style-cast"
987 content = bundle_decode((const bundle_raw *)contentRaw, strlen(contentRaw));
988 #pragma GCC diagnostic pop
992 widgetInstance->OnUpdate(context, content, force);
996 bundle_free(content);
1000 static void InstanceDestroy(const char* classId, const char* id, bundle* bundleData, void* data)
1002 appcore_multiwindow_base_instance_h context;
1004 Internal::Adaptor::Widget *widgetInstance;
1005 const appcore_multiwindow_base_class *cls;
1007 context = appcore_multiwindow_base_instance_find(id);
1011 DALI_LOG_ERROR("could not find widget obj: %s, clear amd info", id);
1012 aul_widget_instance_del(classId, id);
1016 cls = appcore_multiwindow_base_instance_get_class(context);
1019 DALI_LOG_ERROR("widget class is NULL");
1023 widgetInstance = static_cast<Internal::Adaptor::Widget*>(cls->data);
1026 DALI_LOG_ERROR("widget instance is NULL");
1030 Dali::WidgetData *widgetData = widgetInstance->FindWidgetData(id);
1032 widgetData->SetArgs( bundleData );
1033 appcore_multiwindow_base_instance_exit(context);
1034 CheckEmptyInstance(data);
1037 static void CheckEmptyInstance(void* data)
1039 int cnt = appcore_multiwindow_base_instance_get_cnt();
1043 static_cast<Internal::Adaptor::Framework::Impl*>(data)->AppWidgetExit();
1047 static void InstanceResume(const char* classId, const char* id, bundle* bundleData)
1049 appcore_multiwindow_base_instance_h context;
1051 context = appcore_multiwindow_base_instance_find(id);
1055 DALI_LOG_ERROR("context not found: %s", id);
1059 appcore_multiwindow_base_instance_resume(context);
1061 SendUpdateStatus(classId, id, AUL_WIDGET_INSTANCE_EVENT_RESUME, NULL);
1062 if(!gForegroundState)
1064 aul_send_app_status_change_signal(getpid(), gAppId, gPackageId, "fg", "widgetapp" );
1065 gForegroundState = true;
1069 static void InstancePause(const char* classId, const char* id, bundle* bundleData)
1071 appcore_multiwindow_base_instance_h context;
1073 context = appcore_multiwindow_base_instance_find(id);
1077 DALI_LOG_ERROR("context not found: %s", id);
1081 appcore_multiwindow_base_instance_pause(context);
1083 if(gForegroundState)
1085 aul_send_app_status_change_signal(getpid(), gAppId, gPackageId, "bg", "widgetapp" );
1086 gForegroundState = false;
1090 static bool IsWidgetFeatureEnabled()
1092 static bool feature = false;
1093 static bool retrieved = false;
1096 if(retrieved == true)
1099 ret = system_info_get_platform_bool("http://tizen.org/feature/shell.appwidget", &feature);
1100 if(ret != SYSTEM_INFO_ERROR_NONE)
1102 DALI_LOG_ERROR("failed to get system info"); /* LCOV_EXCL_LINE */
1103 return false; /* LCOV_EXCL_LINE */
1111 #ifdef APPCORE_WATCH_AVAILABLE
1112 static bool WatchAppCreate(int width, int height, void *data)
1114 return static_cast<Framework*>(data)->Create();
1117 static void WatchAppTimeTick(watch_time_h time, void *data)
1119 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1120 WatchTime curTime(time);
1122 observer->OnTimeTick(curTime);
1125 static void WatchAppAmbientTick(watch_time_h time, void *data)
1127 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1128 WatchTime curTime(time);
1130 observer->OnAmbientTick(curTime);
1133 static void WatchAppAmbientChanged(bool ambient, void *data)
1135 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1137 observer->OnAmbientChanged(ambient);
1140 static void WatchAppControl(app_control_h app_control, void *data)
1142 Framework* framework = static_cast<Framework*>(data);
1143 Observer *observer = &framework->mObserver;
1144 bundle *bundleData = NULL;
1146 app_control_to_bundle(app_control, &bundleData);
1147 ProcessBundle(framework, bundleData);
1149 observer->OnReset();
1150 observer->OnAppControl(app_control);
1153 static void WatchAppTerminate(void *data)
1155 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1157 observer->OnTerminate();
1160 static void WatchAppPause(void *data)
1162 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1164 observer->OnPause();
1167 static void WatchAppResume(void *data)
1169 Observer *observer = &static_cast<Framework*>(data)->mObserver;
1171 observer->OnResume();
1179 #ifdef APPCORE_WATCH_AVAILABLE
1180 mWatchCallback.create = WatchAppCreate;
1181 mWatchCallback.app_control = WatchAppControl;
1182 mWatchCallback.terminate = WatchAppTerminate;
1183 mWatchCallback.pause = WatchAppPause;
1184 mWatchCallback.resume = WatchAppResume;
1185 mWatchCallback.time_tick = WatchAppTimeTick;
1186 mWatchCallback.ambient_tick = WatchAppAmbientTick;
1187 mWatchCallback.ambient_changed = WatchAppAmbientChanged;
1189 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
1190 AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
1191 AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
1192 AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
1194 ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
1201 #ifdef APPCORE_WATCH_AVAILABLE
1209 Impl( const Impl& impl );
1212 Impl& operator=( const Impl& impl );
1215 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
1216 : mObserver(observer),
1217 mInitialised(false),
1223 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
1226 bool featureFlag = true;
1227 system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
1229 if( featureFlag == false )
1231 set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
1233 #ifdef DALI_ELDBUS_AVAILABLE
1234 // Initialize ElDBus.
1239 mImpl = new Impl(this, type);
1242 Framework::~Framework()
1249 #ifdef DALI_ELDBUS_AVAILABLE
1257 bool Framework::Create()
1259 mInitialised = true;
1264 void Framework::Run()
1269 ret = mImpl->AppMain();
1270 if (ret != APP_ERROR_NONE)
1272 DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
1277 void Framework::Quit()
1282 bool Framework::IsMainLoopRunning()
1287 void Framework::AddAbortCallback( CallbackBase* callback )
1289 mImpl->mAbortCallBack = callback;
1292 std::string Framework::GetBundleName() const
1297 void Framework::SetBundleName(const std::string& name)
1302 std::string Framework::GetBundleId() const
1307 std::string Framework::GetResourcePath()
1309 std::string resourcePath = "";
1310 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
1311 resourcePath = app_get_resource_path();
1312 #else // For backwards compatibility with older Tizen versions
1314 // "DALI_APPLICATION_PACKAGE" is used to get the already configured Application package path.
1315 const char* environmentVariable = "DALI_APPLICATION_PACKAGE";
1316 char* value = getenv( environmentVariable );
1317 if ( value != NULL )
1319 resourcePath = value;
1321 #endif //TIZEN_PLATFORM_CONFIG_SUPPORTED
1323 return resourcePath;
1326 void Framework::SetBundleId(const std::string& id)
1331 void Framework::AbortCallback( )
1333 // if an abort call back has been installed run it.
1334 if (mImpl->mAbortCallBack)
1336 CallbackBase::Execute( *mImpl->mAbortCallBack );
1344 } // namespace Adaptor
1346 } // namespace Internal