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_common.h>
21 #include <sensor_loader.h>
22 #include <sensor_info.h>
23 #include <sensor_types.h>
29 #include <permission_checker.h>
30 #include <command_worker.h>
36 command_worker::cmd_handler_t command_worker::m_cmd_handlers[];
37 sensor_raw_data_map command_worker::m_sensor_raw_data_map;
38 cpacket command_worker::m_sensor_list;
40 std::set<unsigned int> priority_list;
42 command_worker::command_worker(const csocket& socket)
43 : m_client_id(CLIENT_ID_INVALID)
44 , m_permission(SENSOR_PERMISSION_NONE)
47 , m_sensor_id(UNKNOWN_SENSOR)
49 static bool init = false;
53 make_sensor_raw_data_map();
58 m_worker.set_context(this);
59 m_worker.set_working(working);
60 m_worker.set_stopped(stopped);
63 command_worker::~command_worker()
69 bool command_worker::start(void)
71 return m_worker.start();
74 void command_worker::init_cmd_handlers(void)
76 m_cmd_handlers[CMD_GET_ID] = &command_worker::cmd_get_id;
77 m_cmd_handlers[CMD_GET_SENSOR_LIST] = &command_worker::cmd_get_sensor_list;
78 m_cmd_handlers[CMD_HELLO] = &command_worker::cmd_hello;
79 m_cmd_handlers[CMD_BYEBYE] = &command_worker::cmd_byebye;
80 m_cmd_handlers[CMD_START] = &command_worker::cmd_start;
81 m_cmd_handlers[CMD_STOP] = &command_worker::cmd_stop;
82 m_cmd_handlers[CMD_REG] = &command_worker::cmd_register_event;
83 m_cmd_handlers[CMD_UNREG] = &command_worker::cmd_unregister_event;
84 m_cmd_handlers[CMD_SET_OPTION] = &command_worker::cmd_set_option;
85 m_cmd_handlers[CMD_SET_WAKEUP] = &command_worker::cmd_set_wakeup;
86 m_cmd_handlers[CMD_SET_BATCH] = &command_worker::cmd_set_batch;
87 m_cmd_handlers[CMD_UNSET_BATCH] = &command_worker::cmd_unset_batch;
88 m_cmd_handlers[CMD_GET_DATA] = &command_worker::cmd_get_data;
89 m_cmd_handlers[CMD_SET_ATTRIBUTE_INT] = &command_worker::cmd_set_attribute_int;
90 m_cmd_handlers[CMD_SET_ATTRIBUTE_STR] = &command_worker::cmd_set_attribute_str;
93 void command_worker::get_sensor_list(int permissions, cpacket &sensor_list)
95 const int PERMISSION_COUNT = sizeof(permissions) * 8;
96 vector<raw_data_t *> sensor_raw_vec;
97 size_t total_raw_data_size = 0;
99 for (int i = 0; i < PERMISSION_COUNT; ++i) {
100 int perm = (permissions & (1 << i));
103 auto range = m_sensor_raw_data_map.equal_range(perm);
105 sensor_raw_data_map::iterator it_raw_data;
107 for (it_raw_data = range.first; it_raw_data != range.second; ++it_raw_data) {
108 total_raw_data_size += it_raw_data->second.size();
109 sensor_raw_vec.push_back(&(it_raw_data->second));
116 sensor_cnt = sensor_raw_vec.size();
118 sensor_list.set_payload_size(sizeof(cmd_get_sensor_list_done_t) + (sizeof(size_t) * sensor_cnt) + total_raw_data_size);
119 sensor_list.set_cmd(CMD_GET_SENSOR_LIST);
121 cmd_get_sensor_list_done_t *cmd_get_sensor_list_done;
123 cmd_get_sensor_list_done = (cmd_get_sensor_list_done_t*)sensor_list.data();
124 cmd_get_sensor_list_done->sensor_cnt = sensor_cnt;
125 size_t* size_field = (size_t *) cmd_get_sensor_list_done->data;
128 for (int i = 0; i < sensor_cnt; ++i)
129 size_field[i] = sensor_raw_vec[i]->size();
131 char* raw_data_field = cmd_get_sensor_list_done->data + (sizeof(size_t) * sensor_cnt);
134 for (int i = 0; i < sensor_cnt; ++i) {
135 copy(sensor_raw_vec[i]->begin(), sensor_raw_vec[i]->end(), raw_data_field + idx);
136 idx += sensor_raw_vec[i]->size();
141 void command_worker::make_sensor_raw_data_map(void)
143 vector<sensor_base *> sensors;
144 vector<sensor_type_t> types;
145 std::vector<sensor_type_t>::iterator it_type;
146 std::vector<sensor_base *>::iterator it_sensor;
150 types = sensor_loader::get_instance().get_sensor_types();
152 it_type = types.begin();
153 while (it_type != types.end()) {
157 sensors = sensor_loader::get_instance().get_sensors(type);
158 it_sensor = sensors.begin();
160 while (it_sensor != sensors.end()) {
161 (*it_sensor)->get_sensor_info(info);
162 permission = (*it_sensor)->get_permission();
164 sensor_raw_data_map::iterator it_sensor_raw_data;
165 it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t()));
167 info.get_raw_data(it_sensor_raw_data->second);
175 bool command_worker::working(void *ctx)
178 command_worker *inst = (command_worker *)ctx;
180 packet_header header;
183 if (inst->m_socket.recv(&header, sizeof(header)) <= 0) {
185 inst->get_info(info);
186 _D("%s failed to receive header", info.c_str());
190 if (header.size > 0) {
192 payload = new(std::nothrow) char[header.size];
193 retvm_if(!payload, false, "Failed to allocate memory");
195 if (inst->m_socket.recv(payload, header.size) <= 0) {
197 inst->get_info(info);
198 _D("%s failed to receive data of packet", info.c_str());
206 ret = inst->dispatch_command(header.cmd, payload);
215 bool command_worker::stopped(void *ctx)
218 command_worker *inst = (command_worker *)ctx;
220 inst->get_info(info);
221 _I("%s is stopped", info.c_str());
223 if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
225 if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) {
226 _W("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name());
227 inst->m_module->delete_interval(inst->m_client_id, false);
228 inst->m_module->stop();
231 if (inst->m_sensor_id) {
232 if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) {
233 _I("Removing sensor[0x%llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id);
234 get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id);
243 bool command_worker::dispatch_command(int cmd, void* payload)
247 if (!(cmd > 0 && cmd < CMD_CNT)) {
248 _E("Unknown command: %d", cmd);
250 cmd_handler_t cmd_handler;
251 cmd_handler = command_worker::m_cmd_handlers[cmd];
253 ret = (this->*cmd_handler)(payload);
259 bool command_worker::send_cmd_done(long value)
262 cmd_done_t *cmd_done;
264 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_done_t));
265 retvm_if(!ret_packet, false, "Failed to allocate memory");
267 ret_packet->set_cmd(CMD_DONE);
269 cmd_done = (cmd_done_t*)ret_packet->data();
270 cmd_done->value = value;
272 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
273 _E("Failed to send a cmd_done to client_id [%d] with value [%ld]", m_client_id, value);
284 bool command_worker::send_cmd_get_id_done(int client_id)
287 cmd_get_id_done_t *cmd_get_id_done;
289 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_id_done_t));
290 retvm_if(!ret_packet, false, "Failed to allocate memory");
292 ret_packet->set_cmd(CMD_GET_ID);
294 cmd_get_id_done = (cmd_get_id_done_t*)ret_packet->data();
295 cmd_get_id_done->client_id = client_id;
297 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
298 _E("Failed to send a cmd_get_id_done with client_id [%d]", client_id);
307 bool command_worker::send_cmd_get_data_done(int state, sensor_data_t *data)
310 cmd_get_data_done_t *cmd_get_data_done;
312 ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_data_done_t));
313 retvm_if(!ret_packet, false, "Failed to allocate memory");
315 ret_packet->set_cmd(CMD_GET_DATA);
317 cmd_get_data_done = (cmd_get_data_done_t*)ret_packet->data();
318 cmd_get_data_done->state = state;
320 memcpy(&cmd_get_data_done->base_data , data, sizeof(sensor_data_t));
322 if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
323 _E("Failed to send a cmd_get_data_done");
333 bool command_worker::send_cmd_get_sensor_list_done(void)
337 int permission = get_permission();
339 _I("permission = 0x%x", permission);
341 get_sensor_list(permission, sensor_list);
343 if (m_socket.send(sensor_list.packet(), sensor_list.size()) <= 0) {
344 _E("Failed to send a cmd_get_sensor_list_done");
351 bool command_worker::cmd_get_id(void *payload)
356 socklen_t opt_len = sizeof(cr);
358 _D("CMD_GET_ID Handler invoked\n");
359 cmd = (cmd_get_id_t*)payload;
361 if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) {
362 _E("Failed to get socket option with SO_PEERCRED");
366 client_id = get_client_info_manager().create_client_record();
368 get_client_info_manager().set_client_info(client_id, cr.pid, cmd->name);
370 m_permission = get_permission();
371 get_client_info_manager().set_permission(client_id, m_permission);
373 _I("New client id [%d] created", client_id);
375 if (!send_cmd_get_id_done(client_id))
376 _E("Failed to send cmd_done to a client");
382 bool command_worker::cmd_get_sensor_list(void *payload)
384 _D("CMD_GET_SENSOR_LIST Handler invoked\n");
386 if (!send_cmd_get_sensor_list_done())
387 _E("Failed to send cmd_get_sensor_list_done to a client");
392 bool command_worker::cmd_hello(void *payload)
395 long ret_value = OP_ERROR;
397 _D("CMD_HELLO Handler invoked\n");
398 cmd = (cmd_hello_t*)payload;
400 m_sensor_id = cmd->sensor;
401 m_client_id = cmd->client_id;
403 if (m_permission == SENSOR_PERMISSION_NONE)
404 get_client_info_manager().get_permission(m_client_id, m_permission);
406 m_module = (sensor_base *)sensor_loader::get_instance().get_sensor(cmd->sensor);
409 _E("Sensor type[%d] is not supported", cmd->sensor);
410 if (!get_client_info_manager().has_sensor_record(m_client_id))
411 get_client_info_manager().remove_client_record(m_client_id);
413 ret_value = OP_ERROR;
417 if (!is_permission_allowed()) {
418 _E("Permission denied to connect sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
419 ret_value = OP_ERROR;
423 _D("Hello sensor [0x%llx], client id [%d]", m_sensor_id, m_client_id);
424 get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id);
425 _I("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);
426 ret_value = OP_SUCCESS;
428 if (!send_cmd_done(ret_value))
429 _E("Failed to send cmd_done to a client");
434 bool command_worker::cmd_byebye(void *payload)
436 long ret_value = OP_ERROR;
438 if (!is_permission_allowed()) {
439 _E("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
440 ret_value = OP_ERROR;
444 _D("CMD_BYEBYE for client [%d], sensor [0x%llx]", m_client_id, m_sensor_id);
446 if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) {
447 _E("Error removing sensor_record for client [%d]", m_client_id);
448 ret_value = OP_ERROR;
452 m_client_id = CLIENT_ID_INVALID;
453 ret_value = OP_SUCCESS;
456 if (!send_cmd_done(ret_value))
457 _E("Failed to send cmd_done to a client");
459 if (ret_value == OP_SUCCESS)
465 bool command_worker::cmd_start(void *payload)
467 long ret_value = OP_ERROR;
469 if (!is_permission_allowed()) {
470 _E("Permission denied to start sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
471 ret_value = OP_ERROR;
475 _D("START Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id);
477 if (m_module->start()) {
478 get_client_info_manager().set_start(m_client_id, m_sensor_id, true);
480 * Rotation could be changed even LCD is off by pop sync rotation
481 * and a client listening rotation event with always-on option.
482 * To reflect the last rotation state, request it to event dispatcher.
484 get_event_dispathcher().request_last_event(m_client_id, m_sensor_id);
485 ret_value = OP_SUCCESS;
487 _E("Failed to start sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id);
488 ret_value = OP_ERROR;
492 if (!send_cmd_done(ret_value))
493 _E("Failed to send cmd_done to a client");
498 bool command_worker::cmd_stop(void *payload)
500 long ret_value = OP_ERROR;
502 if (!is_permission_allowed()) {
503 _E("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id);
504 ret_value = OP_ERROR;
508 _D("STOP Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id);
510 if (m_module->stop()) {
511 get_client_info_manager().set_start(m_client_id, m_sensor_id, false);
512 ret_value = OP_SUCCESS;
514 _E("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id);
515 ret_value = OP_ERROR;
519 if (!send_cmd_done(ret_value))
520 _E("Failed to send cmd_done to a client");
525 bool command_worker::cmd_register_event(void *payload)
528 long ret_value = OP_ERROR;
530 cmd = (cmd_reg_t*)payload;
532 if (!is_permission_allowed()) {
533 _E("Permission denied to register event [0x%x] for client [%d] to client info manager",
534 cmd->event_type, m_client_id);
535 ret_value = OP_ERROR;
539 if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) {
540 _I("Failed to register event [0x%x] for client [%d] to client info manager",
541 cmd->event_type, m_client_id);
542 ret_value = OP_ERROR;
546 insert_priority_list(cmd->event_type);
548 ret_value = OP_SUCCESS;
549 _D("Registering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id);
552 if (!send_cmd_done(ret_value))
553 _E("Failed to send cmd_done to a client");
558 bool command_worker::cmd_unregister_event(void *payload)
561 long ret_value = OP_ERROR;
563 cmd = (cmd_unreg_t*)payload;
565 if (!is_permission_allowed()) {
566 _E("Permission denied to unregister event [0x%x] for client [%d] to client info manager",
567 cmd->event_type, m_client_id);
568 ret_value = OP_ERROR;
572 if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) {
573 _E("Failed to unregister event [0x%x] for client [%d] from client info manager",
574 cmd->event_type, m_client_id);
575 ret_value = OP_ERROR;
579 ret_value = OP_SUCCESS;
580 _D("Unregistering Event [0x%x] is done for client [%d]",
581 cmd->event_type, m_client_id);
584 if (!send_cmd_done(ret_value))
585 _E("Failed to send cmd_done to a client");
590 bool command_worker::cmd_set_batch(void *payload)
592 cmd_set_batch_t *cmd;
593 long ret_value = OP_ERROR;
595 cmd = (cmd_set_batch_t*)payload;
597 if (!is_permission_allowed()) {
598 _E("Permission denied to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager",
599 m_client_id, m_sensor_id, cmd->interval, cmd->latency);
600 ret_value = OP_ERROR;
604 if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) {
605 _E("Failed to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager",
606 m_client_id, m_sensor_id, cmd->interval, cmd->latency);
607 ret_value = OP_ERROR;
611 if (!m_module->add_interval(m_client_id, cmd->interval, false)) {
612 _E("Failed to set interval for client [%d], for sensor [0x%llx] with interval [%d]",
613 m_client_id, m_sensor_id, cmd->interval);
614 ret_value = OP_ERROR;
618 if (!m_module->add_batch(m_client_id, cmd->latency)) {
619 _E("Failed to set latency for client [%d], for sensor [0x%llx] with latency [%d]",
620 m_client_id, m_sensor_id, cmd->latency);
621 ret_value = OP_ERROR;
625 ret_value = OP_SUCCESS;
628 if (!send_cmd_done(ret_value))
629 _E("Failed to send cmd_done to a client");
634 bool command_worker::cmd_unset_batch(void *payload)
636 long ret_value = OP_ERROR;
638 if (!is_permission_allowed()) {
639 _E("Permission denied to unset batch for client [%d], for sensor [0x%llx] to client info manager",
640 m_client_id, m_sensor_id);
641 ret_value = OP_ERROR;
645 if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) {
646 _E("Failed to unset batch for client [%d], for sensor [0x%llx] to client info manager",
647 m_client_id, m_sensor_id);
648 ret_value = OP_ERROR;
652 if (!m_module->delete_interval(m_client_id, false)) {
653 _E("Failed to delete interval for client [%d]", m_client_id);
654 ret_value = OP_ERROR;
658 if (!m_module->delete_batch(m_client_id)) {
659 _E("Failed to delete latency for client [%d]", m_client_id);
660 ret_value = OP_ERROR;
664 ret_value = OP_SUCCESS;
667 if (!send_cmd_done(ret_value))
668 _E("Failed to send cmd_done to a client");
673 bool command_worker::cmd_set_option(void *payload)
675 cmd_set_option_t *cmd;
676 long ret_value = OP_ERROR;
678 cmd = (cmd_set_option_t*)payload;
680 if (!is_permission_allowed()) {
681 _E("Permission denied to set interval for client [%d], for sensor [0x%llx] with option [%d] to client info manager",
682 m_client_id, m_sensor_id, cmd->option);
683 ret_value = OP_ERROR;
687 if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) {
688 _E("Failed to set option for client [%d], for sensor [0x%llx] with option [%d] to client info manager",
689 m_client_id, m_sensor_id, cmd->option);
690 ret_value = OP_ERROR;
694 ret_value = OP_SUCCESS;
696 if (!send_cmd_done(ret_value))
697 _E("Failed to send cmd_done to a client");
702 bool command_worker::cmd_set_wakeup(void *payload)
704 cmd_set_wakeup_t *cmd;
705 long ret_value = OP_ERROR;
707 cmd = (cmd_set_wakeup_t*)payload;
709 if (!is_permission_allowed()) {
710 _E("Permission denied to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager",
711 m_client_id, m_sensor_id, cmd->wakeup);
712 ret_value = OP_ERROR;
716 if (!get_client_info_manager().set_wakeup(m_client_id, m_sensor_id, cmd->wakeup)) {
717 _E("Failed to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager",
718 m_client_id, m_sensor_id, cmd->wakeup);
719 ret_value = OP_ERROR;
723 ret_value = m_module->add_wakeup(m_client_id, cmd->wakeup);
726 if (!send_cmd_done(ret_value))
727 _E("Failed to send cmd_done to a client");
732 bool command_worker::cmd_get_data(void *payload)
734 const unsigned int GET_DATA_MIN_INTERVAL = 10;
735 int state = OP_ERROR;
737 bool adjusted = false;
742 _D("CMD_GET_VALUE Handler invoked\n");
744 if (!is_permission_allowed()) {
745 _E("Permission denied to get data for client [%d], for sensor [0x%llx]",
746 m_client_id, m_sensor_id);
751 remain_count = m_module->get_data(&data, &length);
753 // In case of not getting sensor data, wait short time and retry again
754 // 1. changing interval to be less than 10ms
755 // 2. In case of first time, wait for INIT_WAIT_TIME
756 // 3. at another time, wait for WAIT_TIME
757 // 4. retrying to get data
758 // 5. repeat 2 ~ 4 operations RETRY_CNT times
759 // 6. reverting back to original interval
760 if ((remain_count >= 0) && !data->timestamp) {
761 const int RETRY_CNT = 5;
762 const unsigned long long INIT_WAIT_TIME = 20000; //20ms
763 const unsigned long WAIT_TIME = 100000; //100ms
766 unsigned int interval = m_module->get_interval(m_client_id, false);
768 if (interval > GET_DATA_MIN_INTERVAL) {
769 m_module->add_interval(m_client_id, GET_DATA_MIN_INTERVAL, false);
773 while ((remain_count >= 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
774 _I("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry);
775 usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME);
776 remain_count = m_module->get_data(&data, &length);
780 m_module->add_interval(m_client_id, interval, false);
787 _E("Failed to get data for client [%d], for sensor [0x%llx]",
788 m_client_id, m_sensor_id);
792 send_cmd_get_data_done(state, data);
797 bool command_worker::cmd_set_attribute_int(void *payload)
799 cmd_set_attribute_int_t *cmd;
800 long ret_value = OP_ERROR;
802 _D("CMD_SET_COMMAND Handler invoked\n");
804 cmd = (cmd_set_attribute_int_t*)payload;
806 if (!is_permission_allowed()) {
807 _E("Permission denied to set command for client [%d], for sensor [0x%llx] with attribute [%d]",
808 m_client_id, m_sensor_id, cmd->attribute);
809 ret_value = OP_ERROR;
813 ret_value = m_module->set_attribute(cmd->attribute, cmd->value);
816 if (!send_cmd_done(ret_value))
817 _E("Failed to send cmd_done to a client");
822 bool command_worker::cmd_set_attribute_str(void *payload)
824 cmd_set_attribute_str_t *cmd;
825 long ret_value = OP_ERROR;
827 _D("CMD_SEND_SENSORHUB_DATA Handler invoked");
829 cmd = (cmd_set_attribute_str_t*)payload;
831 if (!is_permission_allowed()) {
832 _E("Permission denied to send sensorhub_data for client [%d], for sensor [0x%llx]",
833 m_client_id, m_sensor_id);
834 ret_value = OP_ERROR;
838 ret_value = m_module->set_attribute(cmd->attribute, cmd->value, cmd->value_len);
841 if (!send_cmd_done(ret_value))
842 _E("Failed to send cmd_done to a client");
847 void command_worker::get_info(string &info)
849 const char *client_info = NULL;
850 const char *sensor_info = NULL;
852 if (m_client_id != CLIENT_ID_INVALID)
853 client_info = get_client_info_manager().get_client_info(m_client_id);
856 sensor_info = m_module->get_name();
858 info = string("Command worker for ") + (client_info ? client_info : "Unknown") + "'s "
859 + (sensor_info ? sensor_info : "Unknown");
862 int command_worker::get_permission(void)
864 return permission_checker::get_instance().get_permission(m_socket.get_socket_fd());
867 bool command_worker::is_permission_allowed(void)
872 if (m_module->get_permission() & m_permission)
879 client_info_manager& command_worker::get_client_info_manager(void)
881 return client_info_manager::get_instance();
884 sensor_event_dispatcher& command_worker::get_event_dispathcher(void)
886 return sensor_event_dispatcher::get_instance();
889 void insert_priority_list(unsigned int event_type)
891 if (event_type == ORIENTATION_RAW_DATA_EVENT ||
892 event_type == LINEAR_ACCEL_RAW_DATA_EVENT ||
893 event_type == GRAVITY_RAW_DATA_EVENT ||
894 event_type == ROTATION_VECTOR_RAW_DATA_EVENT) {
895 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
896 priority_list.insert(GYROSCOPE_RAW_DATA_EVENT);
897 priority_list.insert(GEOMAGNETIC_RAW_DATA_EVENT);
900 if (event_type == GEOMAGNETIC_RV_RAW_DATA_EVENT) {
901 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
902 priority_list.insert(GEOMAGNETIC_RAW_DATA_EVENT);
905 if (event_type == GAMING_RV_RAW_DATA_EVENT) {
906 priority_list.insert(ACCELEROMETER_RAW_DATA_EVENT);
907 priority_list.insert(GYROSCOPE_RAW_DATA_EVENT);