Refactor AppRegistry to support multi-thread concurrency
[platform/framework/native/appfw.git] / src / io / FIo_FileEventManagerImpl.cpp
index 5fd8111..5f75e97 100644 (file)
@@ -57,19 +57,23 @@ _FileEventManagerImpl::_FileEventManagerImpl(void)
 _FileEventManagerImpl::~_FileEventManagerImpl(void)
 {
        SysLog(NID_IO, "_FileEventManagerImpl: 0x%x", this);
-       _FileEventDispatcher* pDispatcher = _FileEventDispatcher::GetInstance();
 
-       IMapEnumerator* pMapEnum = __pWatchList->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS)
+       if (__pWatchList != null)
        {
-               Integer* pWd = dynamic_cast< Integer* >(pMapEnum->GetValue());
-               if (pWd != null)
+               _FileEventDispatcher* pDispatcher = _FileEventDispatcher::GetInstance();
+               IMapEnumerator* pMapEnum = __pWatchList->GetMapEnumeratorN();
+               while (pMapEnum->MoveNext() == E_SUCCESS)
                {
-                       SysLog(NID_IO, "inotify fd: %d, watch description: %d", __inotifyFd, pWd->ToInt());
-                       int res = inotify_rm_watch(__inotifyFd, pWd->ToInt());
-                       SysTryLog(NID_IO, res == 0, "inotify_rm_watch() failed, errno: %d (%s)", errno, strerror(errno));
-                       pDispatcher->RemoveFileEventInfo(*pWd);
+                       Integer* pWd = dynamic_cast< Integer* >(pMapEnum->GetValue());
+                       if (pWd != null)
+                       {
+                               SysLog(NID_IO, "inotify fd: %d, watch description: %d", __inotifyFd, pWd->ToInt());
+                               int res = inotify_rm_watch(__inotifyFd, pWd->ToInt());
+                               SysTryLog(NID_IO, res == 0, "inotify_rm_watch() failed, errno: %d (%s)", errno, strerror(errno));
+                               pDispatcher->RemoveFileEventInfo(*pWd);
+                       }
                }
+               delete pMapEnum;
        }
 
        delete __pWatchList;
@@ -83,14 +87,17 @@ _FileEventManagerImpl::Construct(IFileEventListener& listener)
        SysTryReturnResult(NID_IO, pWatchList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
        pWatchList->Construct();
 
+       _FileEventDispatcher* pDispatcher = _FileEventDispatcher::GetInstance();
+
        unique_ptr< _FileEvent > pEvent(new (std::nothrow) _FileEvent());
        SysTryReturnResult(NID_IO, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       result r = pEvent->Construct();
+       SysTryReturn(NID_IO, !IsFailed(r), E_IO, r, "[%s] The caller is a worker thread.", GetErrorMessage(r));
 
-       result r = pEvent->AddListener(listener, true);
+       r = pEvent->AddListener(listener, true);
        SysTryReturn(NID_IO, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, E_IO, r,
-                       "[%s] The caller thread is a worker thread.", GetErrorMessage(r));
+                       "[%s] The caller is a worker thread.", GetErrorMessage(r));
 
-       _FileEventDispatcher* pDispatcher = _FileEventDispatcher::GetInstance();
        __inotifyFd = pDispatcher->GetInotifyFd();
        __pWatchList = pWatchList.release();
        __pEvent = pEvent.release();