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 #include <command_worker.h>
21 #include <sensor_loader.h>
22 #include <sensor_info.h>
23 #include <sensor_types.h>
28 #include <permission_checker.h>
35 command_worker::cmd_handler_t command_worker::m_cmd_handlers[];
36 sensor_raw_data_map command_worker::m_sensor_raw_data_map;
37 cpacket command_worker::m_sensor_list;
39 std::set<unsigned int> priority_list;
41 command_worker::command_worker(const csocket& socket)
42 : m_client_id(CLIENT_ID_INVALID)
43 , m_permission(SENSOR_PERMISSION_NONE)
46 , m_sensor_id(UNKNOWN_SENSOR)
48 static bool init = false;
52 make_sensor_raw_data_map();
57 m_worker.set_context(this);
58 m_worker.set_working(working);
59 m_worker.set_stopped(stopped);
62 command_worker::~command_worker()
68 bool command_worker::start(void)
70 return m_worker.start();
73 void command_worker::init_cmd_handlers(void)
75 m_cmd_handlers[CMD_GET_ID] = &command_worker::cmd_get_id;
76 m_cmd_handlers[CMD_GET_SENSOR_LIST] = &command_worker::cmd_get_sensor_list;
77 m_cmd_handlers[CMD_HELLO] = &command_worker::cmd_hello;
78 m_cmd_handlers[CMD_BYEBYE] = &command_worker::cmd_byebye;
79 m_cmd_handlers[CMD_START] = &command_worker::cmd_start;
80 m_cmd_handlers[CMD_STOP] = &command_worker::cmd_stop;
81 m_cmd_handlers[CMD_REG] = &command_worker::cmd_register_event;
82 m_cmd_handlers[CMD_UNREG] = &command_worker::cmd_unregister_event;
83 m_cmd_handlers[CMD_SET_OPTION] = &command_worker::cmd_set_option;
84 m_cmd_handlers[CMD_SET_WAKEUP] = &command_worker::cmd_set_wakeup;
85 m_cmd_handlers[CMD_SET_BATCH] = &command_worker::cmd_set_batch;
86 m_cmd_handlers[CMD_UNSET_BATCH] = &command_worker::cmd_unset_batch;
87 m_cmd_handlers[CMD_SET_COMMAND] = &command_worker::cmd_set_command;
88 m_cmd_handlers[CMD_GET_DATA] = &command_worker::cmd_get_data;
89 m_cmd_handlers[CMD_SEND_SENSORHUB_DATA] = &command_worker::cmd_send_sensorhub_data;
92 void command_worker::get_sensor_list(int permissions, cpacket &sensor_list)
94 const int PERMISSION_COUNT = sizeof(permissions) * 8;
95 vector<raw_data_t *> sensor_raw_vec;
96 size_t total_raw_data_size = 0;
98 for (int i = 0; i < PERMISSION_COUNT; ++i) {
99 int perm = (permissions & (1 << i));
102 auto range = m_sensor_raw_data_map.equal_range(perm);
104 sensor_raw_data_map::iterator it_raw_data;
106 for (it_raw_data = range.first; it_raw_data != range.second; ++it_raw_data) {
107 total_raw_data_size += it_raw_data->second.size();
108 sensor_raw_vec.push_back(&(it_raw_data->second));
115 sensor_cnt = sensor_raw_vec.size();
117 sensor_list.set_payload_size(sizeof(cmd_get_sensor_list_done_t) + (sizeof(size_t) * sensor_cnt) + total_raw_data_size);
118 sensor_list.set_cmd(CMD_GET_SENSOR_LIST);
120 cmd_get_sensor_list_done_t *cmd_get_sensor_list_done;
122 cmd_get_sensor_list_done = (cmd_get_sensor_list_done_t*)sensor_list.data();
123 cmd_get_sensor_list_done->sensor_cnt = sensor_cnt;
124 size_t* size_field = (size_t *) cmd_get_sensor_list_done->data;
127 for (int i = 0; i < sensor_cnt; ++i)
128 size_field[i] = sensor_raw_vec[i]->size();
130 char* raw_data_field = cmd_get_sensor_list_done->data + (sizeof(size_t) * sensor_cnt);
133 for (int i = 0; i < sensor_cnt; ++i) {
134 copy(sensor_raw_vec[i]->begin(), sensor_raw_vec[i]->end(), raw_data_field + idx);
135 idx += sensor_raw_vec[i]->size();
140 void command_worker::make_sensor_raw_data_map(void)
142 vector<sensor_base *> sensors;
143 vector<sensor_type_t> types;
144 std::vector<sensor_type_t>::iterator it_type;
145 std::vector<sensor_base *>::iterator it_sensor;
149 types = sensor_loader::get_instance().get_sensor_types();
151 it_type = types.begin();
152 while (it_type != types.end()) {
156 sensors = sensor_loader::get_instance().get_sensors(type);
157 it_sensor = sensors.begin();
159 while (it_sensor != sensors.end()) {
160 (*it_sensor)->get_sensor_info(info);
161 permission = (*it_sensor)->get_permission();
163 sensor_raw_data_map::iterator it_sensor_raw_data;
164 it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t()));
166 info.get_raw_data(it_sensor_raw_data->second);
174 bool command_worker::working(void *ctx)
177 command_worker *inst = (command_worker *)ctx;
179 packet_header header;
182 if (inst->m_socket.recv(&header, sizeof(header)) <= 0) {
184 inst->get_info(info);
185 DBG("%s failed to receive header", info.c_str());
189 if (header.size > 0) {
191 payload = new(std::nothrow) char[header.size];
192 retvm_if(!payload, false, "Failed to allocate memory");
194 if (inst->m_socket.recv(payload, header.size) <= 0) {
196 inst->get_info(info);
197 DBG("%s failed to receive data of packet", info.c_str());
205 ret = inst->dispatch_command(header.cmd, payload);
214 bool command_worker::stopped(void *ctx)
217 command_worker *inst = (command_worker *)ctx;
219 inst->get_info(info);
220 INFO("%s is stopped", info.c_str());
222 if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
224 if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) {
225 WARN("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name());
226 inst->m_module->delete_interval(inst->m_client_id, false);
227 inst->m_module->stop();
230 if (inst->m_sensor_id) {
231 if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) {
232 INFO("Removing sensor[0x%llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id);
233 get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id);
242 bool command_worker::dispatch_command(int cmd, void* payload)
246 if (!(cmd > 0 && cmd < CMD_CNT)) {
247 ERR("Unknown command: %d", cmd);
249 cmd_handler_t cmd_handler;
250 cmd_handler = command_worker::m_cmd_handlers[cmd];
252 ret = (this->*cmd_handler)(payload);
258 bool command_worker::send_cmd_done(long value)
261 cmd_done_t *cmd_done;
263 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_done_t));
264 retvm_if(!ret_packet, false, "Failed to allocate memory");
266 ret_packet->set_cmd(CMD_DONE);
268 cmd_done = (cmd_done_t*)ret_packet->data();
269 cmd_done->value = value;
271 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
272 ERR("Failed to send a cmd_done to client_id [%d] with value [%ld]", m_client_id, value);
283 bool command_worker::send_cmd_get_id_done(int client_id)
286 cmd_get_id_done_t *cmd_get_id_done;
288 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_id_done_t));
289 retvm_if(!ret_packet, false, "Failed to allocate memory");
291 ret_packet->set_cmd(CMD_GET_ID);
293 cmd_get_id_done = (cmd_get_id_done_t*)ret_packet->data();
294 cmd_get_id_done->client_id = client_id;
296 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
297 ERR("Failed to send a cmd_get_id_done with client_id [%d]", client_id);
306 bool command_worker::send_cmd_get_data_done(int state, sensor_data_t *data)
309 cmd_get_data_done_t *cmd_get_data_done;
311 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_data_done_t));
312 retvm_if(!ret_packet, false, "Failed to allocate memory");
314 ret_packet->set_cmd(CMD_GET_DATA);
316 cmd_get_data_done = (cmd_get_data_done_t*)ret_packet->data();
317 cmd_get_data_done->state = state;
319 memcpy(&cmd_get_data_done->base_data , data, sizeof(sensor_data_t));
321 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
322 ERR("Failed to send a cmd_get_data_done");
332 bool command_worker::send_cmd_get_sensor_list_done(void)
336 int permission = get_permission();
338 INFO("permission = 0x%x", permission);
340 get_sensor_list(permission, sensor_list);
342 if (m_socket.send(sensor_list.packet(), sensor_list.size()) <= 0) {
343 ERR("Failed to send a cmd_get_sensor_list_done");
350 bool command_worker::cmd_get_id(void *payload)
355 socklen_t opt_len = sizeof(cr);
357 DBG("CMD_GET_ID Handler invoked\n");
358 cmd = (cmd_get_id_t*)payload;
360 if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) {
361 ERR("Failed to get socket option with SO_PEERCRED");
365 client_id = get_client_info_manager().create_client_record();
367 get_client_info_manager().set_client_info(client_id, cr.pid, cmd->name);
369 m_permission = get_permission();
370 get_client_info_manager().set_permission(client_id, m_permission);
372 INFO("New client id [%d] created", client_id);
374 if (!send_cmd_get_id_done(client_id))
375 ERR("Failed to send cmd_done to a client");
381 bool command_worker::cmd_get_sensor_list(void *payload)
383 DBG("CMD_GET_SENSOR_LIST Handler invoked\n");
385 if (!send_cmd_get_sensor_list_done())
386 ERR("Failed to send cmd_get_sensor_list_done to a client");
391 bool command_worker::cmd_hello(void *payload)
394 long ret_value = OP_ERROR;
396 DBG("CMD_HELLO Handler invoked\n");
397 cmd = (cmd_hello_t*)payload;
399 m_sensor_id = cmd->sensor;
400 m_client_id = cmd->client_id;
402 if (m_permission == SENSOR_PERMISSION_NONE)
403 get_client_info_manager().get_permission(m_client_id, m_permission);
405 m_module = (sensor_base *)sensor_loader::get_instance().get_sensor(cmd->sensor);
408 ERR("Sensor type[%d] is not supported", cmd->sensor);
409 if (!get_client_info_manager().has_sensor_record(m_client_id))
410 get_client_info_manager().remove_client_record(m_client_id);
412 ret_value = OP_ERROR;
416 if (!is_permission_allowed()) {
417 ERR("Permission denied to connect sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
418 ret_value = OP_ERROR;
422 DBG("Hello sensor [0x%llx], client id [%d]", m_sensor_id, m_client_id);
423 get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id);
424 INFO("New sensor record created for sensor [0x%llx], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id);
425 ret_value = OP_SUCCESS;
427 if (!send_cmd_done(ret_value))
428 ERR("Failed to send cmd_done to a client");
433 bool command_worker::cmd_byebye(void *payload)
435 long ret_value = OP_ERROR;
437 if (!is_permission_allowed()) {
438 ERR("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
439 ret_value = OP_ERROR;
443 DBG("CMD_BYEBYE for client [%d], sensor [0x%llx]", m_client_id, m_sensor_id);
445 if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) {
446 ERR("Error removing sensor_record for client [%d]", m_client_id);
447 ret_value = OP_ERROR;
451 m_client_id = CLIENT_ID_INVALID;
452 ret_value = OP_SUCCESS;
455 if (!send_cmd_done(ret_value))
456 ERR("Failed to send cmd_done to a client");
458 if (ret_value == OP_SUCCESS)
464 bool command_worker::cmd_start(void *payload)
466 long ret_value = OP_ERROR;
468 if (!is_permission_allowed()) {
469 ERR("Permission denied to start sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
470 ret_value = OP_ERROR;
474 DBG("START Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id);
476 if (m_module->start()) {
477 get_client_info_manager().set_start(m_client_id, m_sensor_id, true);
479 * Rotation could be changed even LCD is off by pop sync rotation
480 * and a client listening rotation event with always-on option.
481 * To reflect the last rotation state, request it to event dispatcher.
483 get_event_dispathcher().request_last_event(m_client_id, m_sensor_id);
484 ret_value = OP_SUCCESS;
486 ERR("Failed to start sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id);
487 ret_value = OP_ERROR;
491 if (!send_cmd_done(ret_value))
492 ERR("Failed to send cmd_done to a client");
497 bool command_worker::cmd_stop(void *payload)
499 long ret_value = OP_ERROR;
501 if (!is_permission_allowed()) {
502 ERR("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
503 ret_value = OP_ERROR;
507 DBG("STOP Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id);
509 if (m_module->stop()) {
510 get_client_info_manager().set_start(m_client_id, m_sensor_id, false);
511 ret_value = OP_SUCCESS;
513 ERR("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id);
514 ret_value = OP_ERROR;
518 if (!send_cmd_done(ret_value))
519 ERR("Failed to send cmd_done to a client");
524 bool command_worker::cmd_register_event(void *payload)
527 long ret_value = OP_ERROR;
529 cmd = (cmd_reg_t*)payload;
531 if (!is_permission_allowed()) {
532 ERR("Permission denied to register event [0x%x] for client [%d] to client info manager",
533 cmd->event_type, m_client_id);
534 ret_value = OP_ERROR;
538 if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) {
539 INFO("Failed to register event [0x%x] for client [%d] to client info manager",
540 cmd->event_type, m_client_id);
541 ret_value = OP_ERROR;
545 insert_priority_list(cmd->event_type);
547 ret_value = OP_SUCCESS;
548 DBG("Registering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id);
551 if (!send_cmd_done(ret_value))
552 ERR("Failed to send cmd_done to a client");
557 bool command_worker::cmd_unregister_event(void *payload)
560 long ret_value = OP_ERROR;
562 cmd = (cmd_unreg_t*)payload;
564 if (!is_permission_allowed()) {
565 ERR("Permission denied to unregister event [0x%x] for client [%d] to client info manager",
566 cmd->event_type, m_client_id);
567 ret_value = OP_ERROR;
571 if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) {
572 ERR("Failed to unregister event [0x%x] for client [%d] from client info manager",
573 cmd->event_type, m_client_id);
574 ret_value = OP_ERROR;
578 ret_value = OP_SUCCESS;
579 DBG("Unregistering Event [0x%x] is done for client [%d]",
580 cmd->event_type, m_client_id);
583 if (!send_cmd_done(ret_value))
584 ERR("Failed to send cmd_done to a client");
589 bool command_worker::cmd_set_batch(void *payload)
591 cmd_set_batch_t *cmd;
592 long ret_value = OP_ERROR;
594 cmd = (cmd_set_batch_t*)payload;
596 if (!is_permission_allowed()) {
597 ERR("Permission denied to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager",
598 m_client_id, m_sensor_id, cmd->interval, cmd->latency);
599 ret_value = OP_ERROR;
603 if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) {
604 ERR("Failed to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager",
605 m_client_id, m_sensor_id, cmd->interval, cmd->latency);
606 ret_value = OP_ERROR;
610 if (!m_module->add_interval(m_client_id, cmd->interval, false)) {
611 ERR("Failed to set interval for client [%d], for sensor [0x%llx] with interval [%d]",
612 m_client_id, m_sensor_id, cmd->interval);
613 ret_value = OP_ERROR;
617 if (!m_module->add_batch(m_client_id, cmd->latency)) {
618 ERR("Failed to set latency for client [%d], for sensor [0x%llx] with latency [%d]",
619 m_client_id, m_sensor_id, cmd->latency);
620 ret_value = OP_ERROR;
624 ret_value = OP_SUCCESS;
627 if (!send_cmd_done(ret_value))
628 ERR("Failed to send cmd_done to a client");
633 bool command_worker::cmd_unset_batch(void *payload)
635 long ret_value = OP_ERROR;
637 if (!is_permission_allowed()) {
638 ERR("Permission denied to unset batch for client [%d], for sensor [0x%llx] to client info manager",
639 m_client_id, m_sensor_id);
640 ret_value = OP_ERROR;
644 if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) {
645 ERR("Failed to unset batch for client [%d], for sensor [0x%llx] to client info manager",
646 m_client_id, m_sensor_id);
647 ret_value = OP_ERROR;
651 if (!m_module->delete_interval(m_client_id, false)) {
652 ERR("Failed to delete interval for client [%d]", m_client_id);
653 ret_value = OP_ERROR;
657 if (!m_module->delete_batch(m_client_id)) {
658 ERR("Failed to delete latency for client [%d]", m_client_id);
659 ret_value = OP_ERROR;
663 ret_value = OP_SUCCESS;
666 if (!send_cmd_done(ret_value))
667 ERR("Failed to send cmd_done to a client");
672 bool command_worker::cmd_set_option(void *payload)
674 cmd_set_option_t *cmd;
675 long ret_value = OP_ERROR;
677 cmd = (cmd_set_option_t*)payload;
679 if (!is_permission_allowed()) {
680 ERR("Permission denied to set interval for client [%d], for sensor [0x%llx] with option [%d] to client info manager",
681 m_client_id, m_sensor_id, cmd->option);
682 ret_value = OP_ERROR;
686 if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) {
687 ERR("Failed to set option for client [%d], for sensor [0x%llx] with option [%d] to client info manager",
688 m_client_id, m_sensor_id, cmd->option);
689 ret_value = OP_ERROR;
693 ret_value = OP_SUCCESS;
695 if (!send_cmd_done(ret_value))
696 ERR("Failed to send cmd_done to a client");
701 bool command_worker::cmd_set_wakeup(void *payload)
703 cmd_set_wakeup_t *cmd;
704 long ret_value = OP_ERROR;
706 cmd = (cmd_set_wakeup_t*)payload;
708 if (!is_permission_allowed()) {
709 ERR("Permission denied to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager",
710 m_client_id, m_sensor_id, cmd->wakeup);
711 ret_value = OP_ERROR;
715 if (!get_client_info_manager().set_wakeup(m_client_id, m_sensor_id, cmd->wakeup)) {
716 ERR("Failed to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager",
717 m_client_id, m_sensor_id, cmd->wakeup);
718 ret_value = OP_ERROR;
722 ret_value = m_module->add_wakeup(m_client_id, cmd->wakeup);
725 if (!send_cmd_done(ret_value))
726 ERR("Failed to send cmd_done to a client");
731 bool command_worker::cmd_set_command(void *payload)
733 cmd_set_command_t *cmd;
734 long ret_value = OP_ERROR;
736 DBG("CMD_SET_COMMAND Handler invoked\n");
738 cmd = (cmd_set_command_t*)payload;
740 if (!is_permission_allowed()) {
741 ERR("Permission denied to set command for client [%d], for sensor [0x%llx] with cmd [%d]",
742 m_client_id, m_sensor_id, cmd->cmd);
743 ret_value = OP_ERROR;
747 ret_value = m_module->set_attribute(cmd->cmd, cmd->value);
750 if (!send_cmd_done(ret_value))
751 ERR("Failed to send cmd_done to a client");
756 bool command_worker::cmd_get_data(void *payload)
758 const unsigned int GET_DATA_MIN_INTERVAL = 10;
759 int state = OP_ERROR;
760 bool adjusted = false;
765 DBG("CMD_GET_VALUE Handler invoked\n");
767 if (!is_permission_allowed()) {
768 ERR("Permission denied to get data for client [%d], for sensor [0x%llx]",
769 m_client_id, m_sensor_id);
774 state = m_module->get_data(&data, &length);
776 // In case of not getting sensor data, wait short time and retry again
777 // 1. changing interval to be less than 10ms
778 // 2. In case of first time, wait for INIT_WAIT_TIME
779 // 3. at another time, wait for WAIT_TIME
780 // 4. retrying to get data
781 // 5. repeat 2 ~ 4 operations RETRY_CNT times
782 // 6. reverting back to original interval
783 if ((state >= 0) && !data->timestamp) {
784 const int RETRY_CNT = 5;
785 const unsigned long long INIT_WAIT_TIME = 20000; //20ms
786 const unsigned long WAIT_TIME = 100000; //100ms
789 unsigned int interval = m_module->get_interval(m_client_id, false);
791 if (interval > GET_DATA_MIN_INTERVAL) {
792 m_module->add_interval(m_client_id, GET_DATA_MIN_INTERVAL, false);
796 while ((state >= 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
797 INFO("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry);
798 usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME);
799 state = m_module->get_data(&data, &length);
803 m_module->add_interval(m_client_id, interval, false);
806 if (!data->timestamp)
810 ERR("Failed to get data for client [%d], for sensor [0x%llx]",
811 m_client_id, m_sensor_id);
815 send_cmd_get_data_done(state, data);
820 bool command_worker::cmd_send_sensorhub_data(void *payload)
822 cmd_send_sensorhub_data_t *cmd;
823 long ret_value = OP_ERROR;
825 DBG("CMD_SEND_SENSORHUB_DATA Handler invoked");
827 cmd = (cmd_send_sensorhub_data_t*)payload;
829 if (!is_permission_allowed()) {
830 ERR("Permission denied to send sensorhub_data for client [%d], for sensor [0x%llx]",
831 m_client_id, m_sensor_id);
832 ret_value = OP_ERROR;
836 ret_value = m_module->set_attribute(cmd->data, cmd->data, cmd->data_len);
839 if (!send_cmd_done(ret_value))
840 ERR("Failed to send cmd_done to a client");
845 void command_worker::get_info(string &info)
847 const char *client_info = NULL;
848 const char *sensor_info = NULL;
850 if (m_client_id != CLIENT_ID_INVALID)
851 client_info = get_client_info_manager().get_client_info(m_client_id);
854 sensor_info = m_module->get_name();
856 info = string("Command worker for ") + (client_info ? client_info : "Unknown") + "'s "
857 + (sensor_info ? sensor_info : "Unknown");
860 int command_worker::get_permission(void)
862 return permission_checker::get_instance().get_permission(m_socket.get_socket_fd());
865 bool command_worker::is_permission_allowed(void)
870 if (m_module->get_permission() & m_permission)
877 client_info_manager& command_worker::get_client_info_manager(void)
879 return client_info_manager::get_instance();
882 sensor_event_dispatcher& command_worker::get_event_dispathcher(void)
884 return sensor_event_dispatcher::get_instance();
887 void insert_priority_list(unsigned int event_type)
889 if (event_type == ORIENTATION_RAW_DATA_EVENT ||
890 event_type == LINEAR_ACCEL_RAW_DATA_EVENT ||
891 event_type == GRAVITY_RAW_DATA_EVENT ||
892 event_type == ROTATION_VECTOR_RAW_DATA_EVENT) {
893 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
894 priority_list.insert(GYROSCOPE_RAW_DATA_EVENT);
895 priority_list.insert(GEOMAGNETIC_RAW_DATA_EVENT);
898 if (event_type == GEOMAGNETIC_RV_RAW_DATA_EVENT) {
899 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
900 priority_list.insert(GEOMAGNETIC_RAW_DATA_EVENT);
903 if (event_type == GAMING_RV_RAW_DATA_EVENT) {
904 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
905 priority_list.insert(GYROSCOPE_RAW_DATA_EVENT);