, __eventListenerCount(0)
, __pUiLibrary(null)
, __pX11Library(null)
- , __pAppEventList(null)
{
SysLog(NID_APP, "");
}
AppControl* pAc = null;
+ /*
+ pAc = pRegs->GetTizenAppControlN(aId, oId);
+ if (pAc != null)
+ {
+ SetLastResult(E_SUCCESS);
+ return pAc;
+ }
+ */
+
pAc = pRegs->GetNativeAppControlN(aId, oId);
if (pAc != null)
{
}
+///////////////////////////////////////////////////////////////////////////////
+// LifecycleManager begins.
+///////////////////////////////////////////////////////////////////////////////
+
void
-_AppManagerImpl::AppEventCallback(app_context_h app_context, app_context_event_e event, void* pData)
+_AppLifecycleManager::Init(void)
{
- _AppManagerImpl* pImpl = static_cast<_AppManagerImpl*>(pData);
- if (pImpl == null || pImpl->__pAppEventList == null)
- {
- SysLogException(NID_APP, E_SYSTEM, "Wrong _AppManagerImpl state.");
- return;
- }
+ aul_listen_app_launch_signal(LaunchCallback, this);
+ aul_listen_app_dead_signal(TerminateCallback, this);
+}
- std::unique_ptr< IEnumeratorT<_IAppEventListener*> > pEnum(pImpl->__pAppEventList->GetEnumeratorN());
+void
+_AppLifecycleManager::Fini(void)
+{
+ aul_listen_app_launch_signal(NULL, NULL);
+ aul_listen_app_dead_signal(NULL, NULL);
+}
- if (pEnum.get())
+result
+_AppLifecycleManager::AddListener(_IAppEventListener& listener)
+{
+ if (__pEventList == null)
{
- char* pAppId = NULL;
- app_context_get_app_id(app_context, &pAppId);
- if (pAppId == NULL)
- {
- SysLogException(NID_APP, E_SYSTEM, "Cannot acquire appId.");
- return;
- }
+ std::unique_ptr< LinkedListT<_IAppEventListener*> > pAppEventList(new LinkedListT<_IAppEventListener*>);
+ SysTryReturnResult(NID_APP, pAppEventList, E_SYSTEM, "Memory allocation failed.");
+
+ Init();
- const String appId = pAppId;
+ __pEventList = pAppEventList.release();
+ SysLog(NID_APP, "Registered app event listener.");
+ }
- free(pAppId);
+ return __pEventList->Add(&listener);
+}
- pid_t pid = -1;
- app_context_get_pid(app_context, &pid);
- const int val = event;
+result
+_AppLifecycleManager::RemoveListener(_IAppEventListener& listener)
+{
+ SysTryReturnResult(NID_APP,__pEventList != null, E_OBJ_NOT_FOUND, "_IEventListener list is empty.");
- // loop unfolding
- switch (val)
- {
- case APP_CONTEXT_EVENT_LAUNCHED:
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- _IAppEventListener* pListener = null;
- pEnum->GetCurrent(pListener);
+ result r = __pEventList->Remove(&listener);
- pListener->OnApplicationLaunched(appId, pid);
- }
- break;
- case APP_CONTEXT_EVENT_TERMINATED:
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- _IAppEventListener* pListener = null;
- pEnum->GetCurrent(pListener);
+ if (__pEventList->GetCount() == 0)
+ {
+ Fini();
- pListener->OnApplicationTerminated(appId, pid);
- }
- break;
- default:
- SysLog(NID_APP, "Invalid state.");
- break;
- }
+ delete __pEventList;
+ __pEventList = null;
}
- SysLog(NID_APP, "Finished invoking application event listener.");
+ return r;
}
-result
-_AppManagerImpl::AddAppEventListener(_IAppEventListener& listener)
+int
+_AppLifecycleManager::LaunchCallback(int pid, void* pData)
{
- if (__pAppEventList == null)
+ _AppLifecycleManager* pImpl = static_cast<_AppLifecycleManager*>(pData);
+ if (pImpl == null || pImpl->__pEventList == null)
{
- std::unique_ptr< LinkedListT<_IAppEventListener*> > pAppEventList(new LinkedListT<_IAppEventListener*>);
- SysTryReturnResult(NID_APP, pAppEventList, E_SYSTEM, "Memory allocation failed.");
+ SysLogException(NID_APP, E_SYSTEM, "Wrong _AppLifecycleImpl state.");
+ return -1;
+ }
- const int ret = app_manager_set_app_context_event_cb(_AppManagerImpl::AppEventCallback, this);
- SysTryReturnResult(NID_APP, ret == APP_MANAGER_ERROR_NONE, E_SYSTEM, "Context registration failed.");
+ char appId[255];
+ int ret = aul_app_get_appid_bypid(pid, appId, sizeof(appId));
+ if (ret != AUL_R_OK)
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Cannot acquire appId.");
+ return -1;
+ }
- __pAppEventList = pAppEventList.release();
- SysLog(NID_APP, "Registered app event listener.");
+ std::unique_ptr< IEnumeratorT<_IAppEventListener*> > pEnum(pImpl->__pEventList->GetEnumeratorN());
+ if (pEnum.get())
+ {
+ const String tmp = appId;
+ pImpl->__map.Add(pid, tmp);
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ _IAppEventListener* pListener = null;
+ pEnum->GetCurrent(pListener);
+
+ pListener->OnApplicationLaunched(tmp, pid);
+ }
}
- return __pAppEventList->Add(&listener);
+ SysLog(NID_APP, "Finished invoking application event listener for %s, %d.", appId, pid);
+
+ return 0;
}
-result
-_AppManagerImpl::RemoveAppEventListener(_IAppEventListener& listener)
+int
+_AppLifecycleManager::TerminateCallback(int pid, void* pData)
{
- result r = E_SUCCESS;
-
- SysTryReturnResult(NID_APP,__pAppEventList != null, E_OBJ_NOT_FOUND, "_IAppEventListener list is empty.");
+ _AppLifecycleManager* pImpl = static_cast<_AppLifecycleManager*>(pData);
+ if (pImpl == null || pImpl->__pEventList == null)
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Wrong _AppLifecycleImpl state.");
+ return -1;
+ }
- r = __pAppEventList->Remove(&listener);
+ // terminate callback cannot acquire appId from pid
+ String tmp;
+ result r = pImpl->__map.GetValue(pid, tmp);
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Cannot acquire appId from pid %d.", pid);
+ return -1;
+ }
- if (__pAppEventList->GetCount() == 0)
+ std::unique_ptr< IEnumeratorT<_IAppEventListener*> > pEnum(pImpl->__pEventList->GetEnumeratorN());
+ if (pEnum.get())
{
- app_manager_unset_app_context_event_cb();
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ _IAppEventListener* pListener = null;
+ pEnum->GetCurrent(pListener);
- delete __pAppEventList;
- __pAppEventList = null;
+ pListener->OnApplicationTerminated(tmp, pid);
+ }
}
- return E_SUCCESS;
+ SysLog(NID_APP, "Finished invoking application event listener for %ls, %d.", tmp.GetPointer(), pid);
+
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// LifecycleManager ends.
+///////////////////////////////////////////////////////////////////////////////
+
+
+result
+_AppManagerImpl::AddAppEventListener(_IAppEventListener& listener)
+{
+ return __lifeManager.AddListener(listener);
+}
+
+result
+_AppManagerImpl::RemoveAppEventListener(_IAppEventListener& listener)
+{
+ return __lifeManager.RemoveListener(listener);
}
#include <appfw/app_context.h>
#include <FOspConfig.h>
-#include <FBaseColIListT.h>
-#include <FBaseColIList.h>
#include <FBaseObject.h>
#include <FBaseString.h>
+#include <FBaseColIListT.h>
+#include <FBaseColIList.h>
+#include <FBaseColLinkedListT.h>
+#include <FBaseColHashMapT.h>
#include <FBaseRtIEventListener.h>
#include <FAppAppManager.h>
#include <FBaseSysLog.h>
class _IAppEventListener;
class _AppManagerEventArg;
+
+class _AppLifecycleManager
+{
+public:
+ _AppLifecycleManager(void) : __pEventList(null)
+ {
+ __map.Construct();
+ }
+
+ ~_AppLifecycleManager(void) {}
+
+ result AddListener(_IAppEventListener& listener);
+
+ result RemoveListener(_IAppEventListener& listener);
+
+private:
+ void Init(void);
+
+ void Fini(void);
+
+ static int LaunchCallback(int pid, void* pData);
+
+ static int TerminateCallback(int pid, void* pData);
+
+private:
+ Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
+ Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
+};
+
class _OSP_EXPORT_ _AppManagerImpl
: public Tizen::Base::Object
, public _IAppManagerServiceEventListener
Tizen::Base::Runtime::_LibraryImpl* __pX11Library;
static Tizen::Base::Runtime::_LibraryImpl* __pEcoreXLibrary;
static Tizen::Base::Runtime::_LibraryImpl* __pEcoreLibrary;
- Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pAppEventList;
+ _AppLifecycleManager __lifeManager;
_AppManagerEvent __appManagerEvent;
Tizen::Base::Collection::LinkedListT<IActiveAppEventListener*> __activeAppEventListenerList;