/*
- * 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 <app.h>
#include <bundle.h>
#include <Ecore.h>
-#include <boost/bind.hpp>
+
+#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>
namespace Adaptor
{
-namespace
-{
-
-/// Application Status Enum
-enum
-{
- APP_CREATE,
- APP_TERMINATE,
- APP_PAUSE,
- APP_RESUME,
- APP_RESET,
- APP_LANGUAGE_CHANGE,
-};
-
-} // 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;
- mEventCallback.service = AppService;
- mEventCallback.low_memory = NULL;
- mEventCallback.low_battery = NULL;
- mEventCallback.device_orientation = DeviceRotated;
- mEventCallback.language_changed = AppLanguageChange;
- mEventCallback.region_format_changed = NULL;
+ 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();
}
~Impl()
{
+ delete mAbortCallBack;
+
// we're quiting the main loop so
// mCallbackManager->RemoveAllCallBacks() does not need to be called
// to delete our abort handler
delete mCallbackManager;
}
- // Data
+ int AppMain()
+ {
+ int ret;
- boost::function<void(void)> mAbortCallBack;
- app_event_callback_s mEventCallback;
+ 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;
- // Static methods
- /**
- * Called by AppCore on application creation.
- */
+ 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
+
static bool AppCreate(void *data)
{
- return static_cast<Framework*>(data)->SlpAppStatusHandler(APP_CREATE);
+ return static_cast<Framework*>(data)->Create();
}
- /**
- * Called by AppCore when the application should terminate.
- */
static void AppTerminate(void *data)
{
- static_cast<Framework*>(data)->SlpAppStatusHandler(APP_TERMINATE);
+ 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)->SlpAppStatusHandler(APP_PAUSE);
+ 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)->SlpAppStatusHandler(APP_RESUME);
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnResume();
+ }
+
+ static void ProcessBundle(Framework* framework, bundle *bundleData)
+ {
+ if(bundleData == NULL)
+ {
+ return;
+ }
+
+ // get bundle name
+ char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
+ if(bundleName != NULL)
+ {
+ framework->SetBundleName(bundleName);
+ }
+
+ // get bundle id
+ char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
+ if(bundleId != NULL)
+ {
+ framework->SetBundleId(bundleId);
+ }
}
/**
* 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);
+ Observer *observer = &framework->mObserver;
+ bundle *bundleData = NULL;
- if(framework)
- {
- bundle *bundleData = NULL;
- service_to_bundle(service, &bundleData);
-
- if(bundleData)
- {
- // get bundle name
- char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
- if(bundleName != NULL)
- {
- framework->SetBundleName(bundleName);
- }
-
- // get bundle id
- char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
- if(bundleId != NULL)
- {
- framework->SetBundleId(bundleId);
- }
- }
- framework->SlpAppStatusHandler(APP_RESET);
- }
+ app_control_to_bundle(app_control, &bundleData);
+ ProcessBundle(framework, bundleData);
+
+ observer->OnReset();
+ observer->OnAppControl(app_control);
}
- /**
- * Called by AppCore when the language changes on the device.
- */
- static void AppLanguageChange(void* data)
+ int AppNormalMain()
{
- static_cast<Framework*>(data)->SlpAppStatusHandler(APP_LANGUAGE_CHANGE);
+ 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 DeviceRotated(app_device_orientation_e orientation, void *user_data)
+ void AppNormalExit()
{
- switch(orientation)
- {
- case APP_DEVICE_ORIENTATION_0:
- break;
- case APP_DEVICE_ORIENTATION_90:
- break;
- case APP_DEVICE_ORIENTATION_180:
- break;
- case APP_DEVICE_ORIENTATION_270:
- break;
- }
+ ui_app_exit();
+ }
+
+#ifdef APPCORE_WATCH_AVAILABLE
+ static bool AppCreateWatch(int width, int height, void *data)
+ {
+ return static_cast<Framework*>(data)->Create();
+ }
+
+ static void AppTimeTick(watch_time_h time, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+ WatchTime curTime(time);
+
+ observer->OnTimeTick(curTime);
+ }
+
+ static void AppAmbientTick(watch_time_h time, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+ WatchTime curTime(time);
+
+ observer->OnAmbientTick(curTime);
+ }
+
+ static void AppAmbientChanged(bool ambient, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnAmbientChanged(ambient);
+ }
+#endif
+
+ int AppWatchMain()
+ {
+ 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;
+ }
+
+ void AppWatchExit()
+ {
+#ifdef APPCORE_WATCH_AVAILABLE
+ watch_app_exit();
+#endif
+ }
+
+ static void AppLanguageChanged(app_event_info_h event, void *data)
+ {
+ Observer *observer = &static_cast<Framework*>(data)->mObserver;
+
+ observer->OnLanguageChanged();
+ }
+
+ static void AppDeviceRotated(app_event_info_h event_info, void *data)
+ {
+ }
+
+ 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( const Impl& impl );
+
+ // Undefined
+ Impl& operator=( const Impl& impl );
};
-Framework::Framework(Framework::Observer& observer, int *argc, char ***argv, const std::string& name)
+Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
: mObserver(observer),
mInitialised(false),
mRunning(false),
mArgc(argc),
mArgv(argv),
- mName(name),
mBundleName(""),
mBundleId(""),
- mAbortHandler(boost::bind(&Framework::AbortCallback, this)),
+ mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
mImpl(NULL)
{
+ 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 );
+ }
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;
- app_efl_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\n", ret);
+ }
mRunning = false;
}
void Framework::Quit()
{
- app_efl_exit();
+ mImpl->AppExit();
}
bool Framework::IsMainLoopRunning()
return mRunning;
}
-void Framework::AddAbortCallback(boost::function<void(void)> callBack)
+void Framework::AddAbortCallback( CallbackBase* callback )
{
- mImpl->mAbortCallBack = callBack;
+ mImpl->mAbortCallBack = callback;
}
std::string Framework::GetBundleName() const
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;
// if an abort call back has been installed run it.
if (mImpl->mAbortCallBack)
{
- mImpl->mAbortCallBack();
+ CallbackBase::Execute( *mImpl->mAbortCallBack );
}
else
{
}
}
-bool Framework::SlpAppStatusHandler(int type)
-{
- switch (type)
- {
- case APP_CREATE:
- {
- mInitialised = true;
-
- // Connect to abnormal exit signals
- mAbortHandler.AbortOnSignal( SIGINT );
- mAbortHandler.AbortOnSignal( SIGQUIT );
- mAbortHandler.AbortOnSignal( SIGKILL );
-
- 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_LANGUAGE_CHANGE:
- mObserver.OnLanguageChanged();
- break;
-
- default:
- break;
- }
-
- return true;
-}
-
} // namespace Adaptor
} // namespace Internal