sync with tizen_2.0
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_ThreadImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FBaseRt_ThreadImpl.h
20  * @brief       This is the header file for the %_ThreadImpl class.
21  *
22  * This file contains the declarations of the %_ThreadImpl class.
23  */
24
25 #ifndef _FBASE_RT_INTERNAL_THREAD_IMPL_H_
26 #define _FBASE_RT_INTERNAL_THREAD_IMPL_H_
27
28 #include <pthread.h>
29
30 #include <FBaseRtThread.h>
31 #include "FBaseRt_EventManager.h"
32
33 namespace Tizen { namespace Base { namespace Runtime
34 {
35
36 class _OSP_EXPORT_ _ThreadImpl
37         : public Tizen::Base::Object
38         , public Tizen::Base::Runtime::IRunnable
39 {
40 public:
41         _ThreadImpl(Thread& thread, const Tizen::Base::String& name, long stackSize
42                                 , ThreadPriority priority, ThreadType threadType);
43
44         virtual ~_ThreadImpl(void);
45
46         virtual result Start(void);
47
48         virtual result Stop(void);
49
50         virtual result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs);
51
52         result Join(void);
53
54         result GetExitCode(int& exitCode) const;
55
56         const Tizen::Base::String& GetName(void) const;
57
58         ThreadType GetThreadType(void) const;
59
60         void SetEventManager(_EventManager* pEventManager);
61
62         _EventManager* GetEventManager(void);
63
64         virtual Tizen::Base::Object* Run(void);
65
66         static void Exit(int exitCode);
67
68         static result Sleep(long milliSeconds);
69
70         static result Yield(void);
71
72         static Thread* GetCurrentThread(void);
73
74         static _ThreadImpl* GetCurrentThreadImpl(void);
75
76 protected:
77         virtual result Initialize(void);
78
79         virtual result Finalize(void);
80
81         const Thread* GetThread(void) const;
82
83         const ThreadPriority GetPriority(void) const;
84
85         void SetThread(Thread* pThread);
86
87         void SetNativeThread(pthread_t nativeThread);
88
89 private:
90         static void* ThreadProc(void* pParam);
91
92 protected:
93         Thread* _pThread;
94
95 private:
96         String __name;
97         long __stackSize;
98         ThreadPriority __priority;
99         ThreadType __threadType;
100         pthread_t __nativeThread;
101         int __exitCode;
102         _EventManager* __pEventManager;
103 }; // _ThreadImpl
104
105 } } } // Tizen::Base::Runtime
106
107 #endif  // _FBASE_RT_INTERNAL_THREAD_IMPL_H_