Added support for Event creation in worker thread
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_ThreadImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FBaseRt_ThreadImpl.h
19  * @brief       This is the header file for the %_ThreadImpl class.
20  *
21  * This file contains the declarations of the %_ThreadImpl class.
22  */
23
24 #ifndef _FBASE_RT_INTERNAL_THREAD_IMPL_H_
25 #define _FBASE_RT_INTERNAL_THREAD_IMPL_H_
26
27 #include <pthread.h>
28
29 #include <FBaseRtThread.h>
30 #include "FBaseRt_EventManager.h"
31
32 namespace Tizen { namespace Base { namespace Runtime
33 {
34
35 class _OSP_EXPORT_ _ThreadImpl
36         : public Tizen::Base::Object
37         , public Tizen::Base::Runtime::IRunnable
38 {
39 public:
40         _ThreadImpl(Thread& thread, const Tizen::Base::String& name, long stackSize
41                                 , ThreadPriority priority, ThreadType threadType);
42
43         virtual ~_ThreadImpl(void);
44
45         virtual result Start(void);
46
47         virtual result Stop(void);
48
49         virtual result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs);
50
51         result Join(void);
52
53         result GetExitCode(int& exitCode) const;
54
55         const Tizen::Base::String& GetName(void) const;
56
57         ThreadType GetThreadType(void) const;
58
59         void SetEventManager(_EventManager* pEventManager);
60
61         _EventManager* GetEventManager(void);
62
63         virtual Tizen::Base::Object* Run(void);
64
65         static void Exit(int exitCode);
66
67         static result Sleep(long milliSeconds);
68
69         static result Yield(void);
70
71         static Thread* GetCurrentThread(void);
72
73         static _ThreadImpl* GetCurrentThreadImpl(void);
74
75         static _ThreadImpl* GetMainThreadImpl(void);
76 protected:
77         virtual result Initialize(void);
78
79         virtual result Finalize(void);
80
81         const Thread* GetThread(void) const;
82
83         ThreadPriority GetPriority(void) const;
84
85         void SetThread(Thread* pThread);
86
87         void SetNativeThread(pthread_t nativeThread);
88         void SetMainThread(void);
89
90 private:
91         static void* ThreadProc(void* pParam);
92
93 protected:
94         Thread* _pThread;
95
96 private:
97         String __name;
98         long __stackSize;
99         ThreadPriority __priority;
100         ThreadType __threadType;
101         pthread_t __nativeThread;
102         int __exitCode;
103         _EventManager* __pEventManager;
104         static Thread* __pDefaultThread;
105 }; // _ThreadImpl
106
107 } } } // Tizen::Base::Runtime
108
109 #endif  // _FBASE_RT_INTERNAL_THREAD_IMPL_H_