* @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
* @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
*/
#include <FBaseSysLog.h>
#include "FBaseRt_Event.h"
#include "FBaseRt_EventManager.h"
+#include "FBaseRt_ThreadImpl.h"
using namespace Tizen::Base;
using namespace Tizen::Base::Collection;
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();
}
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.");
_ThreadImpl::Initialize();
+ SetMainThread();
__pEventDispatcher = pEventDispatcher;
return E_SUCCESS;
{
__thread Thread* pCurrentThread = null;
+Thread* _ThreadImpl::__pDefaultThread = null;
_ThreadImpl*
_ThreadImpl::GetCurrentThreadImpl(void)
}
+void
+_ThreadImpl::SetMainThread(void)
+{
+ __pDefaultThread = _pThread;
+}
+
+_ThreadImpl*
+_ThreadImpl::GetMainThreadImpl(void)
+{
+ if (__pDefaultThread != null)
+ {
+ return __pDefaultThread->__pThreadImpl;
+ }
+
+ return null;
+}
} } } // Tizen::Base::Runtime
static _ThreadImpl* GetCurrentThreadImpl(void);
+ static _ThreadImpl* GetMainThreadImpl(void);
protected:
virtual result Initialize(void);
void SetThread(Thread* pThread);
void SetNativeThread(pthread_t nativeThread);
+ void SetMainThread(void);
private:
static void* ThreadProc(void* pParam);
pthread_t __nativeThread;
int __exitCode;
_EventManager* __pEventManager;
+ static Thread* __pDefaultThread;
}; // _ThreadImpl
} } } // Tizen::Base::Runtime