Modify flora license version.
[platform/core/messaging/msg-service.git] / include / common / MsgThread.h
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 #ifndef __MSG_THREAD_H__
18 #define __MSG_THREAD_H__
19
20
21 /*==================================================================================================
22                                          INCLUDE FILES
23 ==================================================================================================*/
24 #include <pthread.h>
25 #include "MsgDebug.h"
26
27 /*==================================================================================================
28                                      CLASS DEFINITIONS
29 ==================================================================================================*/
30 class MsgThread
31 {
32 public:
33         MsgThread(): thd(0) {};
34
35         virtual void start()
36         {
37                 MSG_DEBUG("MsgThread::Start() called");
38
39                 if (pthread_create(&thd, NULL, &MsgThread::thdMain, this) < 0)
40                 {
41                         MSG_DEBUG("pthread_create() error");
42                         return;
43                 }
44
45                 pthread_detach(thd);
46         }
47
48         virtual void stop()
49         {
50                 MSG_DEBUG("MsgThread::stop() called");
51         }
52
53         void wait()
54         {
55                 MSG_DEBUG("MsgThread::Wait() called");
56                 void* pData;
57                 pthread_join(thd, &pData);
58         }
59
60 private:
61         static void* thdMain(void* pInst)
62         {
63                 MSG_DEBUG("MsgThread::thdMain() called");
64                 MsgThread* pt = static_cast<MsgThread*>(pInst);
65                 pt->run();
66                 return NULL;
67         }
68
69         virtual void run() = 0;
70
71         pthread_t thd;
72 };
73
74
75 #endif //__MSG_THREAD_H__
76