Add pointer check
authorHyunbin Lee <hyunbin.lee@samsung.com>
Thu, 30 May 2013 01:43:42 +0000 (10:43 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Thu, 30 May 2013 01:43:57 +0000 (10:43 +0900)
Change-Id: If059bbcb61326a70e8fb0da84aab0ea86ace469e
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
inc/FIoFileEventManager.h
src/io/FIo_FileEvent.cpp
src/io/FIo_FileEvent.h
src/io/FIo_FileEventManagerImpl.cpp

index 92614ca..d8043ec 100644 (file)
@@ -145,7 +145,7 @@ public:
        * @exception    E_SUCCESS                       The method is successful.
        * @exception    E_MAX_EXCEEDED          The number of opened files has exceeded the maximum limit.
        * @exception    E_IO                            Either of the following conditions has occurred: @n
-       *                                                                       - Fail to attach on platform.
+       *                                                                       - The specified listener cannot be registered in worker thread.
        *                                                                       - Detected corruption of a file.
        */
        result Construct(IFileEventListener& listener);
index 607ce1c..8ca58ca 100644 (file)
@@ -28,9 +28,10 @@ using namespace Tizen::Base::Runtime;
 namespace Tizen { namespace Io
 {
 
-_FileEvent::_FileEvent(void)
+result
+_FileEvent::Construct(void)
 {
-       _Event::Initialize();
+       return _Event::Initialize();
 }
 
 void
index 0a6e8a0..699cba2 100644 (file)
@@ -52,7 +52,7 @@ class _FileEvent
 {
 
 public:
-       _FileEvent(void);
+       result Construct(void);
 
 protected:
        virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
index 5fd8111..87fc35f 100644 (file)
@@ -57,18 +57,21 @@ _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);
+                       }
                }
        }
 
@@ -83,14 +86,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();