sensord: clean up sf_common.h/sensor_common.h/sensor_logs.h
[platform/core/system/sensord.git] / src / server / command_worker.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 _COMMAND_WORKER_H_
21 #define _COMMAND_WORKER_H_
22
23 #include <command_common.h>
24 #include <worker_thread.h>
25 #include <client_info_manager.h>
26 #include <sensor_event_dispatcher.h>
27 #include <sensor_base.h>
28 #include <map>
29 #include <cpacket.h>
30
31 typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
32 void insert_priority_list(unsigned int);
33
34 class command_worker {
35 private:
36         typedef bool (command_worker::*cmd_handler_t)(void *payload);
37
38         static const int OP_ERROR = -1;
39         static const int OP_SUCCESS = 0;
40
41         int m_client_id;
42         int m_permission;
43         csocket m_socket;
44         worker_thread m_worker;
45         sensor_base *m_module;
46         sensor_id_t m_sensor_id;
47         static cmd_handler_t m_cmd_handlers[CMD_CNT];
48         static cpacket m_sensor_list;
49         static sensor_raw_data_map m_sensor_raw_data_map;
50
51         static void init_cmd_handlers(void);
52         static void make_sensor_raw_data_map(void);
53         static void get_sensor_list(int permissions, cpacket &sensor_list);
54
55         static bool working(void *ctx);
56         static bool stopped(void *ctx);
57
58         bool dispatch_command(int cmd, void *payload);
59
60         bool send_cmd_done(long value);
61         bool send_cmd_get_id_done(int client_id);
62         bool send_cmd_get_data_done(int state, sensor_data_t *data);
63         bool send_cmd_get_sensor_list_done(void);
64
65         bool cmd_get_id(void *payload);
66         bool cmd_get_sensor_list(void *payload);
67         bool cmd_hello(void *payload);
68         bool cmd_byebye(void *payload);
69         bool cmd_get_value(void *payload);
70         bool cmd_start(void *payload);
71         bool cmd_stop(void *payload);
72         bool cmd_register_event(void *payload);
73         bool cmd_unregister_event(void *payload);
74         bool cmd_set_batch(void *payload);
75         bool cmd_unset_batch(void *payload);
76         bool cmd_set_option(void *payload);
77         bool cmd_set_wakeup(void *payload);
78         bool cmd_get_data(void *payload);
79         bool cmd_set_attribute_int(void *payload);
80         bool cmd_set_attribute_str(void *payload);
81
82         void get_info(std::string &info);
83
84         int get_permission(void);
85         bool is_permission_allowed(void);
86
87         static client_info_manager& get_client_info_manager(void);
88         static sensor_event_dispatcher& get_event_dispathcher(void);
89 public:
90         command_worker(const csocket& socket);
91         virtual ~command_worker();
92
93         bool start(void);
94
95 };
96
97 #endif /* _COMMAND_WORKER_H_ */