X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Ftizen%2Fframework-tizen.cpp;h=7f425edb6f1d6d78ef19f64e4c1b177685fc743b;hb=refs%2Fchanges%2F73%2F103673%2F5;hp=898685352d326e155f9c86cfa34eaad3ab83978e;hpb=232fb8c916fe32f927e8ba3b38901ff0b7a691bc;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/tizen/framework-tizen.cpp b/adaptors/tizen/framework-tizen.cpp index 8986853..7f425ed 100644 --- a/adaptors/tizen/framework-tizen.cpp +++ b/adaptors/tizen/framework-tizen.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -22,7 +22,18 @@ #include #include #include -#include + +#include +#include +#include + +// CONDITIONAL INCLUDES +#ifdef APPCORE_WATCH_AVAILABLE +#include +#endif +#ifdef DALI_ELDBUS_AVAILABLE +#include +#endif // DALI_ELDBUS_AVAILABLE #include @@ -38,177 +49,303 @@ namespace Internal namespace Adaptor { +#if defined(DEBUG_ENABLED) namespace { - -/// Application Status Enum -enum -{ - APP_CREATE, - APP_TERMINATE, - APP_PAUSE, - APP_RESUME, - APP_RESET, - APP_LANGUAGE_CHANGE, -}; - -} // Unnamed namespace +Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New( Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS" ); +} // anonymous namespace +#endif /** * 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; -#if defined(TIZEN_SDK_2_3) - mEventCallback.app_control = AppControl; -#else - mEventCallback.service = AppService; -#endif - mEventCallback.low_memory = NULL; - mEventCallback.low_battery = NULL; - mEventCallback.device_orientation = DeviceRotated; - mEventCallback.language_changed = AppLanguageChange; - mEventCallback.region_format_changed = NULL; + mFramework = static_cast(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; + + if (mApplicationType == NORMAL) + { + ret = AppNormalMain(); + } + else + { + ret = AppWatchMain(); + } + return ret; + } - boost::function mAbortCallBack; - app_event_callback_s mEventCallback; + 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(data)->SlpAppStatusHandler(APP_CREATE); + return static_cast(data)->Create(); } - /** - * Called by AppCore when the application should terminate. - */ static void AppTerminate(void *data) { - static_cast(data)->SlpAppStatusHandler(APP_TERMINATE); + Observer *observer = &static_cast(data)->mObserver; + + observer->OnTerminate(); } - /** - * Called by AppCore when the application is paused. - */ static void AppPause(void *data) { - static_cast(data)->SlpAppStatusHandler(APP_PAUSE); + Observer *observer = &static_cast(data)->mObserver; + + observer->OnPause(); } - /** - * Called by AppCore when the application is resumed. - */ static void AppResume(void *data) { - static_cast(data)->SlpAppStatusHandler(APP_RESUME); + Observer *observer = &static_cast(data)->mObserver; + + observer->OnResume(); + } + + static void ProcessBundle(Framework* framework, bundle *bundleData) + { + if(bundleData == NULL) + { + return; + } + + // get bundle name + char* bundleName = const_cast(bundle_get_val(bundleData, "name")); + if(bundleName != NULL) + { + framework->SetBundleName(bundleName); + } + + // get bundle id + char* bundleId = const_cast(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 */ - -#if defined(TIZEN_SDK_2_3) static void AppControl(app_control_h app_control, void *data) -#else - static void AppService(service_h service, void *data) -#endif { Framework* framework = static_cast(data); + Observer *observer = &framework->mObserver; + bundle *bundleData = NULL; - if(framework) - { - bundle *bundleData = NULL; -#if defined(TIZEN_SDK_2_3) - app_control_to_bundle(app_control, &bundleData); -#else - service_to_bundle(service, &bundleData); + app_control_to_bundle(app_control, &bundleData); + ProcessBundle(framework, bundleData); + + observer->OnReset(); + observer->OnAppControl(app_control); + } + + int AppNormalMain() + { + 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; + } + + void AppNormalExit() + { + ui_app_exit(); + } + +#ifdef APPCORE_WATCH_AVAILABLE + static bool AppCreateWatch(int width, int height, void *data) + { + return static_cast(data)->Create(); + } + + static void AppTimeTick(watch_time_h time, void *data) + { + Observer *observer = &static_cast(data)->mObserver; + WatchTime curTime(time); + + observer->OnTimeTick(curTime); + } + + static void AppAmbientTick(watch_time_h time, void *data) + { + Observer *observer = &static_cast(data)->mObserver; + WatchTime curTime(time); + + observer->OnAmbientTick(curTime); + } + + static void AppAmbientChanged(bool ambient, void *data) + { + Observer *observer = &static_cast(data)->mObserver; + + observer->OnAmbientChanged(ambient); + } #endif - if(bundleData) - { - // get bundle name - char* bundleName = const_cast(bundle_get_val(bundleData, "name")); - if(bundleName != NULL) - { - framework->SetBundleName(bundleName); - } - - // get bundle id - char* bundleId = const_cast(bundle_get_val(bundleData, "id")); - if(bundleId != NULL) - { - framework->SetBundleId(bundleId); - } - } - framework->SlpAppStatusHandler(APP_RESET); - } + 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; } - /** - * Called by AppCore when the language changes on the device. - */ - static void AppLanguageChange(void* data) + void AppWatchExit() { - static_cast(data)->SlpAppStatusHandler(APP_LANGUAGE_CHANGE); +#ifdef APPCORE_WATCH_AVAILABLE + watch_app_exit(); +#endif } - static void DeviceRotated(app_device_orientation_e orientation, void *user_data) + static void AppLanguageChanged(app_event_info_h event, void *data) { - 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; - } + Observer *observer = &static_cast(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(data)->mObserver; + + observer->OnRegionChanged(); + } + + static void AppBatteryLow(app_event_info_h event, void *data) + { + Observer *observer = &static_cast(data)->mObserver; + + observer->OnBatteryLow(); + } + + static void AppMemoryLow(app_event_info_h event, void *data) + { + Observer *observer = &static_cast(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 ); + } +#ifdef DALI_ELDBUS_AVAILABLE + // Initialize ElDBus. + DALI_LOG_INFO( gDBusLogging, Debug::General, "Starting DBus Initialization\n" ); + eldbus_init(); +#endif InitThreads(); - mImpl = new Impl(this); + + mImpl = new Impl(this, type); } Framework::~Framework() @@ -218,21 +355,38 @@ Framework::~Framework() Quit(); } +#ifdef DALI_ELDBUS_AVAILABLE + // Shutdown ELDBus. + DALI_LOG_INFO( gDBusLogging, Debug::General, "Shutting down DBus\n" ); + eldbus_shutdown(); +#endif + 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() @@ -240,9 +394,9 @@ bool Framework::IsMainLoopRunning() return mRunning; } -void Framework::AddAbortCallback(boost::function callBack) +void Framework::AddAbortCallback( CallbackBase* callback ) { - mImpl->mAbortCallBack = callBack; + mImpl->mAbortCallBack = callback; } std::string Framework::GetBundleName() const @@ -270,7 +424,7 @@ void Framework::AbortCallback( ) // if an abort call back has been installed run it. if (mImpl->mAbortCallBack) { - mImpl->mAbortCallBack(); + CallbackBase::Execute( *mImpl->mAbortCallBack ); } else { @@ -278,50 +432,6 @@ void Framework::AbortCallback( ) } } -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