From 08f3300e336bf3ca9586eccc4634dc2a9ea23906 Mon Sep 17 00:00:00 2001 From: "jungmin76.park" Date: Thu, 18 Apr 2013 08:33:45 +0900 Subject: [PATCH] implement LifeDuration feature Change-Id: Iba4404348bb3d7c880626150702b224e8aab3567 Signed-off-by: jungmin76.park --- src/app/FApp_ServiceAppImpl.cpp | 69 +++++++++++++++++++++++++++++++++++++++ src/app/inc/FApp_ServiceAppImpl.h | 29 ++++++++++++++-- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/app/FApp_ServiceAppImpl.cpp b/src/app/FApp_ServiceAppImpl.cpp index da9267b..48f19bf 100644 --- a/src/app/FApp_ServiceAppImpl.cpp +++ b/src/app/FApp_ServiceAppImpl.cpp @@ -35,6 +35,7 @@ #include "FAppPkg_PackageManagerImpl.h" #include "FApp_AppManagerImpl.h" #include "FApp_TemplateUtil.h" +#include "FApp_IAppEventListener.h" using namespace Tizen::App::Package; using namespace Tizen::Base; @@ -44,6 +45,8 @@ using namespace Tizen::System; const wchar_t USE_UI_KEY[] = L"UseUi"; const wchar_t USE_UI_VAL_TRUE[] = L"True"; +const wchar_t LIFE_DURATION_KEY[] = L"LifeDuration"; +const int LIFE_DURATION_MSEC_MAX = 30000; static const RequestId HANDLER_REQUEST_ALARMID = 2; @@ -59,6 +62,9 @@ _ServiceAppImpl* _ServiceAppImpl::__pServiceAppImpl = null; _ServiceAppImpl::_ServiceAppImpl(ServiceApp* pServiceApp) : __pAppImpl(_AppImpl::GetInstance()) , __pServiceApp(pServiceApp) + , __pLifeDurationEventListener(null) + , __pLifeDurationTimer(null) + , __lifeDuration(0) { __pServiceAppImpl = this; SysTryReturnVoidResult(NID_APP, __pAppImpl, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed."); @@ -68,6 +74,11 @@ _ServiceAppImpl::_ServiceAppImpl(ServiceApp* pServiceApp) _ServiceAppImpl::~_ServiceAppImpl(void) { __pServiceAppImpl = null; + if( __pLifeDurationTimer ) + { + __pLifeDurationTimer->Cancel(); + delete __pLifeDurationTimer; + } } @@ -135,6 +146,11 @@ _ServiceAppImpl::OnService(service_s* service, bool initial) { free(pOperation); } + + if( __lifeDuration > 0) + { + SetLifeDurationTimer(__lifeDuration); + } } void @@ -231,6 +247,18 @@ _ServiceAppImpl::OnAppInitializing(void) } } + r = pInfo->GetValue(LIFE_DURATION_KEY, pFeature); + if (r == E_SUCCESS) + { + const String& val = pFeature->GetValue(); + r = Integer::Parse(val, __lifeDuration); + if( r == E_SUCCESS ) + { + __lifeDuration = ( __lifeDuration > LIFE_DURATION_MSEC_MAX ) ? LIFE_DURATION_MSEC_MAX : __lifeDuration; + SysLog(NID_APP, "LifeDuration is (%d)", __lifeDuration); + } + } + _DeleteCollectionMapValue(*pInfo); delete pInfo; } @@ -253,4 +281,45 @@ _ServiceAppImpl::OnServiceAppImplTerminating(bool forcedTermination) return __pServiceApp->OnAppTerminating(*(AppRegistry::GetInstance()), forcedTermination); } +void +_ServiceAppImpl::SetLifeDurationTimer(int lifeDuration) +{ + if( lifeDuration <= 0) + { + return; + } + + if( __pLifeDurationTimer == null) + { + __pLifeDurationTimer = new Timer; + __pLifeDurationTimer->Construct(*this); + SysLog(NID_APP, "Life duration timer is constructed."); + } + else + { + __pLifeDurationTimer->Cancel(); + SysLog(NID_APP, "Life duration timer is cancelled.", lifeDuration ); + } + __pLifeDurationTimer->Start(__lifeDuration); + SysLog(NID_APP, "Life duration timer is started with timeout.(%d)", lifeDuration ); +} + +void +_ServiceAppImpl::OnTimerExpired(Timer& timer) +{ + SysLog(NID_APP, "Life duration timer is expired, so terminating the application."); + timer.Cancel(); + if( __pLifeDurationEventListener) + { + __pLifeDurationEventListener->OnApplicationTerminated(L"", 0); + } + App::GetInstance()->Terminate(); +} + +void +_ServiceAppImpl::SetLifeDurationEventListener(_IAppEventListener* pListener) +{ + __pLifeDurationEventListener = pListener; +} + } } //Tizen::App diff --git a/src/app/inc/FApp_ServiceAppImpl.h b/src/app/inc/FApp_ServiceAppImpl.h index 2f2f797..ec817c2 100644 --- a/src/app/inc/FApp_ServiceAppImpl.h +++ b/src/app/inc/FApp_ServiceAppImpl.h @@ -26,15 +26,24 @@ #include #include - +#include +#include #include "FApp_IAppImpl.h" namespace Tizen { namespace Base { namespace Collection { class IList; } } } -namespace Tizen { namespace Base { namespace Runtime { class _EventDispatcher; } } } +namespace Tizen { namespace Base { namespace Runtime +{ +class Timer; +class IEventListener; +class _EventDispatcher; +}}} + namespace Tizen { namespace App { +class _IAppEventListener; + /** * @class _ServiceAppImpl * @brief This class is the Impl class of a ServiceApp class. @@ -45,6 +54,8 @@ namespace Tizen { namespace App class _OSP_EXPORT_ _ServiceAppImpl : public Tizen::Base::Object , public Tizen::App::_IAppImpl + , public Tizen::Base::Runtime::ITimerEventListener + , virtual public Tizen::Base::Runtime::IEventListener { public: /** @@ -171,6 +182,9 @@ public: */ result Execute(void); + + void SetLifeDurationEventListener(_IAppEventListener* pListener); + private: /** * This is the default constructor for this class. @@ -203,6 +217,11 @@ private: */ virtual ~_ServiceAppImpl(void); + virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer); + + void SetLifeDurationTimer(int lifeDuration); + + private: static _ServiceAppImpl* __pServiceAppImpl; @@ -210,6 +229,12 @@ private: ServiceApp* __pServiceApp; + _IAppEventListener* __pLifeDurationEventListener; + + Tizen::Base::Runtime::Timer* __pLifeDurationTimer; + + int __lifeDuration; + friend class ServiceApp; }; // _ServiceAppImpl -- 2.7.4