implement LifeDuration feature
authorjungmin76.park <jungmin76.park@samsung.com>
Wed, 17 Apr 2013 23:33:45 +0000 (08:33 +0900)
committerGerrit Code Review <gerrit2@kim11>
Thu, 18 Apr 2013 08:51:39 +0000 (17:51 +0900)
Change-Id: Iba4404348bb3d7c880626150702b224e8aab3567
Signed-off-by: jungmin76.park <jungmin76.park@samsung.com>
src/app/FApp_ServiceAppImpl.cpp
src/app/inc/FApp_ServiceAppImpl.h

index da9267b..48f19bf 100644 (file)
@@ -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<String, _AppFeatureInfoImpl>(*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
index 2f2f797..ec817c2 100644 (file)
 #include <app.h>
 
 #include <FAppServiceApp.h>
-
+#include <FBaseRtIEventListener.h>
+#include <FBaseRtITimerEventListener.h>
 #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