4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef _COMMAND_WORKER_H_
21 #define _COMMAND_WORKER_H_
23 #include <sensor_common.h>
24 #include <command_common.h>
25 #include <worker_thread.h>
26 #include <client_info_manager.h>
27 #include <sensor_event_dispatcher.h>
28 #include <sensor_base.h>
31 typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
33 class command_worker {
35 typedef bool (command_worker::*cmd_handler_t)(void *payload);
40 worker_thread m_worker;
41 sensor_base *m_module;
42 sensor_id_t m_sensor_id;
43 static cmd_handler_t m_cmd_handlers[CMD_CNT];
44 static cpacket m_sensor_list;
45 static sensor_raw_data_map m_sensor_raw_data_map;
47 static void init_cmd_handlers(void);
48 static int create_sensor_raw_list(int client_perms, std::vector<raw_data_t *> &raw_list);
49 static void get_sensor_list(int permissions, cpacket &sensor_list);
51 static bool working(void *ctx);
52 static bool stopped(void *ctx);
54 bool dispatch_command(int cmd, void *payload);
56 bool send_cmd_done(long value);
57 bool send_cmd_get_id_done(int client_id);
58 bool send_cmd_get_data_done(int state, sensor_data_t *data);
59 bool send_cmd_get_sensor_list_done(void);
61 bool cmd_get_id(void *payload);
62 bool cmd_get_sensor_list(void *payload);
63 bool cmd_hello(void *payload);
64 bool cmd_byebye(void *payload);
65 bool cmd_get_value(void *payload);
66 bool cmd_start(void *payload);
67 bool cmd_stop(void *payload);
68 bool cmd_register_event(void *payload);
69 bool cmd_unregister_event(void *payload);
70 bool cmd_set_batch(void *payload);
71 bool cmd_unset_batch(void *payload);
72 bool cmd_set_option(void *payload);
73 bool cmd_get_data(void *payload);
74 bool cmd_set_attribute_int(void *payload);
75 bool cmd_set_attribute_str(void *payload);
76 bool cmd_flush(void *payload);
78 void get_info(std::string &info);
80 int get_permission(void);
81 bool is_permission_allowed(void);
83 static client_info_manager& get_client_info_manager(void);
84 static sensor_event_dispatcher& get_event_dispathcher(void);
87 static cmutex m_shared_mutex;
90 command_worker(const csocket& socket);
91 virtual ~command_worker();
97 #endif /* _COMMAND_WORKER_H_ */