Added support for Event creation in worker thread 86/11086/3
authorRithesh Gowda <rithesh.g@samsung.com>
Thu, 17 Oct 2013 11:46:09 +0000 (17:16 +0530)
committerRithesh Gowda <rithesh.g@samsung.com>
Fri, 18 Oct 2013 04:17:44 +0000 (09:47 +0530)
Change-Id: Ie30c7def97a25711d8d18cf0521a7c5a49dfd666
Signed-off-by: Rithesh Gowda <rithesh.g@samsung.com>
inc/FBaseRtEvent.h
src/base/inc/FBaseRt_Event.h [changed mode: 0755->0644]
src/base/runtime/FBaseRt_Event.cpp [changed mode: 0755->0644]
src/base/runtime/FBaseRt_EventManager.cpp
src/base/runtime/FBaseRt_MainThreadImpl.cpp
src/base/runtime/FBaseRt_ThreadImpl.cpp
src/base/runtime/FBaseRt_ThreadImpl.h

index 2f4501b..b7ba556 100644 (file)
@@ -37,7 +37,6 @@ class IEventListener;
 * @since 2.0
 *
 * The %Event class provides methods for notifying events with argument to its listeners.
-* Because bounded to either default thread or event-driven thread, it cannot be created on worker thread.
 * It supports two types of listeners; one is called on the thread where the event is fired, and another is called on the thread where the listener was registered.
 *
 * @code
old mode 100755 (executable)
new mode 100644 (file)
index 884968b..312e37e
@@ -174,7 +174,6 @@ protected:
         * @return              An error code
         * @exception   E_SUCCESS               This method was successful.
         * @exception   E_INVALID_STATE         The event was already initialized.
-        * @exception   E_INVALID_OPERATION     This was called by a worker thread.
         *
         * @remark A derived class from _Event should call this method
         */
old mode 100755 (executable)
new mode 100644 (file)
index 5d6c58c..4b1fbde
@@ -27,6 +27,7 @@
 #include <FBaseSysLog.h>
 #include "FBaseRt_Event.h"
 #include "FBaseRt_EventManager.h"
+#include "FBaseRt_ThreadImpl.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -130,9 +131,20 @@ _Event::AddListener(const IEventListener& listener, bool calledByCallerThread)
 
        if (calledByCallerThread)
        {
+               _ThreadImpl* pThreadImpl = _ThreadImpl::GetCurrentThreadImpl();
+               SysTryReturnResult(NID_BASE_RT, pThreadImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread.");
+
+               ThreadType threadType = pThreadImpl->GetThreadType();
+               SysTryReturnResult(NID_BASE_RT, threadType != THREAD_TYPE_WORKER, E_INVALID_OPERATION, "The caller thread is not an event driven thread.");
+
+               ClearLastResult();
                _EventManager* pEventManager = _EventManager::GetCurrentEventManager();
-               SysTryReturnResult(NID_BASE_RT, pEventManager != null, E_INVALID_OPERATION
-                                                 , "The caller thread is not an event driven thread.");
+               r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       SysPropagate(NID_BASE_RT, r);
+                       return r;
+               }
 
                eventManager = pEventManager->GetHandle();
        }
index 4713ce3..834066c 100644 (file)
@@ -292,8 +292,11 @@ _EventManager::GetCurrentEventManager(void)
        SysTryReturn(NID_BASE_RT, pThreadImpl != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread.");
 
        ThreadType threadType = pThreadImpl->GetThreadType();
-       SysTryReturn(NID_BASE_RT, threadType != THREAD_TYPE_WORKER, null, E_INVALID_OPERATION,
-                                "[E_INVALID_OPERATION] This is a worker thread.");
+       if (threadType == THREAD_TYPE_WORKER)
+       {
+               pThreadImpl = _ThreadImpl::GetMainThreadImpl();
+               SysTryReturn(NID_BASE_RT, pThreadImpl != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] This is not OSP thread.");
+       }
 
        _EventManager* pEventManager = pThreadImpl->GetEventManager();
        SysTryReturn(NID_BASE_RT, pEventManager != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Event manager is not initialized.");
index d7b64e8..e0f61af 100644 (file)
@@ -93,6 +93,7 @@ _MainThreadImpl::Initialize(void)
 
        _ThreadImpl::Initialize();
 
+       SetMainThread();
        __pEventDispatcher = pEventDispatcher;
 
        return E_SUCCESS;
index 9a15e06..ef7b50d 100644 (file)
@@ -37,6 +37,7 @@ namespace Tizen { namespace Base { namespace Runtime
 {
 
 __thread Thread* pCurrentThread = null;
+Thread* _ThreadImpl::__pDefaultThread = null;
 
 _ThreadImpl*
 _ThreadImpl::GetCurrentThreadImpl(void)
@@ -290,4 +291,20 @@ _ThreadImpl::GetEventManager(void)
 }
 
 
+void
+_ThreadImpl::SetMainThread(void)
+{
+       __pDefaultThread = _pThread;
+}
+
+_ThreadImpl*
+_ThreadImpl::GetMainThreadImpl(void)
+{
+       if (__pDefaultThread != null)
+       {
+               return __pDefaultThread->__pThreadImpl;
+       }
+
+       return null;
+}
 } } } // Tizen::Base::Runtime
index 6667f76..999fd4a 100644 (file)
@@ -72,6 +72,7 @@ public:
 
        static _ThreadImpl* GetCurrentThreadImpl(void);
 
+       static _ThreadImpl* GetMainThreadImpl(void);
 protected:
        virtual result Initialize(void);
 
@@ -84,6 +85,7 @@ protected:
        void SetThread(Thread* pThread);
 
        void SetNativeThread(pthread_t nativeThread);
+       void SetMainThread(void);
 
 private:
        static void* ThreadProc(void* pParam);
@@ -99,6 +101,7 @@ private:
        pthread_t __nativeThread;
        int __exitCode;
        _EventManager* __pEventManager;
+       static Thread* __pDefaultThread;
 }; // _ThreadImpl
 
 } } } // Tizen::Base::Runtime