From a73a1e0cb299ad881d878313637df1ab31a5ae59 Mon Sep 17 00:00:00 2001 From: "hs81.go" Date: Thu, 1 Sep 2016 15:20:22 +0900 Subject: [PATCH 01/16] sensord: change an input value name of set_attribute function because a name is not clear which is 'value_len' in set_attribute function so 'value_len' is changed to 'len'. Change-Id: I19caa23268e451653139c2b5f5c73af22edffe95 Signed-off-by: hs81.go --- src/client/client.cpp | 6 +++--- src/client/command_channel.cpp | 10 +++++----- src/client/command_channel.h | 2 +- src/client/sensor_internal.h | 2 +- src/hal/sensor_hal.h | 2 +- src/server/command_worker.cpp | 2 +- src/server/physical_sensor.cpp | 4 ++-- src/server/physical_sensor.h | 2 +- src/shared/command_common.h | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index b01b607..0f69a1d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -194,10 +194,10 @@ bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_ for (auto it = info.attributes_str.begin(); it != info.attributes_str.end(); ++it) { int attribute = it->first; const char *value = it->second->get(); - int value_len = it->second->size(); - if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { + int len = it->second->size(); + if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) { _E("Failed to send cmd_set_attribute_str(%d, %d, %s) for %s", - client_id, value_len, value, get_client_name()); + client_id, len, value, get_client_name()); return false; } } diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index 39c3d4d..319c960 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -639,24 +639,24 @@ bool command_channel::cmd_set_attribute_int(int attribute, int value) return true; } -bool command_channel::cmd_set_attribute_str(int attribute, const char* value, int value_len) +bool command_channel::cmd_set_attribute_str(int attribute, const char* value, int len) { cpacket *packet; cmd_set_attribute_str_t *cmd_set_attribute_str; cmd_done_t *cmd_done; - packet = new(std::nothrow) cpacket(sizeof(cmd_set_attribute_str_t) + value_len); + packet = new(std::nothrow) cpacket(sizeof(cmd_set_attribute_str_t) + len); retvm_if(!packet, false, "Failed to allocate memory"); packet->set_cmd(CMD_SET_ATTRIBUTE_STR); cmd_set_attribute_str = (cmd_set_attribute_str_t*)packet->data(); cmd_set_attribute_str->attribute = attribute; - cmd_set_attribute_str->value_len = value_len; - memcpy(cmd_set_attribute_str->value, value, value_len); + cmd_set_attribute_str->len = len; + memcpy(cmd_set_attribute_str->value, value, len); _I("%s send cmd_set_attribute_str(client_id=%d, attribute = %#x, value_len = %d, value = %#x)", - get_client_name(), m_client_id, attribute, value_len, value); + get_client_name(), m_client_id, attribute, len, value); if (!command_handler(packet, (void **)&cmd_done)) { _E("%s failed to send/receive command with client_id [%d]", diff --git a/src/client/command_channel.h b/src/client/command_channel.h index 2dd3589..0a9cbc4 100644 --- a/src/client/command_channel.h +++ b/src/client/command_channel.h @@ -48,7 +48,7 @@ public: bool cmd_unset_batch(void); bool cmd_get_data(unsigned int type, sensor_data_t *values); bool cmd_set_attribute_int(int attribute, int value); - bool cmd_set_attribute_str(int attribute, const char *value, int value_len); + bool cmd_set_attribute_str(int attribute, const char *value, int len); bool cmd_flush(void); private: diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index 3cc6641..47452d4 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -349,7 +349,7 @@ int sensord_set_attribute_int(int handle, int attribute, int value); * @retval -EINVAL Invalid parameter * @retval -EPERM Operation not permitted */ -int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len); +int sensord_set_attribute_str(int handle, int attribute, const char *value, int len); /** * @brief Send data to sensorhub diff --git a/src/hal/sensor_hal.h b/src/hal/sensor_hal.h index e557687..d90053c 100644 --- a/src/hal/sensor_hal.h +++ b/src/hal/sensor_hal.h @@ -62,7 +62,7 @@ public: { return true; } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len) + virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int len) { return true; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index f3fd9e9..d978481 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -786,7 +786,7 @@ bool command_worker::cmd_set_attribute_str(void *payload) goto out; } - ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value, cmd->value_len); + ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value, cmd->len); out: if (!send_cmd_done(ret_value)) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 96cb7f0..fc16b7b 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -165,14 +165,14 @@ int physical_sensor::set_attribute(int32_t attribute, int32_t value) return OP_SUCCESS; } -int physical_sensor::set_attribute(int32_t attribute, char *value, int value_len) +int physical_sensor::set_attribute(int32_t attribute, char *value, int len) { AUTOLOCK(m_mutex); if (!m_sensor_device) return OP_ERROR; - if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, value_len)) + if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, len)) return OP_ERROR; return OP_SUCCESS; diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index 3db1791..1264931 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -55,7 +55,7 @@ protected: virtual bool on_start(void); virtual bool on_stop(void); virtual int set_attribute(int32_t attribute, int32_t value); - virtual int set_attribute(int32_t attribute, char *value, int value_len); + virtual int set_attribute(int32_t attribute, char *value, int len); virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); virtual bool get_sensor_info(sensor_info &info); diff --git a/src/shared/command_common.h b/src/shared/command_common.h index 2afb3bd..47c47b1 100644 --- a/src/shared/command_common.h +++ b/src/shared/command_common.h @@ -132,7 +132,7 @@ typedef struct { typedef struct { int attribute; - int value_len; + int len; char value[0]; } cmd_set_attribute_str_t; -- 2.7.4 From dc67ca3e8bcb27c6255db5de2b12536adf4d54c9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 21 Sep 2016 00:41:28 +0900 Subject: [PATCH 02/16] sensord: fix socket issue when client cannot receive the event if client is blocked because of some reason, e.g., works heavy in mainloop, sensor daemon is also blocked about sending sensor event. Change-Id: I35ec9f43065594f55e413244470c74fc1c3f2ff1 Signed-off-by: kibak.yoon --- src/client/client_common.h | 17 ++++ src/client/sensor_callback_deliverer.cpp | 155 +++++++++++++++++++++++++++++++ src/client/sensor_callback_deliverer.h | 54 +++++++++++ src/client/sensor_event_listener.cpp | 139 +++++++++++++-------------- src/client/sensor_event_listener.h | 31 ++----- 5 files changed, 298 insertions(+), 98 deletions(-) create mode 100644 src/client/sensor_callback_deliverer.cpp create mode 100644 src/client/sensor_callback_deliverer.h diff --git a/src/client/client_common.h b/src/client/client_common.h index 77e71f7..5671987 100644 --- a/src/client/client_common.h +++ b/src/client/client_common.h @@ -25,7 +25,24 @@ #include #include +#include + #define BASE_GATHERING_INTERVAL 100 +#define THREAD_TERMINATION -1 + +typedef struct { + unsigned long long event_id; + int handle; + sensor_t sensor; + unsigned int event_type; + sensor_cb_t cb; + std::shared_ptr sensor_data; + void *user_data; + sensor_accuracy_changed_cb_t accuracy_cb; + unsigned long long timestamp; + int accuracy; + void *accuracy_user_data; +} client_callback_info; const char *get_sensor_name(sensor_id_t sensor_id); const char *get_event_name(unsigned int event_type); diff --git a/src/client/sensor_callback_deliverer.cpp b/src/client/sensor_callback_deliverer.cpp new file mode 100644 index 0000000..9af3790 --- /dev/null +++ b/src/client/sensor_callback_deliverer.cpp @@ -0,0 +1,155 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +sensor_callback_deliverer::sensor_callback_deliverer() +: m_running(false) +, m_callbacks(NULL) +{ +} + +sensor_callback_deliverer::~sensor_callback_deliverer() +{ +} + +bool sensor_callback_deliverer::start(void) +{ + if (is_running()) + return true; + + m_callbacks = g_async_queue_new(); + retvm_if(!m_callbacks, false, "Failed to allocated memory"); + + m_deliverer = new(std::nothrow) std::thread(&sensor_callback_deliverer::run, this); + + if (!m_deliverer) { + g_async_queue_unref(m_callbacks); + _E("Failed to allocated memory"); + return false; + } + + m_running = true; + + _I("Succeeded to start"); + + return true; +} + +bool sensor_callback_deliverer::stop(void) +{ + if (!is_running()) + return true; + + if (!terminate()) + return false; + + m_deliverer->join(); + delete m_deliverer; + + g_async_queue_unref(m_callbacks); + + _I("Succeeded to stop"); + + return true; +} + +bool sensor_callback_deliverer::is_running(void) +{ + return m_running.load(); +} + +bool sensor_callback_deliverer::push(client_callback_info *ci) +{ + if (!is_running()) + return false; + + retvm_if(!ci, false, "Invalid callback"); + + g_async_queue_push(m_callbacks, ci); + + return true; +} + +gboolean sensor_callback_deliverer::callback_dispatcher(gpointer data) +{ + bool ret; + client_callback_info *ci = (client_callback_info *)data; + + ret = sensor_client_info::get_instance().is_event_active(ci->handle, ci->event_type, ci->event_id); + + if (!ret) { + _W("Discard invalid callback cb(%#x)(%s, %#x, %#x) with id: %llu", + ci->cb, get_event_name(ci->event_type), ci->sensor_data.get(), + ci->user_data, ci->event_id); + + delete ci; + return FALSE; + } + + if (ci->accuracy_cb) + ci->accuracy_cb(ci->sensor, ci->timestamp, ci->accuracy, ci->accuracy_user_data); + + if (ci->cb) + ci->cb(ci->sensor, ci->event_type, (sensor_data_t *)ci->sensor_data.get(), ci->user_data); + + delete ci; + + /* To be called only once, it returns false */ + return FALSE; +} + +void sensor_callback_deliverer::run(void) +{ + client_callback_info *ci; + + while (is_running()) { + ci = static_cast(g_async_queue_pop(m_callbacks)); + + if (ci->handle == THREAD_TERMINATION) { + m_running = false; + delete ci; + return; + } + + deliver_to_main_loop(ci); + } +} + +bool sensor_callback_deliverer::terminate(void) +{ + client_callback_info *ci = new(std::nothrow) client_callback_info; + retvm_if(!ci, false, "Failed to allocated memory"); + + ci->handle = THREAD_TERMINATION; + g_async_queue_push(m_callbacks, ci); + + return true; +} + +void sensor_callback_deliverer::deliver_to_main_loop(client_callback_info *ci) +{ + /* + * Because callback function always returns FALSE, + * it is unnecessary to manage g_source id returned from g_idle_add(). + */ + g_idle_add(callback_dispatcher, ci); +} diff --git a/src/client/sensor_callback_deliverer.h b/src/client/sensor_callback_deliverer.h new file mode 100644 index 0000000..db2145d --- /dev/null +++ b/src/client/sensor_callback_deliverer.h @@ -0,0 +1,54 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _SENSOR_CALLBACK_DELIVERER_H_ +#define _SENSOR_CALLBACK_DELIVERER_H_ + +#include +#include + +#include +#include + +class sensor_callback_deliverer { +public: + sensor_callback_deliverer(); + ~sensor_callback_deliverer(); + + bool start(void); + bool stop(void); + bool is_running(void); + + bool push(client_callback_info *ci); + +private: + static gboolean callback_dispatcher(gpointer data); + + std::atomic_bool m_running; + + GAsyncQueue *m_callbacks; + std::thread *m_deliverer; + + void run(void); + bool terminate(void); + + void deliver_to_main_loop(client_callback_info *ci); +}; + +#endif /* _SENSOR_CALLBACK_DELIVERER_H_ */ diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index dc03f3b..dc40271 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -113,12 +113,14 @@ void sensor_event_listener::handle_events(void* event) unsigned int event_type = *((unsigned int *)(event)); client_callback_info* callback_info = NULL; - vector client_callback_infos; sensor_event_t *sensor_event = (sensor_event_t *)event; sensor_id = sensor_event->sensor_id; cur_time = sensor_event->data->timestamp; accuracy = sensor_event->data->accuracy; + + align_sensor_axis(sensor_id, sensor_event->data); + std::shared_ptr sensor_data(sensor_event->data, free_data()); { /* scope for the lock */ @@ -141,7 +143,7 @@ void sensor_event_listener::handle_events(void* event) client_callback_info* cal_callback_info = handle_calibration_cb(sensor_handle_info, event_type, cur_time, accuracy); if (cal_callback_info) - client_callback_infos.push_back(cal_callback_info); + m_cb_deliverer->push(cal_callback_info); callback_info = get_callback_info(sensor_id, event_info, sensor_data); @@ -159,18 +161,11 @@ void sensor_event_listener::handle_events(void* event) callback_info->accuracy_user_data = sensor_handle_info.m_accuracy_user_data; } - client_callback_infos.push_back(callback_info); + m_cb_deliverer->push(callback_info); print_event_occurrence_log(sensor_handle_info); } } - - auto it_calback_info = client_callback_infos.begin(); - - while (it_calback_info != client_callback_infos.end()) { - post_callback_to_main_loop(*it_calback_info); - ++it_calback_info; - } } client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, std::shared_ptr sensor_data) @@ -183,7 +178,7 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso callback_info->sensor = sensor_info_to_sensor(sensor_info_manager::get_instance().get_info(sensor_id)); callback_info->event_id = event_info->m_id; callback_info->handle = event_info->m_handle; - callback_info->cb = event_info->m_cb; + callback_info->cb = (sensor_cb_t)(event_info->m_cb); callback_info->event_type = event_info->type; callback_info->user_data = event_info->m_user_data; callback_info->accuracy_cb = NULL; @@ -195,24 +190,14 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso return callback_info; } -void sensor_event_listener::post_callback_to_main_loop(client_callback_info* cb_info) -{ - g_idle_add_full(G_PRIORITY_DEFAULT, callback_dispatcher, cb_info, NULL); -} - -bool sensor_event_listener::is_valid_callback(client_callback_info *cb_info) -{ - return m_client_info.is_event_active(cb_info->handle, cb_info->event_type, cb_info->event_id); -} - void sensor_event_listener::set_sensor_axis(int axis) { m_axis = axis; } -void sensor_event_listener::align_sensor_axis(sensor_t sensor, sensor_data_t *data) +void sensor_event_listener::align_sensor_axis(sensor_id_t sensor, sensor_data_t *data) { - sensor_type_t type = sensor_to_sensor_info(sensor)->get_type(); + sensor_id_t type = CONVERT_ID_TYPE(sensor); if (m_axis != SENSORD_AXIS_DISPLAY_ORIENTED) return; @@ -243,33 +228,6 @@ void sensor_event_listener::align_sensor_axis(sensor_t sensor, sensor_data_t *da data->values[1] = y; } -gboolean sensor_event_listener::callback_dispatcher(gpointer data) -{ - client_callback_info *cb_info = (client_callback_info*) data; - - if (!sensor_event_listener::get_instance().is_valid_callback(cb_info)) { - _W("Discard invalid callback cb(%#x)(%s, %#x, %#x) with id: %llu", - cb_info->cb, get_event_name(cb_info->event_type), cb_info->sensor_data.get(), - cb_info->user_data, cb_info->event_id); - - delete cb_info; - return false; - } - - if (cb_info->accuracy_cb) - cb_info->accuracy_cb(cb_info->sensor, cb_info->timestamp, cb_info->accuracy, cb_info->accuracy_user_data); - - sensor_event_listener::get_instance().align_sensor_axis(cb_info->sensor, (sensor_data_t *)cb_info->sensor_data.get()); - ((sensor_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensor_data_t *)cb_info->sensor_data.get(), cb_info->user_data); - - delete cb_info; - -/* -* To be called only once, it returns false -*/ - return false; -} - ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event) { ssize_t len; @@ -333,13 +291,6 @@ void sensor_event_listener::listen_events(void) handle_events((void *)buffer); } while (true); - if (m_poller != NULL) { - delete m_poller; - m_poller = NULL; - } - - close_event_channel(); - { /* the scope for the lock */ lock l(m_thread_mutex); m_thread_state = THREAD_STATE_TERMINATE; @@ -408,24 +359,6 @@ void sensor_event_listener::close_event_channel(void) m_event_socket.close(); } -void sensor_event_listener::stop_event_listener(void) -{ - const int THREAD_TERMINATING_TIMEOUT = 2; - - ulock u(m_thread_mutex); - - if (m_thread_state != THREAD_STATE_TERMINATE) { - m_thread_state = THREAD_STATE_STOP; - - _D("%s is waiting listener thread[state: %d] to be terminated", get_client_name(), m_thread_state); - if (m_thread_cond.wait_for(u, std::chrono::seconds(THREAD_TERMINATING_TIMEOUT)) - == std::cv_status::timeout) - _E("Fail to stop listener thread after waiting %d seconds", THREAD_TERMINATING_TIMEOUT); - else - _D("Listener thread for %s is terminated", get_client_name()); - } -} - void sensor_event_listener::set_thread_state(thread_state state) { lock l(m_thread_mutex); @@ -453,6 +386,9 @@ bool sensor_event_listener::start_event_listener(void) return false; } + if (!start_deliverer()) + return false; + m_event_socket.set_transfer_mode(); m_poller = new(std::nothrow) poller(m_event_socket.get_socket_fd()); @@ -466,6 +402,59 @@ bool sensor_event_listener::start_event_listener(void) return true; } +void sensor_event_listener::stop_event_listener(void) +{ + const int THREAD_TERMINATING_TIMEOUT = 2; + std::cv_status status; + + ulock u(m_thread_mutex); + + /* TOBE: it can be changed to join() simply */ + if (m_thread_state != THREAD_STATE_TERMINATE) { + m_thread_state = THREAD_STATE_STOP; + + _D("%s is waiting listener thread[state: %d] to be terminated", get_client_name(), m_thread_state); + + status = m_thread_cond.wait_for(u, std::chrono::seconds(THREAD_TERMINATING_TIMEOUT)); + if (status == std::cv_status::timeout) + _E("Fail to stop listener thread after waiting %d seconds", THREAD_TERMINATING_TIMEOUT); + else + _D("Listener thread for %s is terminated", get_client_name()); + } + + if (m_poller) { + delete m_poller; + m_poller = NULL; + } + + stop_deliverer(); + close_event_channel(); +} + +bool sensor_event_listener::start_deliverer(void) +{ + if (!m_cb_deliverer) { + m_cb_deliverer = new(std::nothrow) sensor_callback_deliverer(); + retvm_if(!m_cb_deliverer, false, "Failed to allocated memory"); + } + + m_cb_deliverer->start(); + return true; +} + +bool sensor_event_listener::stop_deliverer(void) +{ + if (!m_cb_deliverer) + return false; + + if (!m_cb_deliverer->stop()) + return false; + + delete m_cb_deliverer; + m_cb_deliverer = NULL; + return true; +} + void sensor_event_listener::set_display_rotation(int rt) { _D("New display rotation: %d", rt); diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 9631a63..63dd6d9 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -41,26 +41,13 @@ #include #include #include +#include typedef std::vector handle_vector; typedef std::vector sensor_id_vector; typedef std::unordered_map sensor_handle_info_map; typedef std::unordered_map sensor_command_channel_map; -typedef struct { - unsigned long long event_id; - int handle; - sensor_t sensor; - unsigned int event_type; - void *cb; - std::shared_ptr sensor_data; - void *user_data; - sensor_accuracy_changed_cb_t accuracy_cb; - unsigned long long timestamp; - int accuracy; - void *accuracy_user_data; -} client_callback_info; - typedef void (*hup_observer_t)(void); class sensor_event_listener { @@ -98,6 +85,8 @@ private: sensor_client_info &m_client_info; + sensor_callback_deliverer *m_cb_deliverer; + /* WC1's rotation control */ /* SENSORD_AXIS_DEVICE_ORIENTED, SENSORD_AXIS_DISPLAY_ORIENTED */ int m_axis; @@ -106,30 +95,26 @@ private: sensor_event_listener(); ~sensor_event_listener(); - sensor_event_listener& operator=(const sensor_event_listener&); - bool create_event_channel(void); void close_event_channel(void); ssize_t sensor_event_poll(void *buffer, int buffer_len, struct epoll_event &event); void listen_events(void); - client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy); void handle_events(void* event); + client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy); client_callback_info* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, std::shared_ptr sensor_data); unsigned long long renew_event_id(void); - void post_callback_to_main_loop(client_callback_info *cb_info); - - bool is_valid_callback(client_callback_info *cb_info); - static gboolean callback_dispatcher(gpointer data); - void set_thread_state(thread_state state); /* WC1's sensor axis alignment */ - void align_sensor_axis(sensor_t sensor, sensor_data_t *data); + void align_sensor_axis(sensor_id_t sensor, sensor_data_t *data); + + bool start_deliverer(void); + bool stop_deliverer(void); }; #endif /* _SENSOR_EVENT_LISTENER_H_ */ -- 2.7.4 From 91c8bc6f668275ff47e9d183955ba2eb8177c4ef Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 18 Jul 2016 20:19:11 +0900 Subject: [PATCH 03/16] sensord: return false if the size of id is 0 - If the size of ids is zero, it doesn't need to process the next works. - It doesn't make a problem although it is not fixed. but it would be better to reduce the unnecessary work. Change-Id: I2187d738ee90bae47cb4276b39b5651afa771b97 Signed-off-by: kibak.yoon --- src/server/physical_sensor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index fc16b7b..65ab74e 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -94,6 +94,9 @@ bool physical_sensor::read_fd(std::vector &ids) size = m_sensor_device->read_fd(&_ids); + if (size == 0) + return false; + for (int i = 0; i < size; ++i) ids.push_back(_ids[i]); -- 2.7.4 From d8fd5fc7d62734a8a78566c596cc106e27c0fe8a Mon Sep 17 00:00:00 2001 From: akhilkedia94 Date: Wed, 28 Sep 2016 12:45:34 +0900 Subject: [PATCH 04/16] [face_down_sensor] increasing the window size to increase detection rate Change-Id: I7095440151ff4117442f0d0f2d8e22717a2b3a97 Signed-off-by: akhilkedia94 --- src/sensor/gesture/face_down_alg_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensor/gesture/face_down_alg_impl.cpp b/src/sensor/gesture/face_down_alg_impl.cpp index 93e3762..611d539 100644 --- a/src/sensor/gesture/face_down_alg_impl.cpp +++ b/src/sensor/gesture/face_down_alg_impl.cpp @@ -24,7 +24,7 @@ #define GRAVITY 9.80665 #define TWENTY_DEGREES 0.349066 #define ONE_SIXTY_DEGREES 2.79253 -#define WINDOW_SIZE (2000*100) +#define WINDOW_SIZE (2000*1000) face_down_alg_impl::face_down_alg_impl() { -- 2.7.4 From 874da34a65158036cd2711e8d210c9bfd4bf1363 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 28 Sep 2016 13:54:50 +0900 Subject: [PATCH 05/16] sensord: enable rv/gesture sensors in CMakeLists * remove the unused macro for motion sensor Change-Id: I198014b1355cc395891c403fe1f2c385b40cada1 Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 33c3fe0..3ec60fd 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -7,14 +7,8 @@ SET(HRM_VIRT "OFF") SET(AUTO_ROTATION "ON") SET(GRAVITY "ON") SET(LINEAR_ACCEL "ON") -IF(${ARCH} STREQUAL "EMULATOR") SET(RV "ON") SET(ORIENTATION "ON") -ELSE() -SET(RV "OFF") -SET(ORIENTATION "OFF") -ENDIF() -SET(MOTION "OFF") SET(FACE_DOWN "ON") INCLUDE_DIRECTORIES( @@ -69,9 +63,6 @@ IF("${FACE_DOWN}" STREQUAL "ON") SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/gesture) SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_FACE_DOWN") ENDIF() -IF("${MOTION}" STREQUAL "ON") -add_subdirectory(motion) -ENDIF() MESSAGE("${SENSOR_SRCS}") SET(SENSOR_SRCS ${SENSOR_SRCS} PARENT_SCOPE) -- 2.7.4 From 5966e367c95913e60ee91df5d8ac4d5c1b9ab0e0 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 28 Sep 2016 14:28:47 +0900 Subject: [PATCH 06/16] sensord: version 2.0.8 Change-Id: I4f09f8202b551b1c0ed367998ffad47ff5bb08b2 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 0aa4f0f..fe4facf 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.7 +Version: 2.0.8 Release: 0 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From 7e249a8b19cea3f6c11968942460eb75da382fb1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 26 Oct 2016 15:36:07 +0900 Subject: [PATCH 07/16] sensor: change the hard coded path for supporting 64bit platform Change-Id: Ie1940344d79527a4fe153491a566b32da46c9f2d Signed-off-by: kibak.yoon --- packaging/sensord.spec | 8 ++------ src/server/CMakeLists.txt | 1 + src/server/sensor_loader.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index fe4facf..b1439b8 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -20,10 +20,6 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) Requires: libsensord = %{version}-%{release} -%ifarch %{ix86} x86_64 -%define BUILD_ARCH EMULATOR -%endif - %description Sensor daemon @@ -61,8 +57,8 @@ Sensor functional testing %setup -q MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} \ - -DARCH=%{BUILD_ARCH} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} \ + -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %build make %{?jobs:-j%jobs} diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 763e904..c71bcec 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -8,6 +8,7 @@ PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS}) ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../sensor ${CMAKE_CURRENT_BINARY_DIR}/sensor) ADD_DEFINITIONS(${SENSOR_DEFINITIONS}) +ADD_DEFINITIONS(-DLIBDIR="${LIBDIR}") FOREACH(flag ${SERVER_PKGS_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 21694c8..89d678b 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -57,7 +57,7 @@ using std::vector; using std::string; -#define DEVICE_HAL_DIR_PATH "/usr/lib/sensor" +#define DEVICE_HAL_DIR_PATH LIBDIR "/sensor" sensor_loader::sensor_loader() { -- 2.7.4 From b026f61b5a21f776be5e561f548c760a455929a1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 3 Nov 2016 17:48:16 +0900 Subject: [PATCH 08/16] sensord: fix the bug that handles are pushed to a list regardless of return value Change-Id: Ibf13b5262ae66274b758b065822c634959f5bbbb Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 89d678b..f606d29 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -105,8 +105,8 @@ bool sensor_loader::load(void) for_each(unique_device_hal_paths.begin(), unique_device_hal_paths.end(), [&](const string &path) { void *handle; - load_sensor_devices(path, handle); - m_handles.push_back(handle); + if (load_sensor_devices(path, handle)) + m_handles.push_back(handle); } ); -- 2.7.4 From b596e1f1297a7fe6d3e14c43ac81e827fa84c5fd Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 9 Nov 2016 17:41:46 +0900 Subject: [PATCH 09/16] sensord: change log level from error to warning for the warning case - when applications access not-supported sensors, it doesn't need to print error level logs. Change-Id: I1d98d0ebd85bf3d12a673e320a39d2942d53cc9a Signed-off-by: kibak.yoon --- src/client/client.cpp | 6 +-- src/client/command_channel.cpp | 2 +- src/client/sensor_client_info.cpp | 46 +++++++++++------------ src/sensor/auto_rotation/auto_rotation_sensor.cpp | 2 +- src/sensor/gesture/face_down_sensor.cpp | 2 +- src/sensor/gravity/gravity_sensor.cpp | 4 +- src/sensor/linear_accel/linear_accel_sensor.cpp | 4 +- src/sensor/orientation/orientation_sensor.cpp | 2 +- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 2 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 2 +- src/sensor/rotation_vector/rv_sensor.cpp | 2 +- src/sensor/tilt/tilt_sensor.cpp | 12 +++--- src/server/command_worker.cpp | 8 +++- src/server/sensor_loader.cpp | 2 +- src/server/server.cpp | 5 ++- src/server/worker_thread.cpp | 2 +- src/shared/csocket.cpp | 38 +++++-------------- 17 files changed, 65 insertions(+), 76 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 0f69a1d..7d22d9f 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -612,9 +612,7 @@ API int sensord_connect(sensor_t sensor) bool first_connection = false; sensor_info* info = sensor_to_sensor_info(sensor); - - retvm_if(!sensor_info_manager::get_instance().is_valid(info), - OP_ERROR, "Invalid param: sensor (%p)", sensor); + retv_if(!sensor_info_manager::get_instance().is_valid(info), OP_ERROR); sensor_id_t sensor_id = info->get_id(); @@ -783,7 +781,7 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int AUTOLOCK(lock); if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) { - _E("client %s failed to get handle information", get_client_name()); + _W("client %s failed to get handle information", get_client_name()); return false; } diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index 319c960..683c017 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -212,7 +212,7 @@ bool command_channel::cmd_hello(sensor_id_t sensor) } if (cmd_done->value < 0) { - _E("client %s got error[%d] from server with sensor [%s]", + _W("client %s got value[%d] from server with sensor [%s]", get_client_name(), cmd_done->value, get_sensor_name(sensor)); delete[] (char *)cmd_done; diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index d027d8a..743cd29 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -53,7 +53,7 @@ int sensor_client_info::create_handle(sensor_id_t sensor) handle++; if (handle == MAX_HANDLE) { - _E("Handles of client %s are full", get_client_name()); + _W("Handles of client %s are full", get_client_name()); return MAX_HANDLE_REACHED; } @@ -77,7 +77,7 @@ bool sensor_client_info::delete_handle(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -100,7 +100,7 @@ bool sensor_client_info::register_event(int handle, unsigned int event_type, auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -117,7 +117,7 @@ bool sensor_client_info::unregister_event(int handle, unsigned int event_type) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -134,7 +134,7 @@ bool sensor_client_info::register_accuracy_cb(int handle, sensor_accuracy_change auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -152,7 +152,7 @@ bool sensor_client_info::unregister_accuracy_cb(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -170,7 +170,7 @@ bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int pau auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -187,7 +187,7 @@ bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &p auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -204,7 +204,7 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -220,7 +220,7 @@ bool sensor_client_info::get_passive_mode(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -234,7 +234,7 @@ bool sensor_client_info::set_passive_mode(int handle, bool passive) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -250,7 +250,7 @@ bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -266,7 +266,7 @@ bool sensor_client_info::set_event_batch(int handle, unsigned int event_type, un auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -283,7 +283,7 @@ bool sensor_client_info::set_accuracy(int handle, int accuracy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -299,7 +299,7 @@ bool sensor_client_info::set_bad_accuracy(int handle, int bad_accuracy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -315,7 +315,7 @@ bool sensor_client_info::get_event_info(int handle, unsigned int event_type, uns auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -367,7 +367,7 @@ bool sensor_client_info::add_command_channel(sensor_id_t sensor, command_channel auto it_channel = m_command_channels.find(sensor); if (it_channel != m_command_channels.end()) { - _E("%s alreay has command_channel for %s", get_client_name(), get_sensor_name(sensor)); + _W("%s alreay has command_channel for %s", get_client_name(), get_sensor_name(sensor)); return false; } @@ -381,7 +381,7 @@ bool sensor_client_info::get_command_channel(sensor_id_t sensor, command_channel auto it_channel = m_command_channels.find(sensor); if (it_channel == m_command_channels.end()) { - _E("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor)); + _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor)); return false; } @@ -409,7 +409,7 @@ bool sensor_client_info::close_command_channel(sensor_id_t sensor_id) auto it_channel = m_command_channels.find(sensor_id); if (it_channel == m_command_channels.end()) { - _E("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor_id)); + _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor_id)); return false; } @@ -501,7 +501,7 @@ bool sensor_client_info::get_sensor_id(int handle, sensor_id_t &sensor) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -517,7 +517,7 @@ bool sensor_client_info::get_sensor_state(int handle, int &sensor_state) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -673,7 +673,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, int value) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -689,7 +689,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, const char *va auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 470d5d8..c3bd18e 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -59,7 +59,7 @@ bool auto_rotation_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accel sensor_hal from %s", get_name()); + _W("cannot load accel sensor_hal from %s", get_name()); return false; } diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp index 9aca0f4..03ddf7c 100644 --- a/src/sensor/gesture/face_down_sensor.cpp +++ b/src/sensor/gesture/face_down_sensor.cpp @@ -57,7 +57,7 @@ bool face_down_sensor::init(void) m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); if (!m_gravity_sensor) { - _E("cannot load gravity sensor sensor[%s]", SENSOR_NAME); + _W("cannot load gravity sensor sensor[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 931940a..d4c74ce 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -77,7 +77,7 @@ bool gravity_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accelerometer sensor_hal[%s]", get_name()); + _W("cannot load accelerometer sensor_hal[%s]", get_name()); return false; } @@ -150,7 +150,7 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event) int accuracy; if (!m_fusion->get_rotation_vector(x, y, z, w, heading_accuracy, accuracy)) { - _E("Failed to get rotation vector"); + _W("Failed to get rotation vector"); return; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index f5ad037..56af7b6 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -63,14 +63,14 @@ bool linear_accel_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accelerometer sensor_hal[%s]", get_name()); + _W("cannot load accelerometer sensor_hal[%s]", get_name()); return false; } m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); if (!m_gravity_sensor) { - _E("cannot load gravity sensor_hal[%s]", get_name()); + _W("cannot load gravity sensor_hal[%s]", get_name()); return false; } diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index 8f4bd79..c9cad8b 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -57,7 +57,7 @@ bool orientation_sensor::init(void) m_rotation_vector_sensor = sensor_loader::get_instance().get_sensor(ROTATION_VECTOR_SENSOR); if (!m_rotation_vector_sensor) { - _E("cannot load sensor[%s]", SENSOR_NAME); + _W("cannot load sensor[%s]", SENSOR_NAME); return false; } _I("%s is created!", SENSOR_NAME); diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 1af3da1..7c7c9b3 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -60,7 +60,7 @@ bool gyro_rv_sensor::init(void) m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); if (!m_accel_sensor || !m_gyro_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 6700230..61001c1 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -60,7 +60,7 @@ bool magnetic_rv_sensor::init(void) m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); if (!m_accel_sensor || !m_mag_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 0e9db8e..9fb42c7 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -63,7 +63,7 @@ bool rv_sensor::init(void) m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); if (!m_accel_sensor || !m_gyro_sensor|| !m_mag_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/tilt/tilt_sensor.cpp b/src/sensor/tilt/tilt_sensor.cpp index b60f337..6691978 100644 --- a/src/sensor/tilt/tilt_sensor.cpp +++ b/src/sensor/tilt/tilt_sensor.cpp @@ -61,35 +61,35 @@ tilt_sensor::tilt_sensor() register_supported_event(TILT_RAW_DATA_EVENT); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_VENDOR, m_vendor)) { - _E("[VENDOR] is empty\n"); + _W("[VENDOR] is empty\n"); throw ENXIO; } _I("m_vendor = %s", m_vendor.c_str()); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { - _E("[RAW_DATA_UNIT] is empty\n"); + _W("[RAW_DATA_UNIT] is empty\n"); throw ENXIO; } _I("m_raw_data_unit = %s", m_raw_data_unit.c_str()); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { - _E("[DEFAULT_SAMPLING_TIME] is empty\n"); + _W("[DEFAULT_SAMPLING_TIME] is empty\n"); throw ENXIO; } _I("m_default_sampling_time = %d", m_default_sampling_time); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_PITCH_ROTATION_COMPENSATION, &m_pitch_rotation_compensation)) { - _E("[PITCH_ROTATION_COMPENSATION] is empty\n"); + _W("[PITCH_ROTATION_COMPENSATION] is empty\n"); throw ENXIO; } _I("m_pitch_rotation_compensation = %d", m_pitch_rotation_compensation); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_ROLL_ROTATION_COMPENSATION, &m_roll_rotation_compensation)) { - _E("[ROLL_ROTATION_COMPENSATION] is empty\n"); + _W("[ROLL_ROTATION_COMPENSATION] is empty\n"); throw ENXIO; } @@ -109,7 +109,7 @@ bool tilt_sensor::init(void) m_fusion_sensor = sensor_loader::get_instance().get_sensor(FUSION_SENSOR); if (!m_accel_sensor || !m_fusion_sensor) { - _E("Failed to load sensors, accel: %#x, fusion: %#x", + _W("Failed to load sensors, accel: %#x, fusion: %#x", m_accel_sensor, m_fusion_sensor); return false; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index d978481..8d57968 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -336,6 +336,12 @@ bool command_worker::send_cmd_get_sensor_list_done(void) return false; } + /* + * TODO: get_sensor_list() command is processed on one-time connection in the current architecture. + * but it doesn't need to use one-time connection. + */ + m_socket.close(); + return true; } @@ -397,7 +403,7 @@ bool command_worker::cmd_hello(void *payload) m_module = (sensor_base *)sensor_loader::get_instance().get_sensor(cmd->sensor); if (!m_module) { - _E("Sensor type[%d] is not supported", cmd->sensor); + _W("Sensor type[%d] is not supported", cmd->sensor); if (!get_client_info_manager().has_sensor_record(m_client_id)) get_client_info_manager().remove_client_record(m_client_id); diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index f606d29..c25d07a 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -251,7 +251,7 @@ void sensor_loader::create_virtual_sensors(const char *name) } if (!instance->init()) { - _E("Failed to init %s", name); + _W("Failed to init %s", name); delete instance; return; } diff --git a/src/server/server.cpp b/src/server/server.cpp index 14e24fe..3e30174 100755 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -342,7 +342,8 @@ void server::run(void) void server::stop(void) { - _I("Sensord server stopped"); + if (!m_running) + return; m_running = false; @@ -351,6 +352,8 @@ void server::stop(void) g_main_loop_unref(m_mainloop); m_mainloop = NULL; } + + _I("Sensord server stopped"); } server& server::get_instance(void) diff --git a/src/server/worker_thread.cpp b/src/server/worker_thread.cpp index 9f88a24..9108016 100644 --- a/src/server/worker_thread.cpp +++ b/src/server/worker_thread.cpp @@ -41,7 +41,7 @@ bool worker_thread::transition_function(trans_func_index index) { if (m_trans_func[index] != NULL) { if (!m_trans_func[index](m_context)) { - _E("Transition[%d] function returning false", index); + _W("Transition[%d] function returning false", index); return false; } } diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 3b55107..46033ea 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -83,10 +83,8 @@ bool csocket::bind(const char *sock_path) int length; mode_t socket_mode; - if (!is_valid()) { - _E("%s's socket is invalid", get_client_name()); + if (!is_valid()) return false; - } if (!access(sock_path, F_OK)) { unlink(sock_path); @@ -116,10 +114,8 @@ bool csocket::bind(const char *sock_path) bool csocket::listen(const int max_connections) { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (::listen(m_sock_fd, max_connections) < 0) { _ERRNO(errno, _E, "Failed to listen for socket[%d]", m_sock_fd); @@ -309,10 +305,8 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t csocket::send(const void *buffer, size_t size) const { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return -EINVAL; - } if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); @@ -322,10 +316,8 @@ ssize_t csocket::send(const void *buffer, size_t size) const ssize_t csocket::recv(void* buffer, size_t size) const { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return -EINVAL; - } if (m_sock_type == SOCK_STREAM) return recv_for_stream(buffer, size); @@ -341,10 +333,8 @@ bool csocket::connect(const char *sock_path) int addr_len; bool prev_blocking_mode; - if (!is_valid()) { - _E("%s's socket is invalid", get_client_name()); + if (!is_valid()) return false; - } prev_blocking_mode = is_blocking_mode(); @@ -413,10 +403,8 @@ bool csocket::set_blocking_mode(bool blocking) { int flags; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } flags = fcntl(m_sock_fd, F_GETFL); @@ -444,10 +432,8 @@ bool csocket::set_sock_type(void) opt_len = sizeof(sock_type); - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (getsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &sock_type, &opt_len) < 0) { _ERRNO(errno, _E, "getsockopt(SOL_SOCKET, SO_TYPE) failed for %s, m_sock_fd: %d", @@ -469,10 +455,8 @@ bool csocket::set_connection_mode(void) tv.tv_sec = TIMEOUT; tv.tv_usec = 0; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { _ERRNO(errno, _E, "Set SO_RCVTIMEO failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); @@ -500,10 +484,8 @@ bool csocket::is_blocking_mode(void) { int flags; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } flags = fcntl(m_sock_fd, F_GETFL); @@ -529,7 +511,7 @@ bool csocket::close(void) { if (m_sock_fd >= 0) { if (::close(m_sock_fd) < 0) { - _ERRNO(errno, _E, "Failed to close socket[%d]", m_sock_fd); + _ERRNO(errno, _W, "Failed to close socket[%d]", m_sock_fd); return false; } m_sock_fd = -1; -- 2.7.4 From ecdee543f108afb9755df378fa188b5bc9db1818 Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Mon, 12 Sep 2016 21:54:55 +0900 Subject: [PATCH 10/16] sensord: create file for macros Change-Id: I44a8199875c059ac11e772afe1e6b47c5a0a8b65 Signed-off-by: minsoo kim --- src/shared/macro.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 src/shared/macro.h diff --git a/src/shared/macro.h b/src/shared/macro.h new file mode 100755 index 0000000..7a5f036 --- /dev/null +++ b/src/shared/macro.h @@ -0,0 +1,48 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once + +#include +#include +#include + +#define _cleanup_(x) __attribute__((cleanup(x))) + +static inline void __freep(void *p) +{ + free(*(void**) p); +} + +static inline void __closep(int *fd) +{ + if (*fd >= 0) + close(*fd); +} + +static inline void __fclosep(FILE **f) +{ + if (*f) + fclose(*f); +} + +#define _cleanup_free_ _cleanup_(__freep) +#define _cleanup_close_ _cleanup_(__closep) +#define _cleanup_fclose_ _cleanup_(__fclosep) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -- 2.7.4 From 66e67ca071a6b328503340bbef97cc018c191b9b Mon Sep 17 00:00:00 2001 From: "hs81.go" Date: Tue, 4 Oct 2016 10:46:41 +0900 Subject: [PATCH 11/16] sensord: remove an useless event suffix name Change-Id: Ia16741513429196bdbb1063e9a7dcdce62f8a41b Signed-off-by: hs81.go --- src/client/client_common.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index ec17a1f..a0a7345 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -42,9 +42,8 @@ const char* get_sensor_name(sensor_id_t id) const char* get_event_name(unsigned int event_type) { sensor_type_t type = (sensor_type_t) (event_type >> SENSOR_EVENT_SHIFT); - std::string name(util_sensor_type_t::get_string(type)); - return name.append("_EVENT").c_str(); + return util_sensor_type_t::get_string(type); } unsigned int get_calibration_event_type(unsigned int event_type) -- 2.7.4 From dc6c4ea719820bae22a51f1df5f9d217c29a4f51 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 18:21:34 +0900 Subject: [PATCH 12/16] sensord: add attributes and types to hal_types.h Change-Id: I0e9be365468a59ea948f6cdea1356fe46ae75979 Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index 6c30f47..6beb935 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -108,6 +108,9 @@ typedef enum { SENSOR_DEVICE_WORKOUT, SENSOR_DEVICE_CYCLE_MONITOR, SENSOR_DEVICE_STAIR_TRACKER, + SENSOR_DEVICE_PRESSURE_INDICATOR, + SENSOR_DEVICE_PRESSURE_ALERT, + SENSOR_DEVICE_HR_CALORIE, SENSOR_DEVICE_CONTEXT = 0x7000, SENSOR_DEVICE_MOTION, @@ -221,6 +224,66 @@ typedef struct { enum sensor_attribute { SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), + + SENSOR_ATTR_PEDOMETER_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1), + SENSOR_ATTR_PEDOMETER_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2), + SENSOR_ATTR_PEDOMETER_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3), + + SENSOR_ATTR_STRESS_MONITOR_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), + + SENSOR_ATTR_EXERCISE_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x1), + SENSOR_ATTR_EXERCISE_GPS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x2), + SENSOR_ATTR_EXERCISE_BATCH_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x3), + SENSOR_ATTR_EXERCISE_PSERVICE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x4), + + SENSOR_ATTR_CYCLE_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1), + SENSOR_ATTR_CYCLE_HOLDING_POSITION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2), + SENSOR_ATTR_CYCLE_VELOCITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3), + + SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1), + SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2), + + SENSOR_ATTR_RESTING_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x1), + SENSOR_ATTR_RESTING_HR_MAX_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x2), + SENSOR_ATTR_RESTING_HR_MIN_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x3), + SENSOR_ATTR_RESTING_HR_AVG_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x4), + SENSOR_ATTR_RESTING_HR_HOUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x5), + SENSOR_ATTR_RESTING_HR_MIN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x6), + SENSOR_ATTR_RESTING_HR_SEC = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x7), + SENSOR_ATTR_RESTING_HR_PROPERTY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x10), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x11), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x12), + SENSOR_ATTR_RESTING_HR_PROPERTY_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x13), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x14), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x15), + SENSOR_ATTR_RESTING_HR_PROPERTY_CONT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x16), + SENSOR_ATTR_RESTING_HR_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20), + SENSOR_ATTR_RESTING_HR_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21), + + SENSOR_ATTR_EXERCISE_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1), + SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2), + SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3), + SENSOR_ATTR_EXERCISE_HR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4), + + SENSOR_ATTR_PRESSURE_INDICATOR_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1), + SENSOR_ATTR_PRESSURE_INDICATOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2), + SENSOR_ATTR_PRESSURE_INDICATOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x3), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x4), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x5), + SENSOR_ATTR_PRESSURE_INDICATOR_CURRENT_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x6), + + SENSOR_ATTR_PRESSURE_ALERT_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x1), + SENSOR_ATTR_PRESSURE_ALERT_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x2), + + SENSOR_ATTR_HR_CALORIE_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x1), + SENSOR_ATTR_HR_CALORIE_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x2), + SENSOR_ATTR_HR_CALORIE_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x3), + SENSOR_ATTR_HR_CALORIE_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x4), + SENSOR_ATTR_HR_CALORIE_INST = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x10), + SENSOR_ATTR_HR_CALORIE_EXERCISE_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x11), + SENSOR_ATTR_HR_CALORIE_TARGET_CAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12), + SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13), + SENSOR_ATTR_HR_CALORIE_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20), }; enum sensor_activity { -- 2.7.4 From 7b82ada72d9325ba5192621a9366d915668793b8 Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Thu, 6 Oct 2016 16:09:30 +0900 Subject: [PATCH 13/16] sensord: add get wristup dbus interface SENSORD_BUS_NAME : "org.tizen.system.sensord" SENSORD_OBJECT_PATH : "/Org/Tizen/System/SensorD" SENSORD_INTERFACE_NAME : SENSORD_BUS_NAME WRISTUP_ALGO_METHOD : "wristup_algo" Change-Id: Ic7992b874b2456da2ede823de6bb7ffeb579f1a0 Signed-off-by: minsoo kim --- src/server/dbus_util.cpp | 12 ++++++++++++ src/server/dbus_util.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp index c29b61d..0aa0b90 100755 --- a/src/server/dbus_util.cpp +++ b/src/server/dbus_util.cpp @@ -23,6 +23,7 @@ static int wrist_up_total_cnt; static int wrist_up_lcdon_cnt; +static int wrist_up_algo; static GDBusNodeInfo *introspection_data = NULL; static guint owner_id; @@ -39,6 +40,9 @@ static const gchar introspection_xml[] = " " " " " " +" " +" " +" " " " ""; @@ -59,6 +63,9 @@ static void method_call_handler(GDBusConnection *conn, } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) { _D("wristup_total_cnt called, %d", wrist_up_total_cnt); ret = wrist_up_total_cnt; + } else if (g_strcmp0(method_name, "wristup_algo") == 0) { + _D("wristup_algo called, %d", wrist_up_algo); + ret = wrist_up_algo; } else { _D("No matched method call"); ret = DBUS_FAILED; @@ -141,6 +148,11 @@ void reset_total_count(void) wrist_up_total_cnt = 0; } +void set_wrist_up_algo(int mode) +{ + wrist_up_algo = mode; +} + void init_dbus(void) { #ifndef GLIB_VERSION_2_36 diff --git a/src/server/dbus_util.h b/src/server/dbus_util.h index ce4ad54..f729e3b 100644 --- a/src/server/dbus_util.h +++ b/src/server/dbus_util.h @@ -37,6 +37,7 @@ void reset_lcdon_count(void); int get_total_count(void); void increase_total_count(void); void reset_total_count(void); +void set_wrist_up_algo(int mode); void init_dbus(void); void fini_dbus(void); -- 2.7.4 From 0145bede6b0f34857422de4297038b905f64ecea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 28 Oct 2016 00:26:34 +0900 Subject: [PATCH 14/16] sensord: change socket type from stream to seqpacket Change-Id: I3ecc7f26e9917b29dfeaf4a9164012bf3df2c8f2 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 15 +++++++++++++-- src/shared/csocket.cpp | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index dc40271..fd11d4f 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -240,13 +240,13 @@ ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, s len = m_event_socket.recv(buffer, buffer_len); if (!len) { - _I("%s failed to read after poll!", get_client_name()); + _E("%s failed to read after poll!", get_client_name()); return -1; } } if (len < 0) { - _I("%s failed to recv event from event socket", get_client_name()); + _E("%s failed to recv event from event socket", get_client_name()); return -1; } @@ -277,6 +277,10 @@ void sensor_event_listener::listen_events(void) sensor_event_t *sensor_event = reinterpret_cast(buffer); data_len = sensor_event->data_length; + + if (data_len == 0) + continue; + buffer_data = malloc(data_len); len = sensor_event_poll(buffer_data, data_len, event); @@ -291,6 +295,13 @@ void sensor_event_listener::listen_events(void) handle_events((void *)buffer); } while (true); + if (m_poller) { + delete m_poller; + m_poller = NULL; + } + + close_event_channel(); + { /* the scope for the lock */ lock l(m_thread_mutex); m_thread_state = THREAD_STATE_TERMINATE; diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 46033ea..25a7076 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -25,7 +25,7 @@ csocket::csocket() : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { @@ -34,7 +34,7 @@ csocket::csocket() csocket::csocket(int sock_fd) : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { @@ -45,7 +45,7 @@ csocket::csocket(int sock_fd) csocket::csocket(const csocket &sock) : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { -- 2.7.4 From d75157fd9acfe3000acdf6c036c2e2b559a3d14c Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Mon, 7 Nov 2016 20:04:12 +0900 Subject: [PATCH 15/16] sensord: set socket_type when connection of client is accepted Currently, stream socket is used for command and sequence packet socket is used for sensor event. but when server accepts any connection of client server creates socket object with default socket type. so client socket which is accepted by server must set proper socket type, not default. Change-Id: I789ff247a37a8048e9e4657997ac55a603b484e9 Signed-off-by: minsoo kim --- src/shared/csocket.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 25a7076..c500def 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -170,6 +170,7 @@ bool csocket::accept(csocket& client_socket) const do { client_socket.m_sock_fd = ::accept(m_sock_fd, (sockaddr *)&m_addr, (socklen_t *)&addr_length); + client_socket.set_sock_type(); if (!client_socket.is_valid()) err = errno; } while (err == EINTR); -- 2.7.4 From a3178338a7857eb929280ef05f526c215cd482b2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 17 Nov 2016 00:04:29 +0900 Subject: [PATCH 16/16] sensord: add select before sending the event because check client fd is writable or not, select() is added. Change-Id: I3189b314ec574fa8201dc79e33b91ad2e7f82deb Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index c500def..4a97a3c 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -306,9 +306,35 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t csocket::send(const void *buffer, size_t size) const { + const int TIMEOUT = 5; + fd_set write_fds; + struct timeval tv; + if (!is_valid()) return -EINVAL; + FD_ZERO(&write_fds); + FD_SET(m_sock_fd, &write_fds); + tv.tv_sec = TIMEOUT; + tv.tv_usec = 0; + + int ret; + + ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv); + + if (ret == -1) { + _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); + return false; + } else if (!ret) { + _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); + return false; + } + + if (!FD_ISSET(m_sock_fd, &write_fds)) { + _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); + return false; + } + if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); -- 2.7.4