/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <bundle.h>
#include <Ecore.h>
-#ifdef OVER_TIZEN_SDK_2_2
#include <system_info.h>
#include <app_control_internal.h>
+#include <bundle_internal.h>
+#ifdef APPCORE_WATCH_AVAILABLE
+#include <appcore-watch/watch_app.h>
#endif
+#if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
+#include <tzplatform_config.h>
+#endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
+
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
namespace Adaptor
{
-namespace
-{
-
-/// Application Status Enum
-enum
-{
- APP_CREATE,
- APP_TERMINATE,
- APP_PAUSE,
- APP_RESUME,
- APP_RESET,
- APP_CONTROL,
- APP_LANGUAGE_CHANGE,
- APP_DEVICE_ROTATED,
- APP_REGION_CHANGED,
- APP_BATTERY_LOW,
- APP_MEMORY_LOW
-};
-
-} // Unnamed namespace
-
/**
* Impl to hide EFL data members
*/
struct Framework::Impl
{
- // Constructor
-
- Impl(void* data)
+// Constructor
+ Impl(void* data, Type type )
: mAbortCallBack( NULL ),
mCallbackManager( NULL )
{
- mEventCallback.create = AppCreate;
- mEventCallback.terminate = AppTerminate;
- mEventCallback.pause = AppPause;
- mEventCallback.resume = AppResume;
-#ifndef OVER_TIZEN_SDK_2_2
- mEventCallback.service = AppService;
-
- mEventCallback.low_memory = NULL;
- mEventCallback.low_battery = NULL;
- mEventCallback.device_orientation = AppDeviceRotated;
- mEventCallback.language_changed = AppLanguageChanged;
- mEventCallback.region_format_changed = NULL;
-
-#else
- mEventCallback.app_control = AppControl;
-
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, data);
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, data);
- ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, data);
- ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, data);
- ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, data);
+ mFramework = static_cast<Framework*>(data);
+#ifndef APPCORE_WATCH_AVAILABLE
+ if ( type == WATCH )
+ {
+ throw Dali::DaliException( "", "Watch Application is not supported." );
+ }
#endif
-
+ mApplicationType = type;
mCallbackManager = CallbackManager::New();
}
delete mCallbackManager;
}
- // Data
+ int AppMain()
+ {
+ int ret;
+
+ if (mApplicationType == NORMAL)
+ {
+ ret = AppNormalMain();
+ }
+ else
+ {
+ ret = AppWatchMain();
+ }
+ return ret;
+ }
+ void AppExit()
+ {
+ if (mApplicationType == NORMAL)
+ {
+ AppNormalExit();
+ }
+ else
+ {
+ AppWatchExit();
+ }
+ }
+
+
+ // Data
+ Type mApplicationType;
CallbackBase* mAbortCallBack;
CallbackManager *mCallbackManager;
-#ifndef OVER_TIZEN_SDK_2_2
- app_event_callback_s mEventCallback;
-#else
- ui_app_lifecycle_callback_s mEventCallback;
+ Framework* mFramework;
app_event_handler_h handlers[5];
+ ui_app_lifecycle_callback_s mEventCallback;
+#ifdef APPCORE_WATCH_AVAILABLE
+ watch_app_lifecycle_callback_s mWatchCallback;
#endif
- /**
- * Called by AppCore on application creation.
- */
static bool AppCreate(void *data)
{
- return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);
+ return static_cast<Framework*>(data)->Create();
}
- /**
- * Called by AppCore when the application should terminate.
- */
static void AppTerminate(void *data)
{
- static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnTerminate();
}
- /**
- * Called by AppCore when the application is paused.
- */
static void AppPause(void *data)
{
- static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnPause();
}
- /**
- * Called by AppCore when the application is resumed.
- */
static void AppResume(void *data)
{
- static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnResume();
}
static void ProcessBundle(Framework* framework, bundle *bundleData)
}
}
-#ifndef OVER_TIZEN_SDK_2_2
/**
* Called by AppCore when the application is launched from another module (e.g. homescreen).
* @param[in] b the bundle data which the launcher module sent
*/
- static void AppService(service_h service, void *data)
+ static void AppControl(app_control_h app_control, void *data)
{
Framework* framework = static_cast<Framework*>(data);
-
- if(framework == NULL)
- {
- return;
- }
+ Observer *observer = &framework->mObserver;
bundle *bundleData = NULL;
- service_to_bundle(service, &bundleData);
+ app_control_to_bundle(app_control, &bundleData);
ProcessBundle(framework, bundleData);
- framework->AppStatusHandler(APP_RESET, NULL);
+ observer->OnReset();
+ observer->OnAppControl(app_control);
}
- static void AppLanguageChanged(void* user_data)
+ int AppNormalMain()
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
+ int ret;
+
+ mEventCallback.create = AppCreate;
+ mEventCallback.terminate = AppTerminate;
+ mEventCallback.pause = AppPause;
+ mEventCallback.resume = AppResume;
+ mEventCallback.app_control = AppControl;
+
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
+ ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
+ ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
+
+ ret = ui_app_main(*mFramework->mArgc, *mFramework->mArgv, &mEventCallback, mFramework);
+
+ return ret;
}
- static void AppDeviceRotated(app_device_orientation_e orientation, void *user_data)
+ void AppNormalExit()
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
+ ui_app_exit();
}
-#else
+#ifdef APPCORE_WATCH_AVAILABLE
+ static bool AppCreateWatch(int width, int height, void *data)
+ {
+ return static_cast<Framework*>(data)->Create();
+ }
- /**
- * Called by AppCore when the application is launched from another module (e.g. homescreen).
- * @param[in] b the bundle data which the launcher module sent
- */
- static void AppControl(app_control_h app_control, void *data)
+ static void AppTimeTick(watch_time_h time, void *data)
{
- Framework* framework = static_cast<Framework*>(data);
- if(framework == NULL)
- {
- return;
- }
- bundle *bundleData = NULL;
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+ WatchTime curTime(time);
- app_control_to_bundle(app_control, &bundleData);
- ProcessBundle(framework, bundleData);
+ observer->OnTimeTick(curTime);
+ }
+
+ static void AppAmbientTick(watch_time_h time, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+ WatchTime curTime(time);
- framework->AppStatusHandler(APP_RESET, NULL);
- framework->AppStatusHandler(APP_CONTROL, app_control);
+ observer->OnAmbientTick(curTime);
}
- static void AppLanguageChanged(app_event_info_h event_info, void *user_data)
+ static void AppAmbientChanged(bool ambient, void *data)
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnAmbientChanged(ambient);
}
+#endif
- static void AppDeviceRotated(app_event_info_h event_info, void *user_data)
+ int AppWatchMain()
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_DEVICE_ROTATED, NULL);
+ int ret = true;
+
+#ifdef APPCORE_WATCH_AVAILABLE
+ mWatchCallback.create = AppCreateWatch;
+ mWatchCallback.app_control = AppControl;
+ mWatchCallback.terminate = AppTerminate;
+ mWatchCallback.pause = AppPause;
+ mWatchCallback.resume = AppResume;
+ mWatchCallback.time_tick = AppTimeTick;
+ mWatchCallback.ambient_tick = AppAmbientTick;
+ mWatchCallback.ambient_changed = AppAmbientChanged;
+
+ watch_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, AppBatteryLow, mFramework);
+ watch_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, AppMemoryLow, mFramework);
+ watch_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
+ watch_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
+
+ ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
+#endif
+ return ret;
}
- static void AppRegionChanged(app_event_info_h event_info, void *user_data)
+ void AppWatchExit()
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_REGION_CHANGED, NULL);
+#ifdef APPCORE_WATCH_AVAILABLE
+ watch_app_exit();
+#endif
}
- static void AppBatteryLow(app_event_info_h event_info, void *user_data)
+ static void AppLanguageChanged(app_event_info_h event, void *data)
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_BATTERY_LOW, NULL);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnLanguageChanged();
}
- static void AppMemoryLow(app_event_info_h event_info, void *user_data)
+ static void AppDeviceRotated(app_event_info_h event_info, void *data)
{
- static_cast<Framework*>(user_data)->AppStatusHandler(APP_MEMORY_LOW, NULL);
}
-#endif
+ static void AppRegionChanged(app_event_info_h event, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnRegionChanged();
+ }
+
+ static void AppBatteryLow(app_event_info_h event, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnBatteryLow();
+ }
+
+ static void AppMemoryLow(app_event_info_h event, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnMemoryLow();
+ }
private:
// Undefined
Impl& operator=( const Impl& impl );
};
-Framework::Framework( Framework::Observer& observer, int *argc, char ***argv )
+Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
: mObserver(observer),
mInitialised(false),
mRunning(false),
mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
mImpl(NULL)
{
-
-#ifdef OVER_TIZEN_SDK_2_2
bool featureFlag = true;
system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
if( featureFlag == false )
{
set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
- throw Dali::DaliException( "", "OpenGL ES 2.0 is not supported." );
}
-#endif
-
InitThreads();
- mImpl = new Impl(this);
+
+ mImpl = new Impl(this, type);
}
Framework::~Framework()
delete mImpl;
}
+bool Framework::Create()
+{
+ mInitialised = true;
+ mObserver.OnInit();
+ return true;
+}
+
void Framework::Run()
{
mRunning = true;
+ int ret;
-#ifndef OVER_TIZEN_SDK_2_2
- app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
-
-#else
- int ret = ui_app_main(*mArgc, *mArgv, &mImpl->mEventCallback, this);
+ ret = mImpl->AppMain();
if (ret != APP_ERROR_NONE)
{
- DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d", ret);
+ DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
}
-#endif
-
mRunning = false;
}
void Framework::Quit()
{
- app_efl_exit();
+ mImpl->AppExit();
}
bool Framework::IsMainLoopRunning()
return mBundleId;
}
+std::string Framework::GetResourcePath()
+{
+ std::string resourcePath = "";
+#if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
+ resourcePath = app_get_resource_path();
+#endif //TIZEN_PLATFORM_CONFIG_SUPPORTED
+
+ return resourcePath;
+}
+
void Framework::SetBundleId(const std::string& id)
{
mBundleId = id;
}
}
-bool Framework::AppStatusHandler(int type, void *bundleData)
-{
- switch (type)
- {
- case APP_CREATE:
- {
- mInitialised = true;
-
- // Connect to abnormal exit signals
- mAbortHandler.AbortOnSignal( SIGINT );
- mAbortHandler.AbortOnSignal( SIGQUIT );
- mAbortHandler.AbortOnSignal( SIGKILL );
- mAbortHandler.AbortOnSignal( SIGTERM );
- mAbortHandler.AbortOnSignal( SIGHUP );
-
- mObserver.OnInit();
- break;
- }
-
- case APP_RESET:
- {
- mObserver.OnReset();
- break;
- }
-
- case APP_RESUME:
- {
- mObserver.OnResume();
- break;
- }
-
- case APP_TERMINATE:
- {
- mObserver.OnTerminate();
- break;
- }
-
- case APP_PAUSE:
- {
- mObserver.OnPause();
- break;
- }
-
- case APP_CONTROL:
- {
- mObserver.OnAppControl(bundleData);
- break;
- }
-
- case APP_LANGUAGE_CHANGE:
- {
- mObserver.OnLanguageChanged();
- break;
- }
-
- case APP_REGION_CHANGED:
- {
- mObserver.OnRegionChanged();
- break;
- }
-
- case APP_BATTERY_LOW:
- {
- mObserver.OnBatteryLow();
- break;
- }
-
- case APP_MEMORY_LOW:
- {
- mObserver.OnMemoryLow();
- break;
- }
-
- default:
- break;
- }
-
- return true;
-}
-
} // namespace Adaptor
} // namespace Internal