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 <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>
31 typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
32 void insert_priority_list(unsigned int);
34 class command_worker {
36 typedef bool (command_worker::*cmd_handler_t)(void *payload);
38 static const int OP_ERROR = -1;
39 static const int OP_SUCCESS = 0;
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;
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);
55 static bool working(void *ctx);
56 static bool stopped(void *ctx);
58 bool dispatch_command(int cmd, void *payload);
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);
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);
82 void get_info(std::string &info);
84 int get_permission(void);
85 bool is_permission_allowed(void);
87 static client_info_manager& get_client_info_manager(void);
88 static sensor_event_dispatcher& get_event_dispathcher(void);
90 command_worker(const csocket& socket);
91 virtual ~command_worker();
97 #endif /* _COMMAND_WORKER_H_ */