sensord: fix incorrect return type
[platform/core/system/sensord.git] / src / server / worker_thread.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef _WORKER_THREAD_H_
21 #define _WORKER_THREAD_H_
22
23 #include <mutex>
24 #include <condition_variable>
25
26 class worker_thread {
27 public:
28         enum worker_state_t {
29                 WORKER_STATE_INITIAL,
30                 WORKER_STATE_WORKING,
31                 WORKER_STATE_PAUSED,
32                 WORKER_STATE_STOPPED,
33         };
34
35         typedef bool(*trans_func_t)(void *data);
36 private:
37         enum trans_func_index {
38                 STARTED = 0,
39                 STOPPED,
40                 PAUSED,
41                 RESUMED,
42                 WORKING,
43                 TRANS_FUNC_CNT,
44         };
45
46         typedef std::lock_guard<std::mutex>  lock;
47         typedef std::unique_lock<std::mutex> ulock;
48
49         worker_state_t m_state;
50         void *m_context;
51         std::mutex m_mutex;
52         std::condition_variable m_cond_working;
53         bool m_thread_created;
54
55         trans_func_t m_trans_func[TRANS_FUNC_CNT];
56
57         bool transition_function(trans_func_index index);
58         void main(void);
59 public:
60         worker_thread();
61         virtual ~worker_thread();
62
63         bool start(void);
64         bool stop(void);
65         bool pause(void);
66         bool resume(void);
67
68         worker_state_t get_state(void);
69
70         void set_started(trans_func_t func);
71         void set_stopped(trans_func_t func);
72         void set_paused(trans_func_t func);
73         void set_resumed(trans_func_t func);
74         void set_working(trans_func_t func);
75
76         void set_context(void *ctx);
77 };
78
79 #endif /* _WORKER_THREAD_H_ */