From cb024eefb24bdf45bf6d0598898abc4a5e9ac8c2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 29 Mar 2016 21:57:53 +0900 Subject: [PATCH 01/16] sensord: fix the bug that gravity synthesize has to skip the all event except of accelerometer event Change-Id: I39c074b12584469c8ca5030dcbe28ee8223eaced Signed-off-by: kibak.yoon --- src/sensor/gravity/gravity_sensor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 49147a6..2c39ebf 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -194,6 +194,9 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event) void gravity_sensor::synthesize_lowpass(const sensor_event_t& event) { + if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) + return; + sensor_event_t *gravity_event; float x, y, z, norm, alpha, tau, err; -- 2.7.4 From b262076959983707bb2f185a589e6d29a1cbe841 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 29 Mar 2016 23:03:01 +0900 Subject: [PATCH 02/16] sensord: fix the bug about checking 0 although sensor_id can be 0 Change-Id: I6bf57b579a3aafd53d203ae9283ffd1da5955975 Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index ae4685f..b10071f 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -220,7 +220,7 @@ bool command_worker::stopped(void *ctx) inst->m_module->stop(); } - if (inst->m_sensor_id) { + if (inst->m_sensor_id > UNKNOWN_SENSOR) { if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) { _I("Removing sensor[0x%llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id); -- 2.7.4 From 5068de167b902c129448534c1afc9bc711ec6079 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 30 Mar 2016 13:37:17 +0900 Subject: [PATCH 03/16] sensord: fix the bug that it releases static variable Change-Id: Ic27ab5bcb886fe82c36f75e3970929485c0f3119 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 9066d95..8182905 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -104,6 +104,7 @@ bool sensor_loader::load_sensor_devices(const string &path, void* &handle) dlerror(); + /* TODO: The out-param of the create function should be const */ create_t create_devices = (create_t) dlsym(_handle, "create"); if (!create_devices) { _E("Failed to find symbols in %s", path.c_str()); @@ -128,7 +129,6 @@ bool sensor_loader::load_sensor_devices(const string &path, void* &handle) handle = _handle; - delete _devices; return true; } -- 2.7.4 From 45507e3490f78537d3fc6db7709f4031d01437a7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 30 Mar 2016 13:35:03 +0900 Subject: [PATCH 04/16] sensord: raise SIGKILL when sensord receive SIGTERM Change-Id: Idc6bc5b64441cc088c0d688d8b0f7980529522f9 Signed-off-by: kibak.yoon --- src/server/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/main.cpp b/src/server/main.cpp index 6e46c25..504beb7 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -32,7 +32,9 @@ static void sig_term_handler(int signo, siginfo_t *info, void *data) get_proc_name(info->si_pid, proc_name); _E("Received SIGTERM(%d) from %s(%d)\n", signo, proc_name, info->si_pid); - exit(EXIT_SUCCESS); + + /* TODO: Refactoring */ + raise(SIGKILL); } static void signal_init(void) -- 2.7.4 From 3767ffdc4b6b4d3d07c43f8940417573e704df85 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 18:26:50 +0900 Subject: [PATCH 05/16] sensord: redefine _ERRNO macro to use easily * in previous code, if additional message is needed for log, the another log has to be added. so redefine the macro for using it easily. Change-Id: Ia05199f45acb1d23bf9142ab43e70898101b1a7a Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 2 +- src/shared/csocket.cpp | 66 +++++++++++++++++--------------------------- src/shared/poller.cpp | 4 +-- src/shared/sensor_log.h | 4 +-- 4 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 8182905..785fab2 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -239,7 +239,7 @@ sensor_base* sensor_loader::create_sensor(void) _E("Failed to create sensor, exception: %s", e.what()); return NULL; } catch (int err) { - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to create sensor"); return NULL; } diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 9c33c5e..23bcdd4 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -69,8 +69,7 @@ bool csocket::create(int sock_type) m_sock_fd = socket(AF_UNIX, sock_type, 0); if (!is_valid()) { - _E("Failed to create socket for %s", get_client_name()); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to create socket for %s", get_client_name()); return false; } @@ -100,16 +99,14 @@ bool csocket::bind (const char *sock_path) length = strlen(m_addr.sun_path) + sizeof(m_addr.sun_family); if (::bind(m_sock_fd, (struct sockaddr *)&m_addr, length) < 0) { - _E("Binding failed for socket(%d)", m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to bind for socket[%d]", m_sock_fd); close(); return false; } socket_mode = ( S_IRWXU | S_IRWXG | S_IRWXO ); if (chmod(sock_path, socket_mode) < 0) { - _E("chmod failed for socket(%d)", m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to chmod for socket[%d]", m_sock_fd); close(); return false; } @@ -125,8 +122,7 @@ bool csocket::listen(const int max_connections) } if (::listen(m_sock_fd, max_connections) < 0) { - _E("Listening failed for socket(%d)", m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to listen for socket[%d]", m_sock_fd); close(); return false; } @@ -146,8 +142,7 @@ bool csocket::accept(csocket& client_socket) const } while (err == EINTR); if (!client_socket.is_valid()) { - _E("Accept failed for socket(%d)", m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to accept for socket[%d]", m_sock_fd); return false; } @@ -164,9 +159,8 @@ ssize_t csocket::send_for_seqpacket(const void *buffer, size_t size) const } while (err == EINTR); if (err) { - _E("send(%d, 0x%x, %d, 0x%x) = %d", + _ERRNO(errno, _E, "Failed to send(%d, 0x%x, %d, 0x%x) = %d", m_sock_fd, buffer, size, m_send_flags, len); - _ERRNO(errno); } return err == 0 ? len : -err; @@ -190,13 +184,15 @@ ssize_t csocket::recv_for_seqpacket(void* buffer, size_t size) const } } while (err == EINTR); - if ((err == EAGAIN) || (err == EWOULDBLOCK)) + if ((err == EAGAIN) || (err == EWOULDBLOCK)) { + _ERRNO(err, _D, "Failed to recv(%d, 0x%x, %d, 0x%x) = %d", + m_socket_fd, buffer, size, m_recv_flags, len); return 0; + } if (err) { - _E("recv(%d, 0x%x, %d, 0x%x) = %d", + _ERRNO(err, _E, "Failed to recv(%d, 0x%x, %d, 0x%x) = %d", m_sock_fd, buffer, size, m_recv_flags, len); - _ERRNO(errno); } return err == 0 ? len : -err; @@ -216,10 +212,9 @@ ssize_t csocket::send_for_stream(const void *buffer, size_t size) const total_sent_size += len; err = 0; } else { - _E("send(%d, 0x%p + %d, %d - %d) = %d for %s", + _ERRNO(errno, _E, "Failed to send(%d, 0x%p + %d, %d - %d) = %d for %s", m_sock_fd, buffer, total_sent_size, size, total_sent_size, len, get_client_name()); - _ERRNO(errno); if (errno != EINTR) { err = errno; @@ -248,10 +243,9 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const err = 1; break; } else { - _E("recv(%d, 0x%p + %d, %d - %d) = %d for %s", + _ERRNO(errno, _E, "Failed to recv(%d, 0x%p + %d, %d - %d) = %d for %s", m_sock_fd, buffer, total_recv_size, size, total_recv_size, len, get_client_name()); - _ERRNO(errno); if (errno != EINTR) { err = errno; @@ -314,8 +308,8 @@ bool csocket::connect(const char *sock_path) addr_len = strlen(m_addr.sun_path) + sizeof(m_addr.sun_family); if (::connect(m_sock_fd,(sockaddr *) &m_addr, addr_len) < 0) { - _E("connect error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to connect sock_fd: %d for %s", + m_sock_fd, get_client_name()); return false; } @@ -329,18 +323,17 @@ bool csocket::connect(const char *sock_path) ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv); if (ret == -1) { - _E("select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); - _ERRNO(errno); + _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); close(); return false; } else if (!ret) { - _E("select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); + _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); close(); return false; } if (!FD_ISSET(m_sock_fd, &write_fds)) { - _E("select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); + _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); close(); return false; } @@ -349,14 +342,13 @@ bool csocket::connect(const char *sock_path) socklen_t len = sizeof(so_error); if (getsockopt(m_sock_fd, SOL_SOCKET, SO_ERROR, &so_error, &len) == -1) { - _E("getsockopt failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "getsockopt failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); close(); return false; } if (so_error) { - _E("SO_ERROR occurred for %s, m_sock_fd : %d, so_error : %d", + _ERRNO(errno, _E, "SO_ERROR occurred for %s, m_sock_fd : %d, so_error : %d", get_client_name(), m_sock_fd, so_error); close(); return false; @@ -380,8 +372,7 @@ bool csocket::set_blocking_mode(bool blocking) flags = fcntl(m_sock_fd, F_GETFL); if (flags == -1) { - _E("fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); return false; } @@ -390,8 +381,7 @@ bool csocket::set_blocking_mode(bool blocking) flags = fcntl(m_sock_fd, F_SETFL, flags); if (flags == -1) { - _E("fcntl(F_SETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "fcntl(F_SETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); return false; } @@ -412,9 +402,8 @@ bool csocket::set_sock_type(void) } if (getsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &sock_type, &opt_len) < 0) { - _E("getsockopt(SOL_SOCKET, SO_TYPE) failed for %s, m_sock_fd: %d", + _ERRNO(errno, _E, "getsockopt(SOL_SOCKET, SO_TYPE) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); - _ERRNO(errno); return false; } @@ -438,8 +427,7 @@ bool csocket::set_connection_mode(void) } if(setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { - _E("Set SO_RCVTIMEO failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Set SO_RCVTIMEO failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); close(); return false; } @@ -472,8 +460,7 @@ bool csocket::is_blocking_mode(void) flags = fcntl(m_sock_fd, F_GETFL); if (flags == -1) { - _E("fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd); return false; } @@ -495,8 +482,7 @@ bool csocket::close(void) { if (m_sock_fd >= 0) { if (::close(m_sock_fd) < 0) { - _E("Socket(%d) close failed", m_sock_fd); - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to close socket[%d]", m_sock_fd); return false; } m_sock_fd = -1; diff --git a/src/shared/poller.cpp b/src/shared/poller.cpp index ae01c8b..45e5936 100644 --- a/src/shared/poller.cpp +++ b/src/shared/poller.cpp @@ -55,7 +55,7 @@ bool poller::add_fd(int fd) event.events = EPOLLIN | EPOLLERR | EPOLLHUP; if (epoll_ctl(m_epfd, EPOLL_CTL_ADD, fd, &event)) { - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to add fd[%d]", fd); return false; } @@ -73,7 +73,7 @@ bool poller::fill_event_queue(void) if (errno == EINTR) return true; - _ERRNO(errno); + _ERRNO(errno, _E, "Failed to fill event queue"); return false; } diff --git a/src/shared/sensor_log.h b/src/shared/sensor_log.h index d4d7a06..bcbe921 100644 --- a/src/shared/sensor_log.h +++ b/src/shared/sensor_log.h @@ -49,14 +49,14 @@ #define _I INFO #define _D DBG -#define _ERRNO(errno) do { \ +#define _ERRNO(errno, tag, fmt, arg...) do { \ char buf[1024]; \ char *error = strerror_r(errno, buf, 1024); \ if (!error) { \ _E("Failed to strerror_r()"); \ break; \ } \ - _E("%s : [errno: %d]", error, errno); \ + tag(fmt" (%s[%d])", ##arg, error, errno); \ } while (0) #if defined(_DEBUG) -- 2.7.4 From cb1cc05d6587ed55e64bd7ab73dd100f5e87cb59 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 19:14:42 +0900 Subject: [PATCH 06/16] sensord: remove the changing g_main_context API * this feature is not used anymore Change-Id: I9073d2ee3908ca5d332b7659801e7f0f2b00d825 Signed-off-by: kibak.yoon --- src/client/client.cpp | 13 ------------- src/client/reg_event_info.h | 4 +--- src/client/sensor_client_info.cpp | 17 ----------------- src/client/sensor_client_info.h | 1 - src/client/sensor_event_listener.cpp | 10 +--------- src/client/sensor_event_listener.h | 1 - src/client/sensor_handle_info.cpp | 14 -------------- src/client/sensor_handle_info.h | 2 -- src/client/sensor_internal.h | 11 ----------- 9 files changed, 2 insertions(+), 71 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 302f6e9..ac357bf 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -976,19 +976,6 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t return change_event_batch(handle, event_type, prev_interval, max_batch_latency); } -API bool sensord_change_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext) -{ - AUTOLOCK(lock); - - if (!sensor_client_info::get_instance().set_event_maincontext(handle, event_type, maincontext)) { - _E("Failed to get event info with handle = %d, event_type = 0x%x, maincontext = 0x%x", handle, event_type, maincontext); - return false; - } - - _I("handle = %d, event_type = 0x%x, maincontext = 0x%x", handle, event_type, maincontext); - return true; -} - API bool sensord_set_option(int handle, int option) { sensor_id_t sensor_id; diff --git a/src/client/reg_event_info.h b/src/client/reg_event_info.h index fa8994c..bf20efc 100644 --- a/src/client/reg_event_info.h +++ b/src/client/reg_event_info.h @@ -20,7 +20,6 @@ #ifndef _REG_EVENT_INFO_H_ #define _REG_EVENT_INFO_H_ -#include #include typedef enum { @@ -41,13 +40,12 @@ public: void *m_user_data; unsigned long long m_previous_event_time; bool m_fired; - GMainContext *m_maincontext; reg_event_info() : m_id(0), m_handle(-1), type(0), m_interval(POLL_1HZ_MS), m_latency(0), m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL), - m_previous_event_time(0), m_fired(false), m_maincontext(NULL) {} + m_previous_event_time(0), m_fired(false) {} ~reg_event_info() {} }; diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index ded2acc..d6133c3 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -249,23 +249,6 @@ bool sensor_client_info::set_event_batch(int handle, unsigned int event_type, un return true; } -bool sensor_client_info::set_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext) -{ - AUTOLOCK(m_handle_info_lock); - - 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()); - return false; - } - - if (!it_handle->second.change_reg_event_maincontext(event_type, maincontext)) - return false; - - return true; -} - bool sensor_client_info::set_accuracy(int handle, int accuracy) { AUTOLOCK(m_handle_info_lock); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 47a4adf..33524f1 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -76,7 +76,6 @@ public: bool set_sensor_state(int handle, int sensor_state); bool set_sensor_option(int handle, int sensor_option); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); - bool set_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext); bool set_accuracy(int handle, int accuracy); bool set_bad_accuracy(int handle, int bad_accuracy); bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data); diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index c71b9cd..5964ab6 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -255,7 +255,6 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso callback_info->timestamp = 0; callback_info->accuracy = -1; callback_info->accuracy_user_data = NULL; - callback_info->maincontext = event_info->m_maincontext; callback_info->sensor_data = sensor_data; callback_info->buffer = buffer; @@ -264,14 +263,7 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso void sensor_event_listener::post_callback_to_main_loop(client_callback_info* cb_info) { - if (cb_info->maincontext) { - GSource *_source = g_idle_source_new(); - - g_source_attach(_source, cb_info->maincontext); - g_source_set_callback(_source, callback_dispatcher, cb_info, NULL); - } else { - g_idle_add_full(G_PRIORITY_DEFAULT, callback_dispatcher, cb_info, NULL); - } + g_idle_add_full(G_PRIORITY_DEFAULT, callback_dispatcher, cb_info, NULL); } bool sensor_event_listener::is_valid_callback(client_callback_info *cb_info) diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index fa7b77e..54f5a40 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -59,7 +59,6 @@ typedef struct { unsigned long long timestamp; int accuracy; void *accuracy_user_data; - GMainContext *maincontext; void *buffer; } client_callback_info; diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 796107f..10cd629 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -131,20 +131,6 @@ bool sensor_handle_info::change_reg_event_batch(unsigned int event_type, unsigne return true; } -bool sensor_handle_info::change_reg_event_maincontext(unsigned int event_type, GMainContext *maincontext) -{ - auto it_event = m_reg_event_infos.find(event_type); - - if (it_event == m_reg_event_infos.end()) { - _E("Event %s[0x%x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); - return false; - } - - it_event->second.m_maincontext = maincontext; - - return true; -} - void sensor_handle_info::get_batch(unsigned int &interval, unsigned int &latency) { if (m_reg_event_infos.empty()) { diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index fa0fb4c..d551952 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -25,7 +25,6 @@ #include #include #include -#include typedef std::unordered_map event_info_map; @@ -47,7 +46,6 @@ public: bool delete_reg_event_info(unsigned int event_type); bool change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency); - bool change_reg_event_maincontext(unsigned int event_type, GMainContext *maincontext); reg_event_info* get_reg_event_info(const unsigned int event_type); void get_reg_event_types(event_type_vector &event_types); diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index e5cd958..7a0a3e1 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -26,7 +26,6 @@ #include "stdbool.h" #include -#include /*header for common sensor type*/ #include @@ -318,16 +317,6 @@ bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency); /** - * @brief Change the maincontext of a specifed event type in a connected sensor. - * - * @param[in] handle a handle represensting a connected sensor. - * @param[in] event_type an event type to change maincontext. - * @param[in] maincontext an event is passed to default GMainLoop as default. And it can be changed to specific GMainContext. - * @return true on success, otherwise false. - */ -bool sensord_change_event_maincontext(int handle, unsigned int event_type, GMainContext *maincontext); - -/** * @brief Change the option of a connected sensor. * * @param[in] handle a handle represensting a connected sensor. -- 2.7.4 From e349cf10ca9c831971d706e8426fde12a8986f2e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Mar 2016 10:01:59 +0900 Subject: [PATCH 07/16] sensord: fix the bug about calling get_client_name Change-Id: I671c013bad4215ab41a0ec47bb88ad6fa2621077 Signed-off-by: kibak.yoon --- src/client/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index ac357bf..4a8854f 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1042,7 +1042,7 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) if (!cmd_channel->cmd_set_attribute_int(attribute, value)) { _E("Sending cmd_set_attribute_int(%d, %d) failed for %s", - client_id, value, get_client_name); + client_id, value, get_client_name()); return -EPERM; } @@ -1079,7 +1079,7 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { _E("Sending cmd_set_attribute_str(%d, %d, 0x%x) failed for %s", - client_id, value_len, value, get_client_name); + client_id, value_len, value, get_client_name()); return -EPERM; } -- 2.7.4 From 79420e8906489408b32d26010d3b46fc7ab727d4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Mar 2016 13:10:21 +0900 Subject: [PATCH 08/16] sensord: change the default return value to true Change-Id: Ie943cef2f4375a0cdb2f5909c671218a620b98db Signed-off-by: kibak.yoon --- src/server/sensor_base.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index f339533..0936815 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -87,7 +87,7 @@ int sensor_base::get_data(sensor_data_t **data, int *length) bool sensor_base::flush(void) { - return false; + return true; } int sensor_base::set_attribute(int32_t cmd, int32_t value) @@ -289,22 +289,22 @@ bool sensor_base::push(sensor_event_t *event) bool sensor_base::set_interval(unsigned long interval) { - return false; + return true; } bool sensor_base::set_batch_latency(unsigned long latency) { - return false; + return true; } bool sensor_base::on_start() { - return false; + return true; } bool sensor_base::on_stop() { - return false; + return true; } unsigned long long sensor_base::get_timestamp(void) -- 2.7.4 From 2b64984c0641d7a709edcb08ff15bb763712e377 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Mar 2016 21:04:49 +0900 Subject: [PATCH 09/16] sensord: remove the unnecessary debug log - a client can have serveral handles(it is same as listener) and each of handles can register each other sensor event. so there are so many cases that some event is not registered to handle. - so it is unnecessary to show dlog. Change-Id: Ib97a269e9368964baef84505895bd05ace2fde73 Signed-off-by: kibak.yoon --- src/client/sensor_handle_info.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 10cd629..f24b74a 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -47,10 +47,8 @@ reg_event_info* sensor_handle_info::get_reg_event_info(unsigned int event_type) { auto it_event = m_reg_event_infos.find(event_type); - if (it_event == m_reg_event_infos.end()) { - _D("Event %s[0x%x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); + if (it_event == m_reg_event_infos.end()) return NULL; - } return &(it_event->second); } -- 2.7.4 From cadbe5311dc9bfc84c8de2488cd5c9dfd42c2d1f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 28 Mar 2016 22:40:33 +0900 Subject: [PATCH 10/16] sensor_base: modify get_timestamp() to protected functions Change-Id: Ideaf97be8e3b9440b4cb4446b6fb0db843e38fc5 Signed-off-by: Mu-Woong Lee --- src/server/sensor_base.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 95ea6c5..b69ca8e 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -77,6 +77,9 @@ public: protected: void set_permission(int permission); + static unsigned long long get_timestamp(void); + static unsigned long long get_timestamp(timeval *t); + private: sensor_id_t m_id; int m_permission; @@ -93,9 +96,6 @@ private: virtual bool on_start(void); virtual bool on_stop(void); - - static unsigned long long get_timestamp(void); - static unsigned long long get_timestamp(timeval *t); }; #endif /* _SENSOR_BASE_H_ */ -- 2.7.4 From 10128a9b5761c650df006b398d21e7a2778338b5 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 30 Mar 2016 22:16:07 +0900 Subject: [PATCH 11/16] sensord: init epoll_event variable * if it does not set the value and some problem is happened at first, later, other developers can make a mistake. so for preventing it, initialize this variable's members. Change-Id: I1c2fe47d816c50a524178d5a657b65cec929d4d2 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 5964ab6..99cf76e 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -338,6 +338,8 @@ void sensor_event_listener::listen_events(void) struct epoll_event event; ssize_t len = -1; + event.events = EPOLLIN | EPOLLPRI; + do { void *buffer_data; int data_len; -- 2.7.4 From dd29f31a34c4c08c358dc0fa4950332482a1a710 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:24:52 +0900 Subject: [PATCH 12/16] sensord: fix memory leak when legacy cb is used * when legacy cb is used, allocation of event is useless Change-Id: I1698884940a6744f78963a28746e5b9e4313ec00 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 99cf76e..d344554 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -110,14 +110,14 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle if (!event_info) return NULL; - sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - retvm_if(!cal_data, NULL, "Failed to allocate memory"); - if (event_info->m_cb_type == SENSOR_LEGACY_CB) { cal_event_data.event_data = (void *)&(accuracy); cal_event_data.event_data_size = sizeof(accuracy); cal_sensor_data = &cal_event_data; } else { + sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!cal_data, NULL, "Failed to allocate memory"); + cal_data->accuracy = accuracy; cal_data->timestamp = time; cal_data->values[0] = accuracy; -- 2.7.4 From d3d8e40d87414f9fa8dacd66b7e60bea41e26825 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:26:41 +0900 Subject: [PATCH 13/16] sensord: remove useless buffer parameter * buffer in callback_info is not used anymore, remove it Change-Id: I5a52e869e48972dcde7593a1cfd4333b380cb728 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 9 ++++----- src/client/sensor_event_listener.h | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index d344554..273d0d1 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -125,7 +125,7 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle cal_sensor_data = cal_data; } - cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data, cal_sensor_data); + cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data); m_client_info.set_bad_accuracy(handle_info.m_handle, true); @@ -202,9 +202,9 @@ void sensor_event_listener::handle_events(void* event) client_callback_infos.push_back(cal_callback_info); if (event_info->m_cb_type == SENSOR_LEGACY_CB) - callback_info = get_callback_info(sensor_id, event_info, &event_data, event); + callback_info = get_callback_info(sensor_id, event_info, &event_data); else - callback_info = get_callback_info(sensor_id, event_info, sensor_data, event); + callback_info = get_callback_info(sensor_id, event_info, sensor_data); if (!callback_info) { _E("Failed to get callback_info"); @@ -237,7 +237,7 @@ void sensor_event_listener::handle_events(void* event) } } -client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void* sensor_data, void *buffer) +client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void* sensor_data) { client_callback_info* callback_info; @@ -256,7 +256,6 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso callback_info->accuracy = -1; callback_info->accuracy_user_data = NULL; callback_info->sensor_data = sensor_data; - callback_info->buffer = buffer; return callback_info; } diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 54f5a40..47ff126 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -59,7 +59,6 @@ typedef struct { unsigned long long timestamp; int accuracy; void *accuracy_user_data; - void *buffer; } client_callback_info; typedef void (*hup_observer_t)(void); @@ -112,7 +111,7 @@ private: 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* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void *sensor_data, void *buffer); + client_callback_info* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void *sensor_data); unsigned long long renew_event_id(void); -- 2.7.4 From bf904c562107946fcbc00dd3f88916d3422591e9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:35:07 +0900 Subject: [PATCH 14/16] sensord: fix memory leak in virtual sensors * event memory has to be not released when error happens Change-Id: I53fe2d366069b773b6d9b05c052fa9ac56f85e0d Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 4 +++- src/sensor/gravity/gravity_sensor.cpp | 3 +++ src/sensor/linear_accel/linear_accel_sensor.cpp | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 3afd961..0c4888a 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -181,8 +181,10 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event) remains = get_data(&rotation_data, &data_length); - if (remains < 0) + if (remains < 0) { + free(rotation_event); return; + } rotation_event->sensor_id = get_id(); rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT; diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 2c39ebf..49ee0fe 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -171,6 +171,7 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } @@ -226,6 +227,7 @@ void gravity_sensor::synthesize_lowpass(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } @@ -275,6 +277,7 @@ void gravity_sensor::synthesize_fusion(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 33d1548..eb50de9 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -141,8 +141,10 @@ void linear_accel_sensor::synthesize(const sensor_event_t& event) remains = get_data(&linear_accel_data, &data_length); - if (remains < 0) + if (remains < 0) { + free(linear_accel_event); return; + } linear_accel_event->sensor_id = get_id(); linear_accel_event->event_type = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME; -- 2.7.4 From 920984bc9621284217aea86728a1094c6a0a60d6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:41:24 +0900 Subject: [PATCH 15/16] sensord: close handles in sensor_loader destructor Change-Id: Ie24606b850a13708956808b36210a86983d62ae3 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 9 +++++++++ src/server/sensor_loader.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 785fab2..d525d98 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -50,6 +50,14 @@ sensor_loader::sensor_loader() { } +sensor_loader::~sensor_loader() +{ + for (auto it = m_handles.begin(); it != m_handles.end(); ++it) + dlclose(*it); + + m_handles.clear(); +} + sensor_loader& sensor_loader::get_instance() { static sensor_loader inst; @@ -79,6 +87,7 @@ bool sensor_loader::load(void) [&](const string &path) { void *handle; load_sensor_devices(path, handle); + m_handles.push_back(handle); } ); diff --git a/src/server/sensor_loader.h b/src/server/sensor_loader.h index 763ea9a..b303301 100644 --- a/src/server/sensor_loader.h +++ b/src/server/sensor_loader.h @@ -41,6 +41,7 @@ typedef std::map sensor_device_map_t; class sensor_loader { private: sensor_loader(); + virtual ~sensor_loader(); bool load_sensor_devices(const std::string &path, void* &handle); @@ -54,6 +55,7 @@ private: sensor_map_t m_sensors; sensor_device_map_t m_devices; + std::vector m_handles; public: static sensor_loader& get_instance(); bool load(void); -- 2.7.4 From ff14217dd4535fb3045fbf5c3d506af32faedfd9 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 21 Mar 2016 12:01:49 +0900 Subject: [PATCH 16/16] sensor_base: add data length parameter to on_event() Change-Id: I7b29eb919534e741816ceeb06fd5ddb72919707e Signed-off-by: Mu-Woong Lee --- src/server/physical_sensor.cpp | 2 +- src/server/physical_sensor.h | 2 +- src/server/sensor_event_poller.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 7964065..f7135ee 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -77,7 +77,7 @@ int physical_sensor::get_poll_fd() return m_sensor_device->get_poll_fd(); } -bool physical_sensor::on_event(const sensor_data_t *data, int remains) +bool physical_sensor::on_event(const sensor_data_t *data, int data_len, int remains) { return true; } diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index 393e4d7..d8628c1 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -40,7 +40,7 @@ public: int get_poll_fd(); - virtual bool on_event(const sensor_data_t *data, int remains); + virtual bool on_event(const sensor_data_t *data, int data_len, int remains); virtual bool read_fd(std::vector &ids); virtual int get_data(sensor_data_t **data, int *length); diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index a7ec9a4..f4a68c4 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -137,7 +137,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids break; } - if (!sensor->on_event(data, remains)) { + if (!sensor->on_event(data, data_length, remains)) { free(event); free(data); break; -- 2.7.4