2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseRt_MainThreadImpl.cpp
19 * @brief This is the implementation file for the _MainThreadImpl class.
27 #include <FBaseSysLog.h>
28 #include "FBaseRt_EventDispatcher.h"
29 #include "FBase_NativeError.h"
30 #include "FBaseRt_MainThreadImpl.h"
31 #include "FBaseRt_EventManager.h"
34 namespace Tizen { namespace Base { namespace Runtime
37 _MainThreadImpl::_MainThreadImpl(Thread& thread, const String& name)
38 : _ThreadImpl(thread, name, Thread::DEFAULT_STACK_SIZE, THREAD_PRIORITY_HIGH, THREAD_TYPE_MAIN)
39 , __pEventDispatcher(null)
40 , __pEventManager(null)
45 _MainThreadImpl::~_MainThreadImpl(void)
47 delete __pEventDispatcher;
48 delete __pEventManager;
52 _MainThreadImpl::Start(void)
60 _MainThreadImpl::Run(void)
62 SetNativeThread(pthread_self());
70 _MainThreadImpl::Initialize(void)
73 _EventManager* pEventManager = null;
74 _EventDispatcher* pEventDispatcher = null;
76 GMainContext* pGMainContext = g_main_context_default();
77 SysTryReturnResult(NID_BASE_RT, pGMainContext != null, E_INVALID_STATE, "Failed to get GMainContext.");
79 pEventManager = new (std::nothrow) _EventManager;
80 SysTryReturnResult(NID_BASE_RT, pEventManager != null, E_OUT_OF_MEMORY, "Not enough memory.");
82 r = pEventManager->Construct(pGMainContext);
83 SysTryCatch(NID_BASE_RT, !IsFailed(r), , r, "[%s] Failed to initialize event manager.", GetErrorMessage(r));
85 _ThreadImpl::SetEventManager(pEventManager);
86 __pEventManager = pEventManager;
88 pEventDispatcher = new (std::nothrow) _EventDispatcher;
89 SysTryCatch(NID_BASE_RT, pEventDispatcher!= null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
91 r = pEventDispatcher->Construct(pGMainContext);
92 SysTryCatch(NID_BASE_RT, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
94 _ThreadImpl::Initialize();
97 __pEventDispatcher = pEventDispatcher;
102 delete pEventDispatcher;
104 delete pEventManager;
109 } } } // Tizen::Base::Runtime