From 0a9009fc587c0c9a82ddfac101971b15f5516f40 Mon Sep 17 00:00:00 2001 From: Avichal Date: Thu, 21 Feb 2019 15:19:22 +0530 Subject: [PATCH 01/16] Rectifyng this poniter deletion from member function ASAN TFD289 Change-Id: I8261058c690244e6a21df616c67dae5dda1117ff --- src/server/sensor_handler.cpp | 6 ++++-- src/shared/channel.cpp | 7 ++++++- src/shared/message.cpp | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index fcfef69..b9cdfca 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -83,8 +83,10 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len) for (auto it = m_observers.begin(); it != m_observers.end(); ++it) (*it)->update(uri, msg); - if (msg->ref_count() == 0) - msg->unref(); + if (msg->ref_count() == 0) { + delete msg; + msg = NULL; + } set_cache(data, len); diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index 446c881..639e9c1 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -49,8 +49,13 @@ public: if (!m_ch->send_sync(m_msg)) return false; - if (m_msg) + if (m_msg) { m_msg->unref(); + if(m_msg->ref_count() <= 0) { + delete m_msg; + m_msg = NULL; + } + } return false; } diff --git a/src/shared/message.cpp b/src/shared/message.cpp index 799e64f..f53dd5e 100755 --- a/src/shared/message.cpp +++ b/src/shared/message.cpp @@ -87,7 +87,7 @@ message::message(int error) message::~message() { - if (m_msg && ref_cnt == 0) { + if (m_msg) { delete [] m_msg; m_msg = NULL; } @@ -146,12 +146,12 @@ void message::unref(void) { ref_cnt--; - if (ref_cnt > 0 || !m_msg) + /*if (ref_cnt > 0 || !m_msg) return; delete [] m_msg; m_msg = NULL; - delete this; + delete this;*/ } int message::ref_count(void) -- 2.7.4 From ff7790b316b8c8dc4f0f56bb4d9aefd7796d7e25 Mon Sep 17 00:00:00 2001 From: Avichal Date: Tue, 9 Apr 2019 17:13:16 +0530 Subject: [PATCH 02/16] ASAN issue 1. heap-use-after-free in enlightenment (TFDF-279,280) 2. heap-use-after-free in amd(TFDF-281,282) THis issue reported on termination of sensord Change-Id: I03e1d592e9caa93636d31d712e581c48db2d2363 Signed-off-by: Avichal --- src/shared/channel_event_handler.cpp | 2 -- src/shared/event_loop.cpp | 13 ++++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/shared/channel_event_handler.cpp b/src/shared/channel_event_handler.cpp index cc8a2bb..8a6b64b 100644 --- a/src/shared/channel_event_handler.cpp +++ b/src/shared/channel_event_handler.cpp @@ -46,13 +46,11 @@ bool channel_event_handler::handle(int fd, event_condition condition) if (condition & (EVENT_HUP)) { m_ch->disconnect(); - m_ch = NULL; return false; } if (!m_ch->read_sync(msg, false)) { m_ch->disconnect(); - m_ch = NULL; return false; } diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp index 713cd90..881d39d 100644 --- a/src/shared/event_loop.cpp +++ b/src/shared/event_loop.cpp @@ -38,6 +38,9 @@ static gboolean g_io_handler(GIOChannel *ch, GIOCondition condition, gpointer da uint64_t id; int fd; bool term; + bool ret; + event_loop *loop; + event_handler *handler; unsigned int cond; cond = (unsigned int)condition; @@ -46,17 +49,21 @@ static gboolean g_io_handler(GIOChannel *ch, GIOCondition condition, gpointer da cond &= ~(G_IO_IN | G_IO_OUT); handler_info *info = (handler_info *)data; + loop = info->loop; + handler = info->handler; + retvm_if(!loop || !handler, FALSE, "Invalid event info"); + id = info->id; fd = info->fd; - term = info->loop->is_terminator(fd); + term = loop->is_terminator(fd); if (cond & G_IO_NVAL) return FALSE; - bool ret = info->handler->handle(fd, (event_condition)cond); + ret = handler->handle(fd, (event_condition)cond); if (!ret && !term) { - info->loop->remove_event(id); + loop->remove_event(id); return FALSE; } -- 2.7.4 From c1c0fb3f427cacda73c80bacb1ef5b9afd410a6e Mon Sep 17 00:00:00 2001 From: Avichal Date: Wed, 8 May 2019 18:38:46 +0530 Subject: [PATCH 03/16] Adding sensord dbus policy Change-Id: I3192da5970a0e3089893b0b7e06a8c07cb207182 Signed-off-by: Avichal --- CMakeLists.txt | 3 +++ packaging/sensord.spec | 1 + sensor.conf | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 sensor.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 45e0775..d8e4b05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,3 +29,6 @@ INSTALL( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor FILES_MATCHING PATTERN "*.h" ) +INSTALL( + FILES sensor.conf DESTINATION /etc/dbus-1/system.d +) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 2cf492e..5448001 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -110,6 +110,7 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall %{_unitdir}/sensord.service %{_unitdir}/sensord.socket %{_unitdir}/multi-user.target.wants/sensord.service +%{_sysconfdir}/dbus-1/system.d/sensor.conf %{_unitdir}/sockets.target.wants/sensord.socket %license LICENSE.APLv2 diff --git a/sensor.conf b/sensor.conf new file mode 100644 index 0000000..efb4dcb --- /dev/null +++ b/sensor.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + -- 2.7.4 From 29c00fb9d92a153eb49d07323f9dddc90ad762ad Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 24 Jun 2019 11:33:05 +0900 Subject: [PATCH 04/16] Remove unnecessary settings on sensord.socket Change-Id: Id4ceeaae99469684b64d7b668ad25bd458ac19f8 --- packaging/sensord.socket | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/sensord.socket b/packaging/sensord.socket index 31cff8d..55c5454 100644 --- a/packaging/sensord.socket +++ b/packaging/sensord.socket @@ -7,7 +7,6 @@ SocketGroup=input ListenStream=/run/.sensord.socket SocketMode=0777 PassCredentials=yes -Accept=false SmackLabelIPIn=* SmackLabelIPOut=@ Service=sensord.service -- 2.7.4 From ed4d42656134e1c64bb25343cf6e7c4d40bc33c4 Mon Sep 17 00:00:00 2001 From: "srinivasa.m" Date: Fri, 12 Jul 2019 18:10:27 +0530 Subject: [PATCH 05/16] socket connection return value chack added to avoid crash Change-Id: Ic63c3d4fbd1daad11f09d8d388522bd764241a11 --- src/shared/ipc_client.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/shared/ipc_client.cpp b/src/shared/ipc_client.cpp index f021784..ea86baf 100644 --- a/src/shared/ipc_client.cpp +++ b/src/shared/ipc_client.cpp @@ -52,10 +52,10 @@ channel *ipc_client::connect(channel_handler *handler) channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bind) { - socket *sock; - channel *ch; - channel_event_handler *ev_handler; - + socket *sock = NULL; + channel *ch = NULL; + channel_event_handler *ev_handler = NULL; + bool ret = false; retvm_if(access(m_path.c_str(), F_OK), NULL, "Failed to access to %s", m_path.c_str()); @@ -82,7 +82,14 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi return NULL; } - ch->connect(ev_handler, loop); + ret = ch->connect(ev_handler, loop); + if(ret == false) { + delete ch; + delete sock; + delete ev_handler; + _E("Faield to connect"); + return NULL; + } if (loop && bind) { uint64_t id = loop->add_event(sock->get_fd(), -- 2.7.4 From 313190814bb8cc024a2e0e39b81c3958d924cf94 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 25 Jul 2019 19:13:04 +0900 Subject: [PATCH 06/16] Remove unnecessary setting Change-Id: I4e9795e2ebffd51befe5713db35d5fd0be82a4f5 --- packaging/sensord.service | 1 - packaging/sensord.socket | 1 - 2 files changed, 2 deletions(-) diff --git a/packaging/sensord.service b/packaging/sensord.service index 0f2c7f7..a8ea2ce 100644 --- a/packaging/sensord.service +++ b/packaging/sensord.service @@ -8,7 +8,6 @@ Type=notify SmackProcessLabel=System ExecStart=/usr/bin/sensord MemoryLimit=20M -Sockets=sensord.socket [Install] WantedBy=multi-user.target diff --git a/packaging/sensord.socket b/packaging/sensord.socket index 55c5454..a64cd4b 100644 --- a/packaging/sensord.socket +++ b/packaging/sensord.socket @@ -9,4 +9,3 @@ SocketMode=0777 PassCredentials=yes SmackLabelIPIn=* SmackLabelIPOut=@ -Service=sensord.service -- 2.7.4 From fffc6e5fd2ad327507bb2c709c5a110dfc58eb7b Mon Sep 17 00:00:00 2001 From: "srinivasa.m" Date: Mon, 26 Aug 2019 19:52:02 +0530 Subject: [PATCH 07/16] Coverity issues Fix Change-Id: I69e6f257e7552803b27e5b15b9d00aa52d826b6c --- src/client/sensor_provider.cpp | 2 ++ src/server/sensor_manager.cpp | 1 + 2 files changed, 3 insertions(+) mode change 100644 => 100755 src/client/sensor_provider.cpp mode change 100644 => 100755 src/server/sensor_manager.cpp diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp old mode 100644 new mode 100755 index e742309..c8f0ef6 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -123,6 +123,8 @@ int sensor_provider::send_sensor_info(sensor_info *info) m_channel->send_sync(&msg); + delete []bytes; + return OP_SUCCESS; } diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp old mode 100644 new mode 100755 index 3af7ca9..d01a870 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -143,6 +143,7 @@ void sensor_manager::send_added_msg(sensor_info *info) msg.set_type(CMD_MANAGER_SENSOR_ADDED); send(msg); + delete [] bytes; } void sensor_manager::send_removed_msg(const std::string &uri) -- 2.7.4 From 95b0e1a0763f5888c60b53fb05cce40ff9213987 Mon Sep 17 00:00:00 2001 From: Randeep Singh Date: Mon, 2 Sep 2019 08:57:59 +0000 Subject: [PATCH 08/16] Revert "Coverity issues Fix" This reverts commit fffc6e5fd2ad327507bb2c709c5a110dfc58eb7b. Change-Id: I6987d421ea17cd9d46f96d316b17b89bcad4d88d --- src/client/sensor_provider.cpp | 2 -- src/server/sensor_manager.cpp | 1 - 2 files changed, 3 deletions(-) mode change 100755 => 100644 src/client/sensor_provider.cpp mode change 100755 => 100644 src/server/sensor_manager.cpp diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp old mode 100755 new mode 100644 index c8f0ef6..e742309 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -123,8 +123,6 @@ int sensor_provider::send_sensor_info(sensor_info *info) m_channel->send_sync(&msg); - delete []bytes; - return OP_SUCCESS; } diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp old mode 100755 new mode 100644 index d01a870..3af7ca9 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -143,7 +143,6 @@ void sensor_manager::send_added_msg(sensor_info *info) msg.set_type(CMD_MANAGER_SENSOR_ADDED); send(msg); - delete [] bytes; } void sensor_manager::send_removed_msg(const std::string &uri) -- 2.7.4 From 1c4604d609e6064a3d3dff87129062a9e8548f4b Mon Sep 17 00:00:00 2001 From: "srinivasa.m" Date: Thu, 26 Sep 2019 17:18:17 +0530 Subject: [PATCH 09/16] coverity issues fix Change-Id: I1be07d5441e07219dc8eecc965c91e70e6b1c7d2 Signed-off-by: srinivasa.m --- src/client/sensor_provider.cpp | 4 ++-- src/server/sensor_manager.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index e742309..bd0b894 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -117,12 +117,12 @@ int sensor_provider::send_sensor_info(sensor_info *info) int size; size = serialize(info, &bytes); - + retvm_if(size == -ENOMEM, -ENOMEM, "Failed to serialize"); ipc::message msg((const char *)bytes, size); msg.set_type(CMD_PROVIDER_CONNECT); m_channel->send_sync(&msg); - + delete []bytes; return OP_SUCCESS; } diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index 3af7ca9..7ee0766 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -138,11 +138,13 @@ void sensor_manager::send_added_msg(sensor_info *info) int size; size = serialize(info, &bytes); + retm_if(size == -ENOMEM, "Failed to serialize"); ipc::message msg((const char *)bytes, size); msg.set_type(CMD_MANAGER_SENSOR_ADDED); send(msg); + delete []bytes; } void sensor_manager::send_removed_msg(const std::string &uri) -- 2.7.4 From f9a984d1a4d07a388bf5596ebda86e4ce5c46eb8 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Thu, 7 Nov 2019 13:58:32 +0900 Subject: [PATCH 10/16] Integrate internal fixes Change-Id: Ib7d63ed61153ef5c8ce1ad357b8dace3ad8ca0f4 Signed-off-by: Boram Bae --- CMakeLists.txt | 8 +- include/physical_sensor.h | 21 ++- include/sensor_hal_types.h | 106 +++++++++++ include/sensor_internal.h | 3 + include/sensor_types.h | 20 ++ packaging/sensord.service | 2 + packaging/sensord.socket | 2 + packaging/sensord.spec | 6 +- sensor.conf | 22 --- src/client/sensor_internal.cpp | 188 +++++++++++++++++-- src/client/sensor_listener.cpp | 61 ++++++- src/client/sensor_listener.h | 3 +- src/client/sensor_manager.cpp | 12 +- src/client/sensor_manager.h | 6 +- src/client/sensor_provider.cpp | 17 +- src/client/sensor_provider.h | 1 + src/client/sensor_provider_channel_handler.cpp | 21 +++ src/client/sensor_provider_channel_handler.h | 3 + src/client/sensor_reader.cpp | 88 +++++++++ src/client/sensor_reader.h | 53 ++++++ src/{sensor => fusion-sensor}/CMakeLists.txt | 7 +- .../auto_rotation/auto_rotation_alg.cpp | 0 .../auto_rotation/auto_rotation_alg.h | 0 .../auto_rotation/auto_rotation_alg_emul.cpp | 0 .../auto_rotation/auto_rotation_alg_emul.h | 0 .../auto_rotation/auto_rotation_sensor.cpp | 6 +- .../auto_rotation/auto_rotation_sensor.h | 0 src/{sensor => fusion-sensor}/create.cpp | 10 +- src/{sensor => fusion-sensor}/fusion_util.cpp | 0 src/{sensor => fusion-sensor}/fusion_util.h | 0 .../gesture/face_down_alg.h | 4 +- .../gesture/face_down_alg_impl.cpp | 19 +- .../gesture/face_down_alg_impl.h | 14 +- src/fusion-sensor/gesture/face_down_sensor.cpp | 131 +++++++++++++ src/fusion-sensor/gesture/face_down_sensor.h | 51 ++++++ src/fusion-sensor/gesture/pick_up_sensor.cpp | 98 ++++++++++ src/fusion-sensor/gesture/pick_up_sensor.h | 42 +++++ .../gravity/gravity_comp_sensor.cpp | 0 .../gravity/gravity_comp_sensor.h | 0 .../gravity/gravity_lowpass_sensor.cpp | 0 .../gravity/gravity_lowpass_sensor.h | 0 .../linear_accel/linear_accel_sensor.cpp | 0 .../linear_accel/linear_accel_sensor.h | 0 .../orientation/orientation_sensor.cpp | 2 +- .../orientation/orientation_sensor.h | 0 .../pedometer/average_filter.cpp | 0 .../pedometer/average_filter.h | 0 .../pedometer/pedometer.cpp | 0 .../pedometer/pedometer.h | 0 .../pedometer/pedometer_info.h | 0 .../pedometer/pedometer_sensor.cpp | 0 .../pedometer/pedometer_sensor.h | 0 .../pedometer/pedometer_speed_filter.cpp | 0 .../pedometer/pedometer_speed_filter.h | 0 .../pedometer/savitzky_golay_filter15.cpp | 0 .../pedometer/savitzky_golay_filter15.h | 0 .../pedometer/sensor_frequency_compensator.cpp | 0 .../pedometer/sensor_frequency_compensator.h | 0 .../pedometer/step_detection.cpp | 0 .../pedometer/step_detection.h | 0 .../pedometer/step_event.h | 0 .../pedometer/timestamp.h | 0 .../pedometer/zero_crossing_step_detection.cpp | 0 .../pedometer/zero_crossing_step_detection.h | 0 .../data/100ms/gravity/single_roll_throw/accel.txt | 0 .../data/100ms/gravity/single_roll_throw/gyro.txt | 0 .../100ms/gravity/single_roll_throw/magnetic.txt | 0 .../100ms/linear_acceleration/move_x_y_z/accel.txt | 0 .../100ms/linear_acceleration/move_x_y_z/gyro.txt | 0 .../linear_acceleration/move_x_y_z/magnetic.txt | 0 .../100ms/orientation/roll_pitch_yaw/accel.txt | 0 .../data/100ms/orientation/roll_pitch_yaw/gyro.txt | 0 .../100ms/orientation/roll_pitch_yaw/magnetic.txt | 0 .../data/25ms/pedo/Climb_stairs_down/In_hand/accel | 0 .../data/25ms/pedo/Climb_stairs_down/In_hand/gyro | 0 .../25ms/pedo/Climb_stairs_down/In_hand/magnetic | 0 .../25ms/pedo/Climb_stairs_down/Pant_pocket/accel | 0 .../25ms/pedo/Climb_stairs_down/Pant_pocket/gyro | 0 .../pedo/Climb_stairs_down/Pant_pocket/magnetic | 0 .../25ms/pedo/Climb_stairs_down/Shirt_pocket/accel | 0 .../25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro | 0 .../pedo/Climb_stairs_down/Shirt_pocket/magnetic | 0 .../pedo/Climb_stairs_down/While_talking/accel | 0 .../25ms/pedo/Climb_stairs_down/While_talking/gyro | 0 .../pedo/Climb_stairs_down/While_talking/magnetic | 0 .../data/25ms/pedo/Climb_stairs_up/In_hand/accel | 0 .../data/25ms/pedo/Climb_stairs_up/In_hand/gyro | 0 .../25ms/pedo/Climb_stairs_up/In_hand/magnetic | 0 .../25ms/pedo/Climb_stairs_up/Pant_pocket/accel | 0 .../25ms/pedo/Climb_stairs_up/Pant_pocket/gyro | 0 .../25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic | 0 .../25ms/pedo/Climb_stairs_up/Shirt_pocket/accel | 0 .../25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro | 0 .../pedo/Climb_stairs_up/Shirt_pocket/magnetic | 0 .../25ms/pedo/Climb_stairs_up/While_talking/accel | 0 .../25ms/pedo/Climb_stairs_up/While_talking/gyro | 0 .../pedo/Climb_stairs_up/While_talking/magnetic | 0 .../design/data/25ms/pedo/Walk_fast/In_hand/accel | 0 .../design/data/25ms/pedo/Walk_fast/In_hand/gyro | 0 .../data/25ms/pedo/Walk_fast/In_hand/magnetic | 0 .../data/25ms/pedo/Walk_fast/Pant_pocket/accel | 0 .../data/25ms/pedo/Walk_fast/Pant_pocket/gyro | 0 .../data/25ms/pedo/Walk_fast/Pant_pocket/magnetic | 0 .../data/25ms/pedo/Walk_fast/Shirt_pocket/accel | 0 .../data/25ms/pedo/Walk_fast/Shirt_pocket/gyro | 0 .../data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic | 0 .../data/25ms/pedo/Walk_fast/While_talking/accel | 0 .../data/25ms/pedo/Walk_fast/While_talking/gyro | 0 .../25ms/pedo/Walk_fast/While_talking/magnetic | 0 .../design/data/25ms/pedo/Walk_slow/In_hand/accel | 0 .../design/data/25ms/pedo/Walk_slow/In_hand/gyro | 0 .../data/25ms/pedo/Walk_slow/In_hand/magnetic | 0 .../data/25ms/pedo/Walk_slow/Pant_pocket/accel | 0 .../data/25ms/pedo/Walk_slow/Pant_pocket/gyro | 0 .../data/25ms/pedo/Walk_slow/Pant_pocket/magnetic | 0 .../data/25ms/pedo/Walk_slow/Shirt_pocket/accel | 0 .../data/25ms/pedo/Walk_slow/Shirt_pocket/gyro | 0 .../data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic | 0 .../data/25ms/pedo/Walk_slow/While_talking/accel | 0 .../data/25ms/pedo/Walk_slow/While_talking/gyro | 0 .../25ms/pedo/Walk_slow/While_talking/magnetic | 0 ...ock_diagram_gravity_and_linear_acceleration.png | Bin .../block_diagram_orientation_estimation.png | Bin .../documentation/diagram/device_orientation.png | Bin .../documentation/diagram/kalman_filter_stages.png | Bin .../diagram/orientation_effect_on_gravity.png | Bin .../projection_diagram_gravity_computation.png | Bin .../design/documentation/equation/equation_1.png | Bin .../design/documentation/equation/equation_10.png | Bin .../design/documentation/equation/equation_11.png | Bin .../design/documentation/equation/equation_12.png | Bin .../design/documentation/equation/equation_13.png | Bin .../documentation/equation/equation_13_updated.png | Bin .../design/documentation/equation/equation_14.png | Bin .../design/documentation/equation/equation_15.png | Bin .../design/documentation/equation/equation_16.png | Bin .../design/documentation/equation/equation_17.png | Bin .../design/documentation/equation/equation_18.png | Bin .../design/documentation/equation/equation_19.png | Bin .../design/documentation/equation/equation_2.png | Bin .../design/documentation/equation/equation_20.png | Bin .../design/documentation/equation/equation_21.png | Bin .../design/documentation/equation/equation_22.png | Bin .../design/documentation/equation/equation_23.png | Bin .../design/documentation/equation/equation_24.png | Bin .../design/documentation/equation/equation_25.png | Bin .../design/documentation/equation/equation_26.png | Bin .../design/documentation/equation/equation_27.png | Bin .../design/documentation/equation/equation_28.png | Bin .../design/documentation/equation/equation_29.png | Bin .../design/documentation/equation/equation_3.png | Bin .../design/documentation/equation/equation_30.png | Bin .../design/documentation/equation/equation_31.png | Bin .../design/documentation/equation/equation_32.png | Bin .../design/documentation/equation/equation_33.png | Bin .../design/documentation/equation/equation_34.png | Bin .../design/documentation/equation/equation_35.png | Bin .../design/documentation/equation/equation_36.png | Bin .../design/documentation/equation/equation_37.png | Bin .../design/documentation/equation/equation_38.png | Bin .../design/documentation/equation/equation_39.png | Bin .../design/documentation/equation/equation_4.png | Bin .../design/documentation/equation/equation_40.png | Bin .../design/documentation/equation/equation_5.png | Bin .../design/documentation/equation/equation_6.png | Bin .../design/documentation/equation/equation_7.png | Bin .../design/documentation/equation/equation_8.png | Bin .../design/documentation/equation/equation_9.png | Bin .../documentation/hardware_fusion_sensor.html | 0 .../design/documentation/sensor_fusion.htm | 0 .../rotation_vector/design/lib/axis_rot2quat.m | 0 .../design/lib/estimate_gaming_rv.m | 0 .../design/lib/estimate_geomagnetic_rv.m | 0 .../rotation_vector/design/lib/estimate_gravity.m | 0 .../design/lib/estimate_linear_acceleration.m | 0 .../design/lib/estimate_orientation.m | 0 .../rotation_vector/design/lib/euler2quat.m | 0 .../rotation_vector/design/lib/quat2euler.m | 0 .../rotation_vector/design/lib/quat2rot_mat.m | 0 .../rotation_vector/design/lib/quat_prod.m | 0 .../rotation_vector/design/lib/rot_mat2quat.m | 0 .../rotation_vector/design/lib/sf_pedometer.m | 0 .../rotation_vector/design/readme | 0 .../rotation_vector/design/sf_gaming_rv.m | 0 .../rotation_vector/design/sf_geomagnetic_rv.m | 0 .../rotation_vector/design/sf_gravity.m | 0 .../design/sf_linear_acceleration.m | 0 .../rotation_vector/design/sf_orientation.m | 0 .../rotation_vector/fusion.h | 0 .../rotation_vector/fusion_base.cpp | 0 .../rotation_vector/fusion_base.h | 0 .../rotation_vector/fusion_utils/euler_angles.cpp | 0 .../rotation_vector/fusion_utils/euler_angles.h | 0 .../rotation_vector/fusion_utils/matrix.cpp | 0 .../rotation_vector/fusion_utils/matrix.h | 0 .../fusion_utils/orientation_filter.cpp | 1 - .../fusion_utils/orientation_filter.h | 0 .../rotation_vector/fusion_utils/quaternion.cpp | 0 .../rotation_vector/fusion_utils/quaternion.h | 0 .../fusion_utils/rotation_matrix.cpp | 0 .../rotation_vector/fusion_utils/rotation_matrix.h | 0 .../rotation_vector/fusion_utils/sensor_data.cpp | 0 .../rotation_vector/fusion_utils/sensor_data.h | 0 .../rotation_vector/fusion_utils/vector.cpp | 0 .../rotation_vector/fusion_utils/vector.h | 0 .../rotation_vector/gyro_fusion.cpp | 0 .../rotation_vector/gyro_fusion.h | 0 .../rotation_vector/gyro_magnetic_fusion.cpp | 0 .../rotation_vector/gyro_magnetic_fusion.h | 0 .../rotation_vector/gyro_rv_sensor.cpp | 0 .../rotation_vector/gyro_rv_sensor.h | 0 .../rotation_vector/magnetic_fusion.cpp | 0 .../rotation_vector/magnetic_fusion.h | 0 .../rotation_vector/magnetic_rv_sensor.cpp | 0 .../rotation_vector/magnetic_rv_sensor.h | 0 .../rotation_vector/rv_sensor.cpp | 0 .../rotation_vector/rv_sensor.h | 0 src/{sensor => fusion-sensor}/tilt/tilt_sensor.cpp | 0 src/{sensor => fusion-sensor}/tilt/tilt_sensor.h | 0 src/physical-sensor/CMakeLists.txt | 41 +++++ src/physical-sensor/accel/accel_sensor.cpp | 83 +++++++++ .../accel/accel_sensor.h} | 40 ++-- src/physical-sensor/create.cpp | 52 ++++++ src/physical-sensor/macro.h | 70 +++++++ src/sensor/accel/accel_sensor.cpp | 36 ---- src/sensor/gesture/face_down_sensor.cpp | 202 --------------------- src/sensor/gesture/face_down_sensor.h | 66 ------- src/sensor/hrm/hrm_sensor.cpp | 34 ---- src/sensor/sensorhub/pedometer_sensor.cpp | 92 ---------- src/sensorctl/info.cpp | 6 +- src/sensorctl/injector.h | 2 +- src/sensorctl/sensor_adapter.cpp | 16 +- src/sensorctl/sensor_manager.cpp | 2 + src/sensorctl/sensorctl.cpp | 6 +- src/sensorctl/test_bench.h | 3 - src/sensorctl/testcase/sensor_listener.cpp | 15 +- src/sensorctl/testcase/sensor_provider.cpp | 2 +- src/server/CMakeLists.txt | 2 +- src/server/application_sensor_handler.cpp | 20 ++ src/server/dbus_util.cpp | 188 ------------------- src/server/dbus_util.h | 45 ----- src/server/main.cpp | 5 - src/server/physical_sensor_handler.cpp | 52 ++++-- src/server/physical_sensor_handler.h | 2 + src/server/sensor_event_handler.cpp | 76 +++++--- src/server/sensor_event_handler.h | 9 +- src/server/sensor_handler.cpp | 30 +-- src/server/sensor_handler.h | 3 +- src/server/sensor_listener_proxy.cpp | 62 ++++++- src/server/sensor_listener_proxy.h | 12 +- src/server/sensor_manager.cpp | 47 ++++- src/server/sensor_manager.h | 2 + .../sensor_policy_listener.h} | 20 +- src/server/sensor_policy_monitor.cpp | 97 ++++++++++ src/server/sensor_policy_monitor.h | 51 ++++++ src/server/sensor_publisher.h | 2 +- src/server/server_channel_handler.cpp | 21 +-- src/shared/CMakeLists.txt | 2 +- src/shared/cbase_lock.cpp | 154 ++++++++++++++++ src/shared/cbase_lock.h | 87 +++++++++ src/shared/channel.cpp | 93 ++++++---- src/shared/channel.h | 8 +- src/shared/channel_event_handler.cpp | 4 +- src/shared/cmutex.cpp | 64 +++++++ .../accel/accel_sensor.h => shared/cmutex.h} | 28 ++- src/shared/command_types.h | 9 +- src/shared/event_loop.cpp | 35 ++-- src/shared/event_loop.h | 4 +- src/shared/ipc_client.cpp | 21 +-- src/shared/ipc_server.cpp | 11 +- src/shared/macro.h | 22 +++ src/shared/message.cpp | 27 +-- src/shared/message.h | 2 +- src/shared/sensor_log.h | 5 + src/shared/sensor_types_private.h | 3 + src/shared/sensor_utils.cpp | 21 ++- src/shared/socket.cpp | 16 +- 277 files changed, 2101 insertions(+), 1057 deletions(-) delete mode 100644 sensor.conf create mode 100644 src/client/sensor_reader.cpp create mode 100644 src/client/sensor_reader.h rename src/{sensor => fusion-sensor}/CMakeLists.txt (90%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_alg.cpp (100%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_alg.h (100%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_alg_emul.cpp (100%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_alg_emul.h (100%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_sensor.cpp (98%) rename src/{sensor => fusion-sensor}/auto_rotation/auto_rotation_sensor.h (100%) rename src/{sensor => fusion-sensor}/create.cpp (89%) rename src/{sensor => fusion-sensor}/fusion_util.cpp (100%) rename src/{sensor => fusion-sensor}/fusion_util.h (100%) rename src/{sensor => fusion-sensor}/gesture/face_down_alg.h (90%) rename src/{sensor => fusion-sensor}/gesture/face_down_alg_impl.cpp (80%) rename src/{sensor => fusion-sensor}/gesture/face_down_alg_impl.h (86%) create mode 100644 src/fusion-sensor/gesture/face_down_sensor.cpp create mode 100644 src/fusion-sensor/gesture/face_down_sensor.h create mode 100644 src/fusion-sensor/gesture/pick_up_sensor.cpp create mode 100644 src/fusion-sensor/gesture/pick_up_sensor.h rename src/{sensor => fusion-sensor}/gravity/gravity_comp_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/gravity/gravity_comp_sensor.h (100%) rename src/{sensor => fusion-sensor}/gravity/gravity_lowpass_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/gravity/gravity_lowpass_sensor.h (100%) rename src/{sensor => fusion-sensor}/linear_accel/linear_accel_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/linear_accel/linear_accel_sensor.h (100%) rename src/{sensor => fusion-sensor}/orientation/orientation_sensor.cpp (99%) rename src/{sensor => fusion-sensor}/orientation/orientation_sensor.h (100%) rename src/{sensor => fusion-sensor}/pedometer/average_filter.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/average_filter.h (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer.h (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer_info.h (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer_sensor.h (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer_speed_filter.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/pedometer_speed_filter.h (100%) rename src/{sensor => fusion-sensor}/pedometer/savitzky_golay_filter15.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/savitzky_golay_filter15.h (100%) rename src/{sensor => fusion-sensor}/pedometer/sensor_frequency_compensator.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/sensor_frequency_compensator.h (100%) rename src/{sensor => fusion-sensor}/pedometer/step_detection.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/step_detection.h (100%) rename src/{sensor => fusion-sensor}/pedometer/step_event.h (100%) rename src/{sensor => fusion-sensor}/pedometer/timestamp.h (100%) rename src/{sensor => fusion-sensor}/pedometer/zero_crossing_step_detection.cpp (100%) rename src/{sensor => fusion-sensor}/pedometer/zero_crossing_step_detection.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/device_orientation.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/kalman_filter_stages.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_1.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_10.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_11.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_12.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_13.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_13_updated.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_14.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_15.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_16.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_17.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_18.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_19.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_2.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_20.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_21.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_22.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_23.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_24.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_25.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_26.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_27.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_28.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_29.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_3.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_30.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_31.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_32.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_33.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_34.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_35.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_36.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_37.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_38.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_39.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_4.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_40.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_5.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_6.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_7.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_8.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/equation/equation_9.png (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/hardware_fusion_sensor.html (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/documentation/sensor_fusion.htm (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/axis_rot2quat.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/estimate_gaming_rv.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/estimate_geomagnetic_rv.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/estimate_gravity.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/estimate_linear_acceleration.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/estimate_orientation.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/euler2quat.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/quat2euler.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/quat2rot_mat.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/quat_prod.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/rot_mat2quat.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/lib/sf_pedometer.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/readme (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/sf_gaming_rv.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/sf_geomagnetic_rv.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/sf_gravity.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/sf_linear_acceleration.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/design/sf_orientation.m (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_base.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_base.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/euler_angles.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/euler_angles.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/matrix.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/matrix.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/orientation_filter.cpp (99%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/orientation_filter.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/quaternion.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/quaternion.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/rotation_matrix.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/rotation_matrix.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/sensor_data.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/sensor_data.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/vector.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/fusion_utils/vector.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_fusion.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_fusion.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_magnetic_fusion.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_magnetic_fusion.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_rv_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/gyro_rv_sensor.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/magnetic_fusion.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/magnetic_fusion.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/magnetic_rv_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/magnetic_rv_sensor.h (100%) rename src/{sensor => fusion-sensor}/rotation_vector/rv_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/rotation_vector/rv_sensor.h (100%) rename src/{sensor => fusion-sensor}/tilt/tilt_sensor.cpp (100%) rename src/{sensor => fusion-sensor}/tilt/tilt_sensor.h (100%) create mode 100644 src/physical-sensor/CMakeLists.txt create mode 100644 src/physical-sensor/accel/accel_sensor.cpp rename src/{sensor/sensorhub/pedometer_sensor.h => physical-sensor/accel/accel_sensor.h} (51%) create mode 100644 src/physical-sensor/create.cpp create mode 100644 src/physical-sensor/macro.h delete mode 100644 src/sensor/accel/accel_sensor.cpp delete mode 100644 src/sensor/gesture/face_down_sensor.cpp delete mode 100644 src/sensor/gesture/face_down_sensor.h delete mode 100644 src/sensor/hrm/hrm_sensor.cpp delete mode 100644 src/sensor/sensorhub/pedometer_sensor.cpp delete mode 100644 src/server/dbus_util.cpp delete mode 100644 src/server/dbus_util.h rename src/{sensor/hrm/hrm_sensor.h => server/sensor_policy_listener.h} (65%) create mode 100644 src/server/sensor_policy_monitor.cpp create mode 100644 src/server/sensor_policy_monitor.h create mode 100644 src/shared/cbase_lock.cpp create mode 100644 src/shared/cbase_lock.h create mode 100644 src/shared/cmutex.cpp rename src/{sensor/accel/accel_sensor.h => shared/cmutex.h} (58%) mode change 100755 => 100644 src/shared/message.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d8e4b05..047a1cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,--gc-sections -Wl,--print-gc-sections") SET(CMAKE_VERBOSE_MAKEFILE OFF) MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}") MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") @@ -22,13 +22,11 @@ ADD_SUBDIRECTORY(src/server) ADD_SUBDIRECTORY(src/client) ADD_SUBDIRECTORY(src/client-dummy) ADD_SUBDIRECTORY(src/sensorctl) -ADD_SUBDIRECTORY(src/sensor) +ADD_SUBDIRECTORY(src/physical-sensor) +ADD_SUBDIRECTORY(src/fusion-sensor) INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor FILES_MATCHING PATTERN "*.h" ) -INSTALL( - FILES sensor.conf DESTINATION /etc/dbus-1/system.d -) diff --git a/include/physical_sensor.h b/include/physical_sensor.h index 6009167..58c57da 100644 --- a/include/physical_sensor.h +++ b/include/physical_sensor.h @@ -25,13 +25,15 @@ #include #include +#include "sensor_hal.h" + #ifndef SENSOR_VERSION #define PHYSICAL_SENSOR_VERSION(maj, min) \ ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) #endif #ifndef OP_SUCCESS -#define OP_SUCCESS 1 +#define OP_SUCCESS 0 #endif #ifndef OP_ERROR #define OP_ERROR -1 @@ -57,11 +59,22 @@ public: inline uint32_t get_version(void) { return PHYSICAL_SENSOR_VERSION(1, 0); } - /* TODO */ + virtual std::string get_uri(void) { return ""; } virtual std::string get_privilege(void) { return ""; } - virtual int start(observer_h ob) = 0; - virtual int stop(observer_h ob) = 0; + virtual physical_sensor *clone(void) const = 0; + virtual void set_device(sensor_device *device) { return; } + + virtual int start(observer_h ob) + { + return OP_DEFAULT; + } + + virtual int stop(observer_h ob) + { + return OP_DEFAULT; + } + virtual int set_interval(observer_h ob, uint32_t interval) { return OP_DEFAULT; diff --git a/include/sensor_hal_types.h b/include/sensor_hal_types.h index 6910e30..1dfe2d4 100644 --- a/include/sensor_hal_types.h +++ b/include/sensor_hal_types.h @@ -20,6 +20,7 @@ #include #include +#include #define SENSOR_HAL_VERSION(maj, min) \ ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) @@ -69,6 +70,8 @@ typedef enum { SENSOR_DEVICE_GYROSCOPE_RV, SENSOR_DEVICE_GEOMAGNETIC_RV, + SENSOR_DEVICE_SIGNIFICANT_MOTION = 0x100, + SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, @@ -83,20 +86,29 @@ typedef enum { SENSOR_DEVICE_EXERCISE_ROWING, SENSOR_DEVICE_EXERCISE_STEPPER, + SENSOR_DEVICE_DATA_JOURNAL = 0x500, + SENSOR_DEVICE_FUSION = 0x900, SENSOR_DEVICE_AUTO_ROTATION, SENSOR_DEVICE_AUTO_BRIGHTNESS, + SENSOR_DEVICE_MYOTEST, SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, SENSOR_DEVICE_GESTURE_WRIST_UP, SENSOR_DEVICE_GESTURE_WRIST_DOWN, SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, + SENSOR_DEVICE_GESTURE_PICK_UP, + SENSOR_DEVICE_GESTURE_FACE_DOWN, SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00, SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, SENSOR_DEVICE_GPS_BATCH, + SENSOR_DEVICE_PPG_BATCH, + SENSOR_DEVICE_GPS_TIMESYNC, SENSOR_DEVICE_HRM_CTRL = 0x1A80, + SENSOR_DEVICE_REG_CTRL, + SENSOR_DEVICE_GPS_CTRL, SENSOR_DEVICE_WEAR_STATUS = 0x2000, SENSOR_DEVICE_WEAR_ON_MONITOR, @@ -111,6 +123,16 @@ typedef enum { SENSOR_DEVICE_PRESSURE_INDICATOR, SENSOR_DEVICE_PRESSURE_ALERT, SENSOR_DEVICE_HR_CALORIE, + SENSOR_DEVICE_SWIMMING_TRACKER, + SENSOR_DEVICE_STRESS_TRACKER, + SENSOR_DEVICE_FAKE_MOTION, + SENSOR_DEVICE_GEOFENCE, + SENSOR_DEVICE_SWIMMING_OUTDOOR, + SENSOR_DEVICE_AUTO_SWIMMING, + SENSOR_DEVICE_INACTIVITY_DETECTOR, + SENSOR_DEVICE_HRM_BP, + SENSOR_DEVICE_ECG, + SENSOR_DEVICE_FALL_DETECTION, SENSOR_DEVICE_CONTEXT = 0x7000, SENSOR_DEVICE_MOTION, @@ -126,6 +148,7 @@ typedef enum { SENSOR_DEVICE_GSR, SENSOR_DEVICE_SIMSENSE, SENSOR_DEVICE_PPG, + } sensor_device_type; /* @@ -228,6 +251,8 @@ enum sensor_attribute { 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_PEDOMETER_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x4), + SENSOR_ATTR_PEDOMETER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2F), SENSOR_ATTR_STRESS_MONITOR_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), @@ -239,6 +264,9 @@ enum sensor_attribute { 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_CYCLE_GET_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x4), + SENSOR_ATTR_CYCLE_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x5), + SENSOR_ATTR_CYCLE_GPS_AGREEMENT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x6), SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1), SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2), @@ -260,10 +288,17 @@ enum sensor_attribute { 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_STEP_LEVEL_MONITOR_DW_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STEP_LEVEL_MONITOR, 0x1), + 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_EXERCISE_HR_ELEVATED_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x5), + SENSOR_ATTR_EXERCISE_HR_ELEVATED_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x6), + SENSOR_ATTR_EXERCISE_HR_BPM_RAW = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x7), + SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x8), + SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x9), 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), @@ -284,6 +319,77 @@ enum sensor_attribute { 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), + + SENSOR_ATTR_SWIMMING_TRACKER_PLACE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x1), + SENSOR_ATTR_SWIMMING_TRACKER_DISTANCE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x2), + SENSOR_ATTR_SWIMMING_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x3), + SENSOR_ATTR_SWIMMING_TRACKER_BATCH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x4), + SENSOR_ATTR_SWIMMING_TRACKER_GOAL_CALORIES = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x5), + SENSOR_ATTR_SWIMMING_TRACKER_GOAL_LAPS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x6), + SENSOR_ATTR_SWIMMING_TRACKER_TIME_REST = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x7), + SENSOR_ATTR_SWIMMING_TRACKER_TIME_TURN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x8), + + SENSOR_ATTR_SWIMMING_OUTDOOR_SET_BATCH_LAP_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x1), + SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_LENGTH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x2), + SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x3), + SENSOR_ATTR_SWIMMING_OUTDOOR_SET_GPS_PERMISSION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x4), + SENSOR_ATTR_SWIMMING_OUTDOOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x6), + + SENSOR_ATTR_AUTO_SWIMMING_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_AUTO_SWIMMING, 0x1), + + SENSOR_ATTR_INACTIVITY_DETECTOR_LEVEL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x1), + SENSOR_ATTR_INACTIVITY_DETECTOR_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x2), + + SENSOR_ATTR_STRESS_TRACKER_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x1), + SENSOR_ATTR_STRESS_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x2), + + SENSOR_ATTR_STRESS_MONITOR_BASE_HR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), + SENSOR_ATTR_STRESS_MONITOR_HISTO_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x2), + SENSOR_ATTR_STRESS_MONITOR_HISTO_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x3), + SENSOR_ATTR_STRESS_MONITOR_TUNE_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x4), + SENSOR_ATTR_STRESS_MONITOR_TUNE_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x5), + SENSOR_ATTR_STRESS_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x6), + SENSOR_ATTR_STRESS_MONITOR_OPERATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x7), + + SENSOR_ATTR_SLEEP_MONITOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x1), + SENSOR_ATTR_SLEEP_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x2), + + SENSOR_ATTR_SLEEP_DETECTOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x1), + SENSOR_ATTR_SLEEP_DETECTOR_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x2), + + SENSOR_ATTR_DATA_JOURNAL_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x1), + SENSOR_ATTR_DATA_JOURNAL_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x2), + + SENSOR_ATTR_GPS_BATCH_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_BATCH, 0x1), + + SENSOR_ATTR_PPG_BATCH_POLLING_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x1), + SENSOR_ATTR_PPG_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x2), + + SENSOR_ATTR_REG_CTRL_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x1), + SENSOR_ATTR_REG_CTRL_ADDRESS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x2), + SENSOR_ATTR_REG_CTRL_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x3), + SENSOR_ATTR_REG_CTRL_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x4), + + SENSOR_ATTR_GPS_CTRL_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_CTRL, 0x1), + + SENSOR_ATTR_FAKE_MOTION_EVENT_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x1), + SENSOR_ATTR_FAKE_MOTION_EVENT_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x2), + SENSOR_ATTR_FAKE_MOTION_PAUSE_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x3), + + SENSOR_ATTR_GEOFENCE_ID = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x1), + SENSOR_ATTR_GEOFENCE_LAT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x2), + SENSOR_ATTR_GEOFENCE_LON = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x3), + SENSOR_ATTR_GEOFENCE_RADIUS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x4), + SENSOR_ATTR_GEOFENCE_PROVIDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x5), + SENSOR_ATTR_GEOFENCE_ACCURACY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x6), + SENSOR_ATTR_GEOFENCE_TIMESTAMP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x7), + SENSOR_ATTR_GEOFENCE_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x8), + SENSOR_ATTR_GEOFENCE_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x10), + SENSOR_ATTR_GEOFENCE_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x11), + SENSOR_ATTR_GEOFENCE_SET_LOCATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x12), + SENSOR_ATTR_GEOFENCE_BT_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x13), + + SENSOR_ATTR_FALL_DETECTION_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FALL_DETECTION, 0x1), }; enum sensor_activity { diff --git a/include/sensor_internal.h b/include/sensor_internal.h index ee3b375..d9f2b18 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -423,6 +423,9 @@ int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_s typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data); int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data); +typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data); +int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data); + int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data); /* Deprecated */ diff --git a/include/sensor_types.h b/include/sensor_types.h index 9c9426c..62aebbc 100644 --- a/include/sensor_types.h +++ b/include/sensor_types.h @@ -92,6 +92,8 @@ typedef enum sensor_type_t { GYROSCOPE_RV_SENSOR, GEOMAGNETIC_RV_SENSOR, + SIGNIFICANT_MOTION_SENSOR = 0x100, + HUMAN_PEDOMETER_SENSOR = 0x300, HUMAN_SLEEP_MONITOR_SENSOR, HUMAN_SLEEP_DETECTOR_SENSOR, @@ -108,24 +110,32 @@ typedef enum sensor_type_t { EXERCISE_ROWING_SENSOR, EXERCISE_STEPPER_SENSOR, + DATA_JOURNAL_SENSOR = 0x500, + EXTERNAL_EXERCISE_SENSOR = 0x800, EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR, FUSION_SENSOR = 0x900, AUTO_ROTATION_SENSOR, AUTO_BRIGHTNESS_SENSOR, + MYOTEST_SENSOR, GESTURE_MOVEMENT_SENSOR = 0x1200, GESTURE_WRIST_UP_SENSOR, GESTURE_WRIST_DOWN_SENSOR, GESTURE_MOVEMENT_STATE_SENSOR, + GESTURE_PICK_UP_SENSOR, GESTURE_FACE_DOWN_SENSOR, ACTIVITY_TRACKER_SENSOR = 0x1A00, ACTIVITY_LEVEL_MONITOR_SENSOR, GPS_BATCH_SENSOR, + PPG_BATCH_SENSOR, + GPS_TIMESYNC_SENSOR, HRM_CTRL_SENSOR = 0x1A80, + REG_CTRL_SENSOR, + GPS_CTRL_SENSOR, WEAR_STATUS_SENSOR = 0x2000, WEAR_ON_MONITOR_SENSOR, @@ -142,6 +152,16 @@ typedef enum sensor_type_t { PRESSURE_INDICATOR_SENSOR, PRESSURE_ALERT_SENSOR, HR_CALORIE_SENSOR, + SWIMMING_TRACKER_SENSOR, + STRESS_TRACKER_SENSOR, + FAKE_MOTION_SENSOR, + GEOFENCE_SENSOR, + SWIMMING_OUTDOOR_SENSOR, + AUTO_SWIMMING_SENSOR, + INACTIVITY_DETECTOR_SENSOR, + HRM_BP_SENSOR, + ECG_SENSOR, + FALL_DETECTION_SENSOR, CONTEXT_SENSOR = 0x7000, MOTION_SENSOR, diff --git a/packaging/sensord.service b/packaging/sensord.service index a8ea2ce..be67d1b 100644 --- a/packaging/sensord.service +++ b/packaging/sensord.service @@ -8,6 +8,8 @@ Type=notify SmackProcessLabel=System ExecStart=/usr/bin/sensord MemoryLimit=20M +Sockets=sensord.socket +Nice=-5 [Install] WantedBy=multi-user.target diff --git a/packaging/sensord.socket b/packaging/sensord.socket index a64cd4b..31cff8d 100644 --- a/packaging/sensord.socket +++ b/packaging/sensord.socket @@ -7,5 +7,7 @@ SocketGroup=input ListenStream=/run/.sensord.socket SocketMode=0777 PassCredentials=yes +Accept=false SmackLabelIPIn=* SmackLabelIPOut=@ +Service=sensord.service diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 5448001..9ea15c0 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 4.0.3 +Version: 4.0.54 Release: 1 Group: System/Sensor Framework License: Apache-2.0 @@ -14,6 +14,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) @@ -67,7 +68,6 @@ Group: System/Testing %description -n sensor-test Sensor functional testing - %prep %setup -q @@ -106,11 +106,11 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall %{_libdir}/libsensor-genuine.so.* %{_libdir}/libsensord-shared.so %{_libdir}/sensor/fusion/libsensor-fusion.so +%{_libdir}/sensor/physical/libsensor-physical.so %{_bindir}/sensord %{_unitdir}/sensord.service %{_unitdir}/sensord.socket %{_unitdir}/multi-user.target.wants/sensord.service -%{_sysconfdir}/dbus-1/system.d/sensor.conf %{_unitdir}/sockets.target.wants/sensord.socket %license LICENSE.APLv2 diff --git a/sensor.conf b/sensor.conf deleted file mode 100644 index efb4dcb..0000000 --- a/sensor.conf +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 5a9f042..a0f1e08 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -30,17 +30,67 @@ #include #include #include +#include +#include + +#include "sensor_reader.h" #define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11) #define MAX_LISTENER 100 using namespace sensor; +typedef struct { + int listener_id; + sensor_cb_t cb; + sensor_accuracy_changed_cb_t acc_cb; + sensor_info *sensor; + sensor_data_t *data; + void *user_data; +} callback_info_s; + +static sensor::sensor_manager manager; +static std::unordered_map listeners; +static cmutex lock; + +static gboolean callback_dispatcher(gpointer data) +{ + int event_type = 0; + callback_info_s *info = (callback_info_s *)data; + + AUTOLOCK(lock); + + if (info->sensor) + event_type = CONVERT_TYPE_EVENT(info->sensor->get_type()); + + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) + info->cb(info->sensor, event_type, info->data, info->user_data); + + delete [] info->data; + delete info; + return FALSE; +} + +static gboolean accuracy_callback_dispatcher(gpointer data) +{ + callback_info_s *info = (callback_info_s *)data; + + AUTOLOCK(lock); + + if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) + info->acc_cb(info->sensor, info->data->timestamp, info->data->accuracy, info->user_data); + + delete [] info->data; + delete info; + return FALSE; +} + class sensor_event_handler : public ipc::channel_handler { public: - sensor_event_handler(sensor_t sensor, sensor_cb_t cb, void *user_data) - : m_sensor(reinterpret_cast(sensor)) + sensor_event_handler(int id, sensor_t sensor, sensor_cb_t cb, void *user_data) + : m_listener_id(id) + , m_sensor(reinterpret_cast(sensor)) , m_cb(cb) , m_user_data(user_data) {} @@ -49,19 +99,26 @@ public: void disconnected(ipc::channel *ch) {} void read(ipc::channel *ch, ipc::message &msg) { - int event_type; - sensor_data_t *data; + callback_info_s *info; + sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()]; + + memcpy(data, msg.body(), msg.size()); - data = reinterpret_cast(msg.body()); - event_type = CONVERT_TYPE_EVENT(m_sensor->get_type()); + info = new(std::nothrow) callback_info_s(); + info->listener_id = m_listener_id; + info->cb = m_cb; + info->sensor = m_sensor; + info->data = data; + info->user_data = m_user_data; - m_cb(m_sensor, event_type, data, m_user_data); + g_idle_add(callback_dispatcher, info); } void read_complete(ipc::channel *ch) {} void error_caught(ipc::channel *ch, int error) {} private: + int m_listener_id; sensor_info *m_sensor; sensor_cb_t m_cb; void *m_user_data; @@ -70,8 +127,9 @@ private: class sensor_accuracy_handler : public ipc::channel_handler { public: - sensor_accuracy_handler(sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data) - : m_sensor(reinterpret_cast(sensor)) + sensor_accuracy_handler(int id, sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data) + : m_listener_id(id) + , m_sensor(reinterpret_cast(sensor)) , m_cb(cb) , m_user_data(user_data) {} @@ -80,24 +138,31 @@ public: void disconnected(ipc::channel *ch) {} void read(ipc::channel *ch, ipc::message &msg) { - sensor_data_t *data; - data = reinterpret_cast(msg.body()); + callback_info_s *info; + sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()]; + + memcpy(data, msg.body(), msg.size()); + + info = new(std::nothrow) callback_info_s(); + info->listener_id = m_listener_id; + info->acc_cb = m_cb; + info->sensor = m_sensor; + info->data = data; + info->user_data = m_user_data; - m_cb(m_sensor, data->timestamp, data->accuracy, m_user_data); + g_idle_add(accuracy_callback_dispatcher, info); } void read_complete(ipc::channel *ch) {} void error_caught(ipc::channel *ch, int error) {} private: + int m_listener_id; sensor_info *m_sensor; sensor_accuracy_changed_cb_t m_cb; void *m_user_data; }; -static sensor::sensor_manager manager; -static std::unordered_map listeners; - /* * TO-DO-LIST: * 1. power save option / lcd vconf : move to server @@ -236,18 +301,23 @@ API bool sensord_is_wakeup_supported(sensor_t sensor) API int sensord_connect(sensor_t sensor) { + AUTOLOCK(lock); + retvm_if(!manager.connect(), -EIO, "Failed to connect"); retvm_if(!manager.is_supported(sensor), -EINVAL, "Invalid sensor[%p]", sensor); retvm_if(listeners.size() > MAX_LISTENER, -EPERM, "Exceeded the maximum listener"); sensor::sensor_listener *listener; + static sensor_reader reader; - listener = new(std::nothrow) sensor::sensor_listener(sensor); + listener = new(std::nothrow) sensor::sensor_listener(sensor, reader.get_event_loop()); retvm_if(!listener, -ENOMEM, "Failed to allocate memory"); listeners[listener->get_id()] = listener; + _D("Connect[%d]", listener->get_id()); + return listener->get_id(); } @@ -255,12 +325,16 @@ API bool sensord_disconnect(int handle) { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); listener = it->second; retvm_if(!listener, false, "Invalid handle[%d]", handle); + _D("Disconnect[%d]", listener->get_id()); + delete listener; listeners.erase(handle); @@ -275,6 +349,8 @@ API bool sensord_register_event(int handle, unsigned int event_type, int prev_max_batch_latency; sensor_event_handler *handler; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -294,7 +370,7 @@ API bool sensord_register_event(int handle, unsigned int event_type, return false; } - handler = new(std::nothrow) sensor_event_handler(listener->get_sensor(), cb, user_data); + handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, user_data); if (!handler) { listener->set_max_batch_latency(prev_max_batch_latency); listener->set_interval(prev_interval); @@ -304,6 +380,8 @@ API bool sensord_register_event(int handle, unsigned int event_type, listener->set_event_handler(handler); + _D("Register event[%d]", listener->get_id()); + return true; } @@ -311,6 +389,8 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -318,6 +398,8 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) listener->unset_event_handler(); + _D("Unregister event[%d]", listener->get_id()); + return true; } @@ -326,12 +408,14 @@ API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t c sensor::sensor_listener *listener; sensor_accuracy_handler *handler; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); listener = it->second; - handler = new(std::nothrow) sensor_accuracy_handler(listener->get_sensor(), cb, user_data); + handler = new(std::nothrow) sensor_accuracy_handler(handle, listener->get_sensor(), cb, user_data); retvm_if(!handler, false, "Failed to allocate memory"); listener->set_accuracy_handler(handler); @@ -343,6 +427,8 @@ API bool sensord_unregister_accuracy_cb(int handle) { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -358,6 +444,9 @@ API bool sensord_start(int handle, int option) sensor::sensor_listener *listener; int prev_pause; int pause; + int interval, batch_latency; + + AUTOLOCK(lock); auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -378,6 +467,16 @@ API bool sensord_start(int handle, int option) return false; } + interval = listener->get_interval(); + if (interval > 0) + listener->set_interval(interval); + + batch_latency = listener->get_max_batch_latency(); + listener->set_max_batch_latency(batch_latency); + + _D("Start[%d] with the interval[%d] batch_latency[%d]", + listener->get_id(), interval, batch_latency); + return true; } @@ -386,6 +485,8 @@ API bool sensord_stop(int handle) int ret; sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -396,6 +497,8 @@ API bool sensord_stop(int handle) if (ret == -EAGAIN || ret == OP_SUCCESS) return true; + _D("Stop[%d]", listener->get_id()); + return false; } @@ -403,6 +506,8 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -413,6 +518,8 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi return false; } + _D("Set interval[%d, %d]", listener->get_id(), interval); + return true; } @@ -420,6 +527,8 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -430,6 +539,8 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t return false; } + _D("Set max batch latency[%d, %u]", listener->get_id(), max_batch_latency); + return true; } @@ -438,6 +549,8 @@ API bool sensord_set_option(int handle, int option) sensor::sensor_listener *listener; int pause; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -450,6 +563,8 @@ API bool sensord_set_option(int handle, int option) return false; } + _D("Set pause option[%d, %d]", listener->get_id(), pause); + return true; } @@ -467,6 +582,8 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return -EIO; } + _D("Set attribute[%d, %d, %d]", listener->get_id(), attribute, value); + return OP_SUCCESS; } @@ -491,6 +608,8 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -508,6 +627,8 @@ API bool sensord_flush(int handle) { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -525,6 +646,8 @@ API bool sensord_set_passive_mode(int handle, bool passive) { sensor::sensor_listener *listener; + AUTOLOCK(lock); + auto it = listeners.find(handle); retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); @@ -746,6 +869,18 @@ API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, se return OP_SUCCESS; } +API int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data) +{ + retvm_if(!provider, -EINVAL, "Invalid paramter"); + retvm_if(!callback, -EINVAL, "Invalid paramter"); + + sensor_provider *p = static_cast(provider); + + p->set_attribute_str_cb(callback, user_data); + + return OP_SUCCESS; +} + API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data) { retvm_if(!provider, -EINVAL, "Invalid paramter"); @@ -822,6 +957,23 @@ API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege) return true; } +static std::unordered_map external_providers; +static int provider_id = 0; + +typedef struct external_cb_info_s { + int id; + sensor_external_command_cb_t cb; + void *user_data; +} external_cb_info_s; + +static void external_attr_cb(sensord_provider_h provider, int attribute, const char *data, int cnt, void *user_data) +{ + external_cb_info_s *info = (external_cb_info_s *)user_data; + + if (info->cb) + info->cb(info->id, data, cnt, info->user_data); +} + /* deprecated */ API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data) { diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index 96a7076..e08e179 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -24,9 +24,12 @@ #include #include #include +#include using namespace sensor; +static cmutex lock; + class listener_handler : public ipc::channel_handler { public: @@ -36,7 +39,6 @@ public: void connected(ipc::channel *ch) {} void disconnected(ipc::channel *ch) { - _D("Disconnected"); /* If channel->disconnect() is not explicitly called, * listener will be restored */ m_listener->restore(); @@ -78,6 +80,22 @@ sensor_listener::sensor_listener(sensor_t sensor) init(); } +sensor_listener::sensor_listener(sensor_t sensor, ipc::event_loop *loop) +: m_id(0) +, m_sensor(reinterpret_cast(sensor)) +, m_client(NULL) +, m_cmd_channel(NULL) +, m_evt_channel(NULL) +, m_handler(NULL) +, m_evt_handler(NULL) +, m_acc_handler(NULL) +, m_loop(loop) +, m_connected(false) +, m_started(false) +{ + init(); +} + sensor_listener::~sensor_listener() { deinit(); @@ -107,6 +125,8 @@ bool sensor_listener::init(void) void sensor_listener::deinit(void) { + _D("Deinitializing.."); + stop(); disconnect(); delete m_handler; @@ -116,6 +136,7 @@ void sensor_listener::deinit(void) m_client = NULL; m_attributes.clear(); + _D("Deinitialized.."); } int sensor_listener::get_id(void) @@ -133,6 +154,8 @@ void sensor_listener::restore(void) ret_if(!is_connected()); retm_if(!connect(), "Failed to restore listener"); + _D("Restoring sensor listener"); + /* Restore attributes/status */ if (m_started.load()) start(); @@ -153,7 +176,7 @@ bool sensor_listener::connect(void) m_cmd_channel = m_client->connect(NULL); retvm_if(!m_cmd_channel, false, "Failed to connect to server"); - m_evt_channel = m_client->connect(m_handler, &m_loop, false); + m_evt_channel = m_client->connect(m_handler, m_loop, false); retvm_if(!m_evt_channel, false, "Failed to connect to server"); ipc::message msg; @@ -183,6 +206,8 @@ void sensor_listener::disconnect(void) ret_if(!is_connected()); m_connected.store(false); + _D("Disconnecting.."); + m_evt_channel->disconnect(); delete m_evt_channel; m_evt_channel = NULL; @@ -201,16 +226,22 @@ bool sensor_listener::is_connected(void) ipc::channel_handler *sensor_listener::get_event_handler(void) { + AUTOLOCK(lock); + return m_evt_handler; } void sensor_listener::set_event_handler(ipc::channel_handler *handler) { + AUTOLOCK(lock); + m_evt_handler = handler; } void sensor_listener::unset_event_handler(void) { + AUTOLOCK(lock); + delete m_evt_handler; m_evt_handler = NULL; } @@ -275,7 +306,7 @@ int sensor_listener::stop(void) m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { - _E("Failed to stop listener[%d], sensor[%s]", get_id(), m_sensor->get_uri().c_str()); + _E("Failed to stop listener[%d]", get_id()); return reply.header()->err; } @@ -332,6 +363,12 @@ int sensor_listener::set_interval(unsigned int interval) _I("Listener[%d] set interval[%u]", get_id(), _interval); + /* If it is not started, store the value only */ + if (!m_started.load()) { + m_attributes[SENSORD_ATTRIBUTE_INTERVAL] = _interval; + return OP_SUCCESS; + } + return set_attribute(SENSORD_ATTRIBUTE_INTERVAL, _interval); } @@ -339,6 +376,12 @@ int sensor_listener::set_max_batch_latency(unsigned int max_batch_latency) { _I("Listener[%d] set max batch latency[%u]", get_id(), max_batch_latency); + /* If it is not started, store the value only */ + if (!m_started.load()) { + m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency; + return OP_SUCCESS; + } + return set_attribute(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY, max_batch_latency); } @@ -392,14 +435,14 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) size = sizeof(cmd_listener_attr_str_t) + len; - buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; + buf = (cmd_listener_attr_str_t *) malloc(sizeof(char) * size); retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); msg.set_type(CMD_LISTENER_ATTR_STR); buf->listener_id = m_id; buf->attribute = attribute; - memcpy(&buf->value, value, len); + memcpy(buf->value, value, len); buf->len = len; msg.enclose((char *)buf, size); @@ -407,9 +450,13 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) m_cmd_channel->send_sync(&msg); m_cmd_channel->read_sync(reply); - delete [] buf; + /* Message memory is released automatically after sending message, + so it doesn't need to free memory */ - return reply.header()->err; + if (reply.header()->err < 0) + return reply.header()->err; + + return OP_SUCCESS; } int sensor_listener::get_sensor_data(sensor_data_t *data) diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h index f0a1f1b..be53ee5 100644 --- a/src/client/sensor_listener.h +++ b/src/client/sensor_listener.h @@ -34,6 +34,7 @@ namespace sensor { class sensor_listener { public: sensor_listener(sensor_t sensor); + sensor_listener(sensor_t sensor, ipc::event_loop *loop); virtual ~sensor_listener(); int get_id(void); @@ -85,7 +86,7 @@ private: ipc::channel_handler *m_handler; ipc::channel_handler *m_evt_handler; ipc::channel_handler *m_acc_handler; - ipc::event_loop m_loop; + ipc::event_loop *m_loop; std::atomic m_connected; std::atomic m_started; std::map m_attributes; diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 1c59634..f16601f 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -54,7 +54,7 @@ int sensor_manager::get_sensor(const char *uri, sensor_t *sensor) } sensor_info *info = get_info(uri); - retv_if(!info, -EACCES); + retvm_if(!info, -EACCES, "There is no accessible sensor for uri[%s]", uri); *sensor = (sensor_t)info; return OP_SUCCESS; @@ -69,7 +69,7 @@ int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count) infos = get_infos(uri); size = infos.size(); - retv_if(size == 0, -EACCES); + retvm_if(size == 0, -EACCES, "There is no accessible sensors for uri[%s]", uri); *list = (sensor_t *)malloc(sizeof(sensor_info *) * size); retvm_if(!*list, -ENOMEM, "Failed to allocate memory"); @@ -134,8 +134,8 @@ int sensor_manager::remove_sensor(const char *uri) { for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { if ((*it).get_uri() == uri) { - _I("Removing sensor[%s]", (*it).get_uri().c_str()); - it = m_sensors.erase(it); + m_sensors.erase(it); + _I("Removed sensor[%s]", uri); return OP_SUCCESS; } @@ -254,7 +254,7 @@ void sensor_manager::restore(void) _D("Restored manager"); } -void sensor_manager::decode_sensors(const char *buf, std::vector &infos) +void sensor_manager::decode_sensors(const char *buf, std::list &infos) { int count = 0; sensor_info info; @@ -333,7 +333,7 @@ bool sensor_manager::has_privilege(std::string &uri) sensor_info *sensor_manager::get_info(const char *uri) { if (strncmp(uri, utils::get_uri(ALL_SENSOR), strlen(utils::get_uri(ALL_SENSOR))) == 0) - return &m_sensors[0]; + return &m_sensors.front(); for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { if ((*it).get_uri() != uri) diff --git a/src/client/sensor_manager.h b/src/client/sensor_manager.h index 350bb01..c335e0a 100644 --- a/src/client/sensor_manager.h +++ b/src/client/sensor_manager.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "sensor_internal.h" @@ -68,7 +68,7 @@ private: bool connect_channel(void); bool is_connected(void); - void decode_sensors(const char *buf, std::vector &infos); + void decode_sensors(const char *buf, std::list &infos); bool get_sensors_internal(void); bool has_privilege(std::string &uri); @@ -82,7 +82,7 @@ private: std::atomic m_connected; channel_handler *m_handler; - std::vector m_sensors; + std::list m_sensors; }; } diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index bd0b894..7afe921 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -117,12 +117,12 @@ int sensor_provider::send_sensor_info(sensor_info *info) int size; size = serialize(info, &bytes); - retvm_if(size == -ENOMEM, -ENOMEM, "Failed to serialize"); + ipc::message msg((const char *)bytes, size); msg.set_type(CMD_PROVIDER_CONNECT); m_channel->send_sync(&msg); - delete []bytes; + return OP_SUCCESS; } @@ -170,14 +170,6 @@ void sensor_provider::restore(void) int sensor_provider::publish(sensor_data_t *data, int len) { - for (int i = 0; i < data->value_count; ++i) { - if (!(data->values[i] >= m_sensor.get_min_range() && - data->values[i] <= m_sensor.get_max_range())) { - _E("Out of range"); - return OP_ERROR; - } - } - ipc::message msg; msg.set_type(CMD_PROVIDER_PUBLISH); msg.enclose((const char *)data, len); @@ -207,3 +199,8 @@ void sensor_provider::set_interval_cb(sensord_provider_interval_changed_cb cb, v m_handler->set_interval_cb(cb, user_data); } +void sensor_provider::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data) +{ + m_handler->set_attribute_str_cb(cb, user_data); +} + diff --git a/src/client/sensor_provider.h b/src/client/sensor_provider.h index 2191b60..7b26754 100644 --- a/src/client/sensor_provider.h +++ b/src/client/sensor_provider.h @@ -47,6 +47,7 @@ public: void set_start_cb(sensord_provider_start_cb cb, void *user_data); void set_stop_cb(sensord_provider_stop_cb cb, void *user_data); void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data); + void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data); int publish(sensor_data_t *data, int len); diff --git a/src/client/sensor_provider_channel_handler.cpp b/src/client/sensor_provider_channel_handler.cpp index ed3fd01..c939138 100644 --- a/src/client/sensor_provider_channel_handler.cpp +++ b/src/client/sensor_provider_channel_handler.cpp @@ -30,9 +30,11 @@ sensor_provider::channel_handler::channel_handler(sensor_provider *provider) , m_start_cb(NULL) , m_stop_cb(NULL) , m_interval_changed_cb(NULL) +, m_attribute_str_cb(NULL) , m_start_user_data(NULL) , m_stop_user_data(NULL) , m_interval_changed_user_data(NULL) +, m_attribute_str_user_data(NULL) { } @@ -65,6 +67,19 @@ void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg) if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_interval_changed_cb) m_interval_changed_cb(m_provider, buf.value, m_interval_changed_user_data); break; + case CMD_PROVIDER_ATTR_STR: + cmd_provider_attr_str_t *attr; + + attr = (cmd_provider_attr_str_t *) new(std::nothrow) char[msg.size()]; + retm_if(!attr, "Failed to allocate memory"); + + msg.disclose((char *)attr); + + if (m_attribute_str_cb) + m_attribute_str_cb(m_provider, attr->attribute, attr->value, attr->len, m_attribute_str_user_data); + + delete [] attr; + break; } } @@ -93,3 +108,9 @@ void sensor_provider::channel_handler::set_interval_cb(sensord_provider_interval m_interval_changed_cb = cb; m_interval_changed_user_data = user_data; } + +void sensor_provider::channel_handler::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data) +{ + m_attribute_str_cb = cb; + m_attribute_str_user_data = user_data; +} diff --git a/src/client/sensor_provider_channel_handler.h b/src/client/sensor_provider_channel_handler.h index 877f9db..89a0e36 100644 --- a/src/client/sensor_provider_channel_handler.h +++ b/src/client/sensor_provider_channel_handler.h @@ -41,6 +41,7 @@ public: void set_start_cb(sensord_provider_start_cb cb, void *user_data); void set_stop_cb(sensord_provider_stop_cb cb, void *user_data); void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data); + void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data); private: sensor_provider *m_provider; @@ -48,10 +49,12 @@ private: sensord_provider_start_cb m_start_cb; sensord_provider_stop_cb m_stop_cb; sensord_provider_interval_changed_cb m_interval_changed_cb; + sensord_provider_attribute_str_cb m_attribute_str_cb; void *m_start_user_data; void *m_stop_user_data; void *m_interval_changed_user_data; + void *m_attribute_str_user_data; }; } diff --git a/src/client/sensor_reader.cpp b/src/client/sensor_reader.cpp new file mode 100644 index 0000000..cdbad28 --- /dev/null +++ b/src/client/sensor_reader.cpp @@ -0,0 +1,88 @@ +/* + * sensord + * + * Copyright (c) 2018 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 "sensor_reader.h" + +#include +#include +#include + +using namespace sensor; + +sensor_reader::sensor_reader() +: m_reader(NULL) +, m_event_loop(NULL) +, m_mutex() +, m_cond() +, m_loop(NULL) +, m_running(false) +{ + m_event_loop = new(std::nothrow) ipc::event_loop(); + m_reader = new(std::nothrow) std::thread(&sensor::sensor_reader::read_event, this); + m_reader->detach(); + + if (!m_running) + wait_for_preparation(); + + _I("Created"); +} + +sensor_reader::~sensor_reader() +{ + _I("Destroying.."); + retm_if(!m_reader, "Invalid reader"); + + m_running = false; + + m_event_loop->stop(); + + delete m_reader; + m_reader = NULL; + + delete m_event_loop; + m_event_loop = NULL; + + _I("Destroyed"); +} + +ipc::event_loop *sensor_reader::get_event_loop(void) +{ + retvm_if(!m_event_loop, NULL, "Invalid context"); + + return m_event_loop; +} + +void sensor_reader::wait_for_preparation(void) +{ + std::unique_lock lock(m_mutex); + m_cond.wait_for(lock, std::chrono::seconds(1)); +} + +void sensor_reader::read_event(void) +{ + _I("RUN"); + m_loop = g_main_loop_new(g_main_context_new(), false); + m_event_loop->set_mainloop(m_loop); + + m_cond.notify_one(); + m_running = true; + + if (!m_event_loop->run()) + _E("Failed to run event loop"); +} diff --git a/src/client/sensor_reader.h b/src/client/sensor_reader.h new file mode 100644 index 0000000..010eb42 --- /dev/null +++ b/src/client/sensor_reader.h @@ -0,0 +1,53 @@ +/* + * sensord + * + * Copyright (c) 2018 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_READER_H__ +#define __SENSOR_READER_H__ + +#include +#include + +#include +#include +#include + +namespace sensor { + +class sensor_reader { +public: + sensor_reader(); + ~sensor_reader(); + + ipc::event_loop *get_event_loop(void); + +private: + void wait_for_preparation(void); + void read_event(void); + + std::thread *m_reader; + GMainLoop *m_loop; + ipc::event_loop *m_event_loop; + std::mutex m_mutex; + std::condition_variable m_cond; + std::atomic m_running; +}; + +} + +#endif /* __SENSOR_READER_H__ */ diff --git a/src/sensor/CMakeLists.txt b/src/fusion-sensor/CMakeLists.txt similarity index 90% rename from src/sensor/CMakeLists.txt rename to src/fusion-sensor/CMakeLists.txt index 388cb3a..4ac9942 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/fusion-sensor/CMakeLists.txt @@ -65,7 +65,12 @@ FILE(GLOB_RECURSE SRCS ${SRCS} pedometer/*.cpp) ADD_DEFINITIONS(-DENABLE_PEDOMETER) ENDIF() +IF("${GESTURE}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} gesture/*.cpp) +ADD_DEFINITIONS(-DENABLE_GESTURE) +ENDIF() + MESSAGE("Sources: ${SRCS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/fusion) diff --git a/src/sensor/auto_rotation/auto_rotation_alg.cpp b/src/fusion-sensor/auto_rotation/auto_rotation_alg.cpp similarity index 100% rename from src/sensor/auto_rotation/auto_rotation_alg.cpp rename to src/fusion-sensor/auto_rotation/auto_rotation_alg.cpp diff --git a/src/sensor/auto_rotation/auto_rotation_alg.h b/src/fusion-sensor/auto_rotation/auto_rotation_alg.h similarity index 100% rename from src/sensor/auto_rotation/auto_rotation_alg.h rename to src/fusion-sensor/auto_rotation/auto_rotation_alg.h diff --git a/src/sensor/auto_rotation/auto_rotation_alg_emul.cpp b/src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.cpp similarity index 100% rename from src/sensor/auto_rotation/auto_rotation_alg_emul.cpp rename to src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.cpp diff --git a/src/sensor/auto_rotation/auto_rotation_alg_emul.h b/src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.h similarity index 100% rename from src/sensor/auto_rotation/auto_rotation_alg_emul.h rename to src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.h diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/fusion-sensor/auto_rotation/auto_rotation_sensor.cpp similarity index 98% rename from src/sensor/auto_rotation/auto_rotation_sensor.cpp rename to src/fusion-sensor/auto_rotation/auto_rotation_sensor.cpp index 7fb6587..d9687c9 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/fusion-sensor/auto_rotation/auto_rotation_sensor.cpp @@ -72,7 +72,11 @@ bool auto_rotation_sensor::init(void) void auto_rotation_sensor::deinit(void) { + if (!m_alg) + return; + delete m_alg; + m_alg = NULL; } int auto_rotation_sensor::get_sensor_info(const sensor_info2_t **info) @@ -121,7 +125,7 @@ int auto_rotation_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return 1; + return 0; } int auto_rotation_sensor::start(observer_h ob) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.h b/src/fusion-sensor/auto_rotation/auto_rotation_sensor.h similarity index 100% rename from src/sensor/auto_rotation/auto_rotation_sensor.h rename to src/fusion-sensor/auto_rotation/auto_rotation_sensor.h diff --git a/src/sensor/create.cpp b/src/fusion-sensor/create.cpp similarity index 89% rename from src/sensor/create.cpp rename to src/fusion-sensor/create.cpp index 3c9b372..241a4cd 100644 --- a/src/sensor/create.cpp +++ b/src/fusion-sensor/create.cpp @@ -40,6 +40,10 @@ #ifdef ENABLE_PEDOMETER #include "pedometer/pedometer_sensor.h" #endif +#ifdef ENABLE_GESTURE +#include "gesture/face_down_sensor.h" +#include "gesture/pick_up_sensor.h" +#endif static std::vector sensors; @@ -63,7 +67,7 @@ void create_sensor(const char *name) extern "C" int create(fusion_sensor_t **fsensors) { #ifdef ENABLE_AUTO_ROTATION - create_sensor("Accelerometer"); + create_sensor("Auto Rotation Sensor"); #endif #ifdef ENABLE_GRAVITY @@ -89,6 +93,10 @@ extern "C" int create(fusion_sensor_t **fsensors) create_sensor("Pedometer"); #endif +#ifdef ENABLE_GESTURE + create_sensor("Face Down Sensor"); + create_sensor("Pick Up Sensor"); +#endif *fsensors = &sensors[0]; return sensors.size(); } diff --git a/src/sensor/fusion_util.cpp b/src/fusion-sensor/fusion_util.cpp similarity index 100% rename from src/sensor/fusion_util.cpp rename to src/fusion-sensor/fusion_util.cpp diff --git a/src/sensor/fusion_util.h b/src/fusion-sensor/fusion_util.h similarity index 100% rename from src/sensor/fusion_util.h rename to src/fusion-sensor/fusion_util.h diff --git a/src/sensor/gesture/face_down_alg.h b/src/fusion-sensor/gesture/face_down_alg.h similarity index 90% rename from src/sensor/gesture/face_down_alg.h rename to src/fusion-sensor/gesture/face_down_alg.h index 16ab460..5c981b9 100644 --- a/src/sensor/gesture/face_down_alg.h +++ b/src/fusion-sensor/gesture/face_down_alg.h @@ -20,12 +20,12 @@ #ifndef __FACE_DOWN_ALG_H__ #define __FACE_DOWN_ALG_H__ -#include +#include class face_down_alg { public: virtual ~face_down_alg() {}; - virtual void push_event(const sensor_event_t & event) = 0; + virtual void update(sensor_data_t *data) = 0; virtual bool get_face_down(void) = 0; }; diff --git a/src/sensor/gesture/face_down_alg_impl.cpp b/src/fusion-sensor/gesture/face_down_alg_impl.cpp similarity index 80% rename from src/sensor/gesture/face_down_alg_impl.cpp rename to src/fusion-sensor/gesture/face_down_alg_impl.cpp index 611d539..e51a73a 100644 --- a/src/sensor/gesture/face_down_alg_impl.cpp +++ b/src/fusion-sensor/gesture/face_down_alg_impl.cpp @@ -16,10 +16,11 @@ * limitations under the License. * */ +#include "face_down_alg_impl.h" + +#include #include #include -#include -#include #define GRAVITY 9.80665 #define TWENTY_DEGREES 0.349066 @@ -37,17 +38,16 @@ face_down_alg_impl::~face_down_alg_impl() { } -void face_down_alg_impl::push_event(const sensor_event_t & event) +void face_down_alg_impl::update(sensor_data_t *data) { - //_I("face_down_alg: %llu acc[2]: %f",event.data->timestamp,event.data->values[2]); - m_current_time = event.data->timestamp; + m_current_time = data->timestamp; remove_old_up_time(); - if (event.data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES))) - m_latest_down_time = event.data->timestamp; + if (data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES))) + m_latest_down_time = data->timestamp; - if (event.data->values[2] > (GRAVITY * cos(TWENTY_DEGREES))) - m_oldest_up_time.push(event.data->timestamp); + if (data->values[2] > (GRAVITY * cos(TWENTY_DEGREES))) + m_oldest_up_time.push(data->timestamp); } void face_down_alg_impl::remove_old_up_time(void) @@ -76,6 +76,7 @@ unsigned long long face_down_alg_impl::is_facing_down(void) { if (m_current_time - m_latest_down_time < WINDOW_SIZE) return m_latest_down_time; + return 0; } diff --git a/src/sensor/gesture/face_down_alg_impl.h b/src/fusion-sensor/gesture/face_down_alg_impl.h similarity index 86% rename from src/sensor/gesture/face_down_alg_impl.h rename to src/fusion-sensor/gesture/face_down_alg_impl.h index 997719d..ff65ee7 100644 --- a/src/sensor/gesture/face_down_alg_impl.h +++ b/src/fusion-sensor/gesture/face_down_alg_impl.h @@ -20,24 +20,26 @@ #ifndef __FACE_DOWN_ALG_IMPL_H__ #define __FACE_DOWN_ALG_IMPL_H__ -#include -#include #include +#include "face_down_alg.h" + class face_down_alg_impl : public virtual face_down_alg { public: face_down_alg_impl(); ~face_down_alg_impl(); - void push_event(const sensor_event_t & event); + void update(sensor_data_t *data); bool get_face_down(void); + private: + void remove_old_up_time(void); + unsigned long long is_facing_down(void); + unsigned long long was_facing_up(void); + unsigned long long m_current_time; unsigned long long m_last_event_time; unsigned long long m_latest_down_time; std::queue m_oldest_up_time; - void remove_old_up_time(void); - unsigned long long is_facing_down(); - unsigned long long was_facing_up(); }; #endif /* __FACE_DOWN_ALG_IMPL_H__ */ diff --git a/src/fusion-sensor/gesture/face_down_sensor.cpp b/src/fusion-sensor/gesture/face_down_sensor.cpp new file mode 100644 index 0000000..b3874c1 --- /dev/null +++ b/src/fusion-sensor/gesture/face_down_sensor.cpp @@ -0,0 +1,131 @@ +/* + * 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 "face_down_sensor.h" + +#include +#include + +#include "face_down_alg_impl.h" + +#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_face_down/tizen_default" +#define NAME_VENDOR "tizen.org" + +#define SRC_ID_GRAVITY 0x1 +#define SRC_URI_GRAVITY "http://tizen.org/sensor/general/gravity" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GESTURE_FACE_DOWN_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 50, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_GRAVITY, SRC_URI_GRAVITY} +}; + +face_down_sensor::face_down_sensor() +: m_state(0) +, m_timestamp(0) +, m_alg(NULL) +{ + if (!init()) + throw OP_ERROR; +} + +face_down_sensor::~face_down_sensor() +{ + deinit(); +} + +bool face_down_sensor::init(void) +{ + m_alg = get_alg(); + retvm_if(!m_alg, false, "Not supported"); + return true; +} + +void face_down_sensor::deinit(void) +{ + if (!m_alg) + return; + + delete m_alg; + m_alg = NULL; +} + +int face_down_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int face_down_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 1; +} + +int face_down_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + int state; + + m_alg->update(data); + + state = m_alg->get_face_down(); + retv_if(!state, OP_ERROR); + + m_state = state; + m_timestamp = data->timestamp; + + return OP_SUCCESS; +} + +int face_down_sensor::get_data(sensor_data_t ** data, int *length) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); + + sensor_data->accuracy = SENSOR_ACCURACY_GOOD; + sensor_data->timestamp = m_timestamp; + sensor_data->values[0] = m_state; + sensor_data->value_count = 1; + + *data = sensor_data; + *length = sizeof(sensor_data_t); + + return 0; +} + +face_down_alg_impl *face_down_sensor::get_alg(void) +{ + face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl(); + retvm_if(!alg, NULL, "Failed to allocate memory"); + + return alg; +} diff --git a/src/fusion-sensor/gesture/face_down_sensor.h b/src/fusion-sensor/gesture/face_down_sensor.h new file mode 100644 index 0000000..56f1b3f --- /dev/null +++ b/src/fusion-sensor/gesture/face_down_sensor.h @@ -0,0 +1,51 @@ +/* + * 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 __FACE_DOWN_SENSOR_H__ +#define __FACE_DOWN_SENSOR_H__ + +#include +#include + +#include "face_down_alg_impl.h" + +class face_down_sensor : public fusion_sensor { +public: + face_down_sensor(); + virtual ~face_down_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + bool init(void); + void deinit(void); + + face_down_alg_impl *get_alg(void); + + int m_state; + unsigned long long m_timestamp; + + face_down_alg_impl *m_alg; +}; + +#endif /* __FACE_DOWN_SENSOR_H__ */ diff --git a/src/fusion-sensor/gesture/pick_up_sensor.cpp b/src/fusion-sensor/gesture/pick_up_sensor.cpp new file mode 100644 index 0000000..11f51f6 --- /dev/null +++ b/src/fusion-sensor/gesture/pick_up_sensor.cpp @@ -0,0 +1,98 @@ +/* + * sensord + * + * Copyright (c) 2017 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 "pick_up_sensor.h" + +#include +#include + +#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_pick_up/tizen_default" +#define NAME_VENDOR "tizen.org" + +#define SRC_ID_MOVE 0x1 +#define SRC_URI_MOVE "http://tizen.org/sensor/general/gesture_movement/SENSOR_GESTURE_MOVEMENT" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GESTURE_PICK_UP_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 0, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_MOVE, SRC_URI_MOVE} +}; + +pick_up_sensor::pick_up_sensor() +: m_state(0) +, m_timestamp(0) +{ +} + +pick_up_sensor::~pick_up_sensor() +{ +} + +int pick_up_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int pick_up_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 1; +} + +int pick_up_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + int state = data->values[0]; + + _D("State : %d", state); + + m_state = state; + m_timestamp = data->timestamp; + + return OP_SUCCESS; +} + +int pick_up_sensor::get_data(sensor_data_t **data, int *length) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); + + sensor_data->accuracy = SENSOR_ACCURACY_GOOD; + sensor_data->timestamp = m_timestamp; + sensor_data->values[0] = m_state; + sensor_data->value_count = 1; + + *data = sensor_data; + *length = sizeof(sensor_data_t); + + return 0; +} diff --git a/src/fusion-sensor/gesture/pick_up_sensor.h b/src/fusion-sensor/gesture/pick_up_sensor.h new file mode 100644 index 0000000..0b43983 --- /dev/null +++ b/src/fusion-sensor/gesture/pick_up_sensor.h @@ -0,0 +1,42 @@ +/* + * sensord + * + * Copyright (c) 2017 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 __PICK_UP_SENSOR_H__ +#define __PICK_UP_SENSOR_H__ + +#include +#include + +class pick_up_sensor : public fusion_sensor { +public: + pick_up_sensor(); + virtual ~pick_up_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + int m_state; + unsigned long long m_timestamp; +}; + +#endif /* __PICK_UP_SENSOR_H__ */ diff --git a/src/sensor/gravity/gravity_comp_sensor.cpp b/src/fusion-sensor/gravity/gravity_comp_sensor.cpp similarity index 100% rename from src/sensor/gravity/gravity_comp_sensor.cpp rename to src/fusion-sensor/gravity/gravity_comp_sensor.cpp diff --git a/src/sensor/gravity/gravity_comp_sensor.h b/src/fusion-sensor/gravity/gravity_comp_sensor.h similarity index 100% rename from src/sensor/gravity/gravity_comp_sensor.h rename to src/fusion-sensor/gravity/gravity_comp_sensor.h diff --git a/src/sensor/gravity/gravity_lowpass_sensor.cpp b/src/fusion-sensor/gravity/gravity_lowpass_sensor.cpp similarity index 100% rename from src/sensor/gravity/gravity_lowpass_sensor.cpp rename to src/fusion-sensor/gravity/gravity_lowpass_sensor.cpp diff --git a/src/sensor/gravity/gravity_lowpass_sensor.h b/src/fusion-sensor/gravity/gravity_lowpass_sensor.h similarity index 100% rename from src/sensor/gravity/gravity_lowpass_sensor.h rename to src/fusion-sensor/gravity/gravity_lowpass_sensor.h diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/fusion-sensor/linear_accel/linear_accel_sensor.cpp similarity index 100% rename from src/sensor/linear_accel/linear_accel_sensor.cpp rename to src/fusion-sensor/linear_accel/linear_accel_sensor.cpp diff --git a/src/sensor/linear_accel/linear_accel_sensor.h b/src/fusion-sensor/linear_accel/linear_accel_sensor.h similarity index 100% rename from src/sensor/linear_accel/linear_accel_sensor.h rename to src/fusion-sensor/linear_accel/linear_accel_sensor.h diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/fusion-sensor/orientation/orientation_sensor.cpp similarity index 99% rename from src/sensor/orientation/orientation_sensor.cpp rename to src/fusion-sensor/orientation/orientation_sensor.cpp index 7cec3f2..8dd1036 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/fusion-sensor/orientation/orientation_sensor.cpp @@ -108,5 +108,5 @@ int orientation_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return 1; + return 0; } diff --git a/src/sensor/orientation/orientation_sensor.h b/src/fusion-sensor/orientation/orientation_sensor.h similarity index 100% rename from src/sensor/orientation/orientation_sensor.h rename to src/fusion-sensor/orientation/orientation_sensor.h diff --git a/src/sensor/pedometer/average_filter.cpp b/src/fusion-sensor/pedometer/average_filter.cpp similarity index 100% rename from src/sensor/pedometer/average_filter.cpp rename to src/fusion-sensor/pedometer/average_filter.cpp diff --git a/src/sensor/pedometer/average_filter.h b/src/fusion-sensor/pedometer/average_filter.h similarity index 100% rename from src/sensor/pedometer/average_filter.h rename to src/fusion-sensor/pedometer/average_filter.h diff --git a/src/sensor/pedometer/pedometer.cpp b/src/fusion-sensor/pedometer/pedometer.cpp similarity index 100% rename from src/sensor/pedometer/pedometer.cpp rename to src/fusion-sensor/pedometer/pedometer.cpp diff --git a/src/sensor/pedometer/pedometer.h b/src/fusion-sensor/pedometer/pedometer.h similarity index 100% rename from src/sensor/pedometer/pedometer.h rename to src/fusion-sensor/pedometer/pedometer.h diff --git a/src/sensor/pedometer/pedometer_info.h b/src/fusion-sensor/pedometer/pedometer_info.h similarity index 100% rename from src/sensor/pedometer/pedometer_info.h rename to src/fusion-sensor/pedometer/pedometer_info.h diff --git a/src/sensor/pedometer/pedometer_sensor.cpp b/src/fusion-sensor/pedometer/pedometer_sensor.cpp similarity index 100% rename from src/sensor/pedometer/pedometer_sensor.cpp rename to src/fusion-sensor/pedometer/pedometer_sensor.cpp diff --git a/src/sensor/pedometer/pedometer_sensor.h b/src/fusion-sensor/pedometer/pedometer_sensor.h similarity index 100% rename from src/sensor/pedometer/pedometer_sensor.h rename to src/fusion-sensor/pedometer/pedometer_sensor.h diff --git a/src/sensor/pedometer/pedometer_speed_filter.cpp b/src/fusion-sensor/pedometer/pedometer_speed_filter.cpp similarity index 100% rename from src/sensor/pedometer/pedometer_speed_filter.cpp rename to src/fusion-sensor/pedometer/pedometer_speed_filter.cpp diff --git a/src/sensor/pedometer/pedometer_speed_filter.h b/src/fusion-sensor/pedometer/pedometer_speed_filter.h similarity index 100% rename from src/sensor/pedometer/pedometer_speed_filter.h rename to src/fusion-sensor/pedometer/pedometer_speed_filter.h diff --git a/src/sensor/pedometer/savitzky_golay_filter15.cpp b/src/fusion-sensor/pedometer/savitzky_golay_filter15.cpp similarity index 100% rename from src/sensor/pedometer/savitzky_golay_filter15.cpp rename to src/fusion-sensor/pedometer/savitzky_golay_filter15.cpp diff --git a/src/sensor/pedometer/savitzky_golay_filter15.h b/src/fusion-sensor/pedometer/savitzky_golay_filter15.h similarity index 100% rename from src/sensor/pedometer/savitzky_golay_filter15.h rename to src/fusion-sensor/pedometer/savitzky_golay_filter15.h diff --git a/src/sensor/pedometer/sensor_frequency_compensator.cpp b/src/fusion-sensor/pedometer/sensor_frequency_compensator.cpp similarity index 100% rename from src/sensor/pedometer/sensor_frequency_compensator.cpp rename to src/fusion-sensor/pedometer/sensor_frequency_compensator.cpp diff --git a/src/sensor/pedometer/sensor_frequency_compensator.h b/src/fusion-sensor/pedometer/sensor_frequency_compensator.h similarity index 100% rename from src/sensor/pedometer/sensor_frequency_compensator.h rename to src/fusion-sensor/pedometer/sensor_frequency_compensator.h diff --git a/src/sensor/pedometer/step_detection.cpp b/src/fusion-sensor/pedometer/step_detection.cpp similarity index 100% rename from src/sensor/pedometer/step_detection.cpp rename to src/fusion-sensor/pedometer/step_detection.cpp diff --git a/src/sensor/pedometer/step_detection.h b/src/fusion-sensor/pedometer/step_detection.h similarity index 100% rename from src/sensor/pedometer/step_detection.h rename to src/fusion-sensor/pedometer/step_detection.h diff --git a/src/sensor/pedometer/step_event.h b/src/fusion-sensor/pedometer/step_event.h similarity index 100% rename from src/sensor/pedometer/step_event.h rename to src/fusion-sensor/pedometer/step_event.h diff --git a/src/sensor/pedometer/timestamp.h b/src/fusion-sensor/pedometer/timestamp.h similarity index 100% rename from src/sensor/pedometer/timestamp.h rename to src/fusion-sensor/pedometer/timestamp.h diff --git a/src/sensor/pedometer/zero_crossing_step_detection.cpp b/src/fusion-sensor/pedometer/zero_crossing_step_detection.cpp similarity index 100% rename from src/sensor/pedometer/zero_crossing_step_detection.cpp rename to src/fusion-sensor/pedometer/zero_crossing_step_detection.cpp diff --git a/src/sensor/pedometer/zero_crossing_step_detection.h b/src/fusion-sensor/pedometer/zero_crossing_step_detection.h similarity index 100% rename from src/sensor/pedometer/zero_crossing_step_detection.h rename to src/fusion-sensor/pedometer/zero_crossing_step_detection.h diff --git a/src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt diff --git a/src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt b/src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt similarity index 100% rename from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt rename to src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro diff --git a/src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic b/src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic similarity index 100% rename from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic rename to src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic diff --git a/src/sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png diff --git a/src/sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png diff --git a/src/sensor/rotation_vector/design/documentation/diagram/device_orientation.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/device_orientation.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/device_orientation.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/device_orientation.png diff --git a/src/sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png diff --git a/src/sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png diff --git a/src/sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png b/src/fusion-sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png rename to src/fusion-sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_1.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_1.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_1.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_1.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_10.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_10.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_10.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_10.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_11.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_11.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_11.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_11.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_12.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_12.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_12.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_12.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_13.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_13.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_13_updated.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13_updated.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_13_updated.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13_updated.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_14.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_14.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_14.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_14.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_15.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_15.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_15.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_15.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_16.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_16.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_16.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_16.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_17.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_17.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_17.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_17.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_18.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_18.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_18.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_18.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_19.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_19.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_19.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_19.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_2.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_2.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_2.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_2.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_20.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_20.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_20.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_20.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_21.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_21.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_21.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_21.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_22.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_22.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_22.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_22.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_23.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_23.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_23.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_23.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_24.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_24.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_24.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_24.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_25.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_25.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_25.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_25.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_26.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_26.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_26.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_26.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_27.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_27.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_27.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_27.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_28.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_28.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_28.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_28.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_29.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_29.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_29.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_29.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_3.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_3.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_3.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_3.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_30.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_30.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_30.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_30.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_31.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_31.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_31.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_31.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_32.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_32.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_32.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_32.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_33.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_33.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_33.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_33.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_34.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_34.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_34.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_34.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_35.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_35.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_35.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_35.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_36.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_36.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_36.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_36.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_37.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_37.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_37.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_37.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_38.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_38.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_38.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_38.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_39.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_39.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_39.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_39.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_4.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_4.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_4.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_4.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_40.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_40.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_40.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_40.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_5.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_5.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_5.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_5.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_6.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_6.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_6.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_6.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_7.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_7.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_7.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_7.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_8.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_8.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_8.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_8.png diff --git a/src/sensor/rotation_vector/design/documentation/equation/equation_9.png b/src/fusion-sensor/rotation_vector/design/documentation/equation/equation_9.png similarity index 100% rename from src/sensor/rotation_vector/design/documentation/equation/equation_9.png rename to src/fusion-sensor/rotation_vector/design/documentation/equation/equation_9.png diff --git a/src/sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html b/src/fusion-sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html similarity index 100% rename from src/sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html rename to src/fusion-sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html diff --git a/src/sensor/rotation_vector/design/documentation/sensor_fusion.htm b/src/fusion-sensor/rotation_vector/design/documentation/sensor_fusion.htm similarity index 100% rename from src/sensor/rotation_vector/design/documentation/sensor_fusion.htm rename to src/fusion-sensor/rotation_vector/design/documentation/sensor_fusion.htm diff --git a/src/sensor/rotation_vector/design/lib/axis_rot2quat.m b/src/fusion-sensor/rotation_vector/design/lib/axis_rot2quat.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/axis_rot2quat.m rename to src/fusion-sensor/rotation_vector/design/lib/axis_rot2quat.m diff --git a/src/sensor/rotation_vector/design/lib/estimate_gaming_rv.m b/src/fusion-sensor/rotation_vector/design/lib/estimate_gaming_rv.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/estimate_gaming_rv.m rename to src/fusion-sensor/rotation_vector/design/lib/estimate_gaming_rv.m diff --git a/src/sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m b/src/fusion-sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m rename to src/fusion-sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m diff --git a/src/sensor/rotation_vector/design/lib/estimate_gravity.m b/src/fusion-sensor/rotation_vector/design/lib/estimate_gravity.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/estimate_gravity.m rename to src/fusion-sensor/rotation_vector/design/lib/estimate_gravity.m diff --git a/src/sensor/rotation_vector/design/lib/estimate_linear_acceleration.m b/src/fusion-sensor/rotation_vector/design/lib/estimate_linear_acceleration.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/estimate_linear_acceleration.m rename to src/fusion-sensor/rotation_vector/design/lib/estimate_linear_acceleration.m diff --git a/src/sensor/rotation_vector/design/lib/estimate_orientation.m b/src/fusion-sensor/rotation_vector/design/lib/estimate_orientation.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/estimate_orientation.m rename to src/fusion-sensor/rotation_vector/design/lib/estimate_orientation.m diff --git a/src/sensor/rotation_vector/design/lib/euler2quat.m b/src/fusion-sensor/rotation_vector/design/lib/euler2quat.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/euler2quat.m rename to src/fusion-sensor/rotation_vector/design/lib/euler2quat.m diff --git a/src/sensor/rotation_vector/design/lib/quat2euler.m b/src/fusion-sensor/rotation_vector/design/lib/quat2euler.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/quat2euler.m rename to src/fusion-sensor/rotation_vector/design/lib/quat2euler.m diff --git a/src/sensor/rotation_vector/design/lib/quat2rot_mat.m b/src/fusion-sensor/rotation_vector/design/lib/quat2rot_mat.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/quat2rot_mat.m rename to src/fusion-sensor/rotation_vector/design/lib/quat2rot_mat.m diff --git a/src/sensor/rotation_vector/design/lib/quat_prod.m b/src/fusion-sensor/rotation_vector/design/lib/quat_prod.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/quat_prod.m rename to src/fusion-sensor/rotation_vector/design/lib/quat_prod.m diff --git a/src/sensor/rotation_vector/design/lib/rot_mat2quat.m b/src/fusion-sensor/rotation_vector/design/lib/rot_mat2quat.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/rot_mat2quat.m rename to src/fusion-sensor/rotation_vector/design/lib/rot_mat2quat.m diff --git a/src/sensor/rotation_vector/design/lib/sf_pedometer.m b/src/fusion-sensor/rotation_vector/design/lib/sf_pedometer.m similarity index 100% rename from src/sensor/rotation_vector/design/lib/sf_pedometer.m rename to src/fusion-sensor/rotation_vector/design/lib/sf_pedometer.m diff --git a/src/sensor/rotation_vector/design/readme b/src/fusion-sensor/rotation_vector/design/readme similarity index 100% rename from src/sensor/rotation_vector/design/readme rename to src/fusion-sensor/rotation_vector/design/readme diff --git a/src/sensor/rotation_vector/design/sf_gaming_rv.m b/src/fusion-sensor/rotation_vector/design/sf_gaming_rv.m similarity index 100% rename from src/sensor/rotation_vector/design/sf_gaming_rv.m rename to src/fusion-sensor/rotation_vector/design/sf_gaming_rv.m diff --git a/src/sensor/rotation_vector/design/sf_geomagnetic_rv.m b/src/fusion-sensor/rotation_vector/design/sf_geomagnetic_rv.m similarity index 100% rename from src/sensor/rotation_vector/design/sf_geomagnetic_rv.m rename to src/fusion-sensor/rotation_vector/design/sf_geomagnetic_rv.m diff --git a/src/sensor/rotation_vector/design/sf_gravity.m b/src/fusion-sensor/rotation_vector/design/sf_gravity.m similarity index 100% rename from src/sensor/rotation_vector/design/sf_gravity.m rename to src/fusion-sensor/rotation_vector/design/sf_gravity.m diff --git a/src/sensor/rotation_vector/design/sf_linear_acceleration.m b/src/fusion-sensor/rotation_vector/design/sf_linear_acceleration.m similarity index 100% rename from src/sensor/rotation_vector/design/sf_linear_acceleration.m rename to src/fusion-sensor/rotation_vector/design/sf_linear_acceleration.m diff --git a/src/sensor/rotation_vector/design/sf_orientation.m b/src/fusion-sensor/rotation_vector/design/sf_orientation.m similarity index 100% rename from src/sensor/rotation_vector/design/sf_orientation.m rename to src/fusion-sensor/rotation_vector/design/sf_orientation.m diff --git a/src/sensor/rotation_vector/fusion.h b/src/fusion-sensor/rotation_vector/fusion.h similarity index 100% rename from src/sensor/rotation_vector/fusion.h rename to src/fusion-sensor/rotation_vector/fusion.h diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/fusion-sensor/rotation_vector/fusion_base.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_base.cpp rename to src/fusion-sensor/rotation_vector/fusion_base.cpp diff --git a/src/sensor/rotation_vector/fusion_base.h b/src/fusion-sensor/rotation_vector/fusion_base.h similarity index 100% rename from src/sensor/rotation_vector/fusion_base.h rename to src/fusion-sensor/rotation_vector/fusion_base.h diff --git a/src/sensor/rotation_vector/fusion_utils/euler_angles.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/euler_angles.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/euler_angles.h b/src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/euler_angles.h rename to src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.h diff --git a/src/sensor/rotation_vector/fusion_utils/matrix.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/matrix.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/matrix.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/matrix.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/matrix.h b/src/fusion-sensor/rotation_vector/fusion_utils/matrix.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/matrix.h rename to src/fusion-sensor/rotation_vector/fusion_utils/matrix.h diff --git a/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.cpp similarity index 99% rename from src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.cpp index 2b03cf0..43ea867 100644 --- a/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp +++ b/src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.cpp @@ -65,7 +65,6 @@ orientation_filter::orientation_filter() m_var_azimuth = vec; m_gyro.m_time_stamp = 0; - m_gyro_dt = 0; } template diff --git a/src/sensor/rotation_vector/fusion_utils/orientation_filter.h b/src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/orientation_filter.h rename to src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.h diff --git a/src/sensor/rotation_vector/fusion_utils/quaternion.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/quaternion.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/quaternion.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/quaternion.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/quaternion.h b/src/fusion-sensor/rotation_vector/fusion_utils/quaternion.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/quaternion.h rename to src/fusion-sensor/rotation_vector/fusion_utils/quaternion.h diff --git a/src/sensor/rotation_vector/fusion_utils/rotation_matrix.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/rotation_matrix.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/rotation_matrix.h b/src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/rotation_matrix.h rename to src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.h diff --git a/src/sensor/rotation_vector/fusion_utils/sensor_data.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/sensor_data.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/sensor_data.h b/src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/sensor_data.h rename to src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.h diff --git a/src/sensor/rotation_vector/fusion_utils/vector.cpp b/src/fusion-sensor/rotation_vector/fusion_utils/vector.cpp similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/vector.cpp rename to src/fusion-sensor/rotation_vector/fusion_utils/vector.cpp diff --git a/src/sensor/rotation_vector/fusion_utils/vector.h b/src/fusion-sensor/rotation_vector/fusion_utils/vector.h similarity index 100% rename from src/sensor/rotation_vector/fusion_utils/vector.h rename to src/fusion-sensor/rotation_vector/fusion_utils/vector.h diff --git a/src/sensor/rotation_vector/gyro_fusion.cpp b/src/fusion-sensor/rotation_vector/gyro_fusion.cpp similarity index 100% rename from src/sensor/rotation_vector/gyro_fusion.cpp rename to src/fusion-sensor/rotation_vector/gyro_fusion.cpp diff --git a/src/sensor/rotation_vector/gyro_fusion.h b/src/fusion-sensor/rotation_vector/gyro_fusion.h similarity index 100% rename from src/sensor/rotation_vector/gyro_fusion.h rename to src/fusion-sensor/rotation_vector/gyro_fusion.h diff --git a/src/sensor/rotation_vector/gyro_magnetic_fusion.cpp b/src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.cpp similarity index 100% rename from src/sensor/rotation_vector/gyro_magnetic_fusion.cpp rename to src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.cpp diff --git a/src/sensor/rotation_vector/gyro_magnetic_fusion.h b/src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.h similarity index 100% rename from src/sensor/rotation_vector/gyro_magnetic_fusion.h rename to src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.h diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/fusion-sensor/rotation_vector/gyro_rv_sensor.cpp similarity index 100% rename from src/sensor/rotation_vector/gyro_rv_sensor.cpp rename to src/fusion-sensor/rotation_vector/gyro_rv_sensor.cpp diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.h b/src/fusion-sensor/rotation_vector/gyro_rv_sensor.h similarity index 100% rename from src/sensor/rotation_vector/gyro_rv_sensor.h rename to src/fusion-sensor/rotation_vector/gyro_rv_sensor.h diff --git a/src/sensor/rotation_vector/magnetic_fusion.cpp b/src/fusion-sensor/rotation_vector/magnetic_fusion.cpp similarity index 100% rename from src/sensor/rotation_vector/magnetic_fusion.cpp rename to src/fusion-sensor/rotation_vector/magnetic_fusion.cpp diff --git a/src/sensor/rotation_vector/magnetic_fusion.h b/src/fusion-sensor/rotation_vector/magnetic_fusion.h similarity index 100% rename from src/sensor/rotation_vector/magnetic_fusion.h rename to src/fusion-sensor/rotation_vector/magnetic_fusion.h diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/fusion-sensor/rotation_vector/magnetic_rv_sensor.cpp similarity index 100% rename from src/sensor/rotation_vector/magnetic_rv_sensor.cpp rename to src/fusion-sensor/rotation_vector/magnetic_rv_sensor.cpp diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.h b/src/fusion-sensor/rotation_vector/magnetic_rv_sensor.h similarity index 100% rename from src/sensor/rotation_vector/magnetic_rv_sensor.h rename to src/fusion-sensor/rotation_vector/magnetic_rv_sensor.h diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/fusion-sensor/rotation_vector/rv_sensor.cpp similarity index 100% rename from src/sensor/rotation_vector/rv_sensor.cpp rename to src/fusion-sensor/rotation_vector/rv_sensor.cpp diff --git a/src/sensor/rotation_vector/rv_sensor.h b/src/fusion-sensor/rotation_vector/rv_sensor.h similarity index 100% rename from src/sensor/rotation_vector/rv_sensor.h rename to src/fusion-sensor/rotation_vector/rv_sensor.h diff --git a/src/sensor/tilt/tilt_sensor.cpp b/src/fusion-sensor/tilt/tilt_sensor.cpp similarity index 100% rename from src/sensor/tilt/tilt_sensor.cpp rename to src/fusion-sensor/tilt/tilt_sensor.cpp diff --git a/src/sensor/tilt/tilt_sensor.h b/src/fusion-sensor/tilt/tilt_sensor.h similarity index 100% rename from src/sensor/tilt/tilt_sensor.h rename to src/fusion-sensor/tilt/tilt_sensor.h diff --git a/src/physical-sensor/CMakeLists.txt b/src/physical-sensor/CMakeLists.txt new file mode 100644 index 0000000..9ef4c4c --- /dev/null +++ b/src/physical-sensor/CMakeLists.txt @@ -0,0 +1,41 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensor-physical CXX) +INCLUDE(GNUInstallDirs) + +SET(ACCEL "OFF") + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/src/shared + ${CMAKE_CURRENT_SOURCE_DIR} +) + +# Common Options +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections") +MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}") +MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") + +# Internal Debugging Options +#ADD_DEFINITIONS(-Wall -g -D_DEBUG) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED dlog glib-2.0 vconf libtzplatform-config) + +FOREACH(flag ${PLUGINS_PKGS_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +FILE(GLOB SRCS *.cpp) + +IF("${ACCEL}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} accel/*.cpp) +ADD_DEFINITIONS(-DENABLE_ACCEL) +ENDIF() + +MESSAGE("Sources: ${SRCS}") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/physical) diff --git a/src/physical-sensor/accel/accel_sensor.cpp b/src/physical-sensor/accel/accel_sensor.cpp new file mode 100644 index 0000000..6178e6d --- /dev/null +++ b/src/physical-sensor/accel/accel_sensor.cpp @@ -0,0 +1,83 @@ +/* + * 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 "accel_sensor.h" +#include + +#define URI_ACCEL "http://tizen.org/sensor/general/accelerometer" + +accel_sensor::accel_sensor() +{ + _I("accel_sensor is created : %#x", this); +} + +accel_sensor::~accel_sensor() +{ + _I("accel_sensor is destroyed : %#x", this); +} + +std::string accel_sensor::get_uri(void) +{ + return URI_ACCEL; +} + +physical_sensor *accel_sensor::clone(void) const +{ + return new accel_sensor(*this); +} + +int accel_sensor::start(observer_h ob) +{ + return OP_DEFAULT; +} + +int accel_sensor::stop(observer_h ob) +{ + return OP_DEFAULT; +} + +int accel_sensor::set_interval(observer_h ob, uint32_t interval) +{ + return OP_DEFAULT; +} + +int accel_sensor::set_batch_latency(observer_h ob, uint32_t latency) +{ + return OP_DEFAULT; +} + +int accel_sensor::set_attribute(observer_h ob, int32_t attr, int32_t value) +{ + return OP_DEFAULT; +} + +int accel_sensor::set_attribute(observer_h ob, int32_t attr, const char *value, int len) +{ + return OP_DEFAULT; +} + +int accel_sensor::flush(observer_h ob) +{ + return OP_DEFAULT; +} + +int accel_sensor::on_event(sensor_data_t *data, int32_t len, int32_t remains) +{ + return OP_DEFAULT; +} diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/physical-sensor/accel/accel_sensor.h similarity index 51% rename from src/sensor/sensorhub/pedometer_sensor.h rename to src/physical-sensor/accel/accel_sensor.h index 16f1ac7..ea8b60f 100644 --- a/src/sensor/sensorhub/pedometer_sensor.h +++ b/src/physical-sensor/accel/accel_sensor.h @@ -17,31 +17,29 @@ * */ -#ifndef _PEDOMETER_SENSOR_H_ -#define _PEDOMETER_SENSOR_H_ +#ifndef __ACCEL_SENSOR_H__ +#define __ACCEL_SENSOR_H__ #include -class pedometer_sensor : public physical_sensor { +class accel_sensor : public physical_sensor { public: - pedometer_sensor(); - virtual ~pedometer_sensor(); - - bool on_event(const sensor_data_t *data, int data_len, int remains); - -private: - unsigned long long m_steps; - unsigned long long m_walk_steps; - unsigned long long m_run_steps; - unsigned long long m_walk_up_steps; - unsigned long long m_walk_down_steps; - unsigned long long m_run_up_steps; - unsigned long long m_run_down_steps; - double m_distance; - double m_calories; - - void accumulate(sensor_pedometer_data_t *data); + accel_sensor(); + ~accel_sensor(); + + std::string get_uri(void); + physical_sensor *clone(void) const; + + int start(observer_h ob); + int stop(observer_h ob); + + int set_interval(observer_h ob, uint32_t interval); + int set_batch_latency(observer_h ob, uint32_t latency); + int set_attribute(observer_h ob, int32_t attr, int32_t value); + int set_attribute(observer_h ob, int32_t attr, const char *value, int len); + int flush(observer_h ob); + int on_event(sensor_data_t *data, int32_t len, int32_t remains); }; -#endif /* _PEDOMETER_SENSOR_H_ */ +#endif /* __ACCEL_SENSOR_H__ */ diff --git a/src/physical-sensor/create.cpp b/src/physical-sensor/create.cpp new file mode 100644 index 0000000..dfaca85 --- /dev/null +++ b/src/physical-sensor/create.cpp @@ -0,0 +1,52 @@ +/* + * 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 + +#ifdef ENABLE_ACCEL +#include "accel/accel_sensor.h" +#endif + +static std::vector sensors; + +template +void create_sensor(const char *name) +{ + physical_sensor *instance = NULL; + try { + instance = new _sensor; + } catch (std::exception &e) { + _E("Failed to create %s sensor, exception: %s", name, e.what()); + return; + } catch (int err) { + _ERRNO(err, _E, "Failed to create %s sensor device", name); + return; + } + + sensors.push_back(instance); +} + +extern "C" int create(physical_sensor_t **fsensors) +{ +#ifdef ENABLE_ACCEL + create_sensor("Accelerometer"); +#endif + *fsensors = &sensors[0]; + return sensors.size(); +} diff --git a/src/physical-sensor/macro.h b/src/physical-sensor/macro.h new file mode 100644 index 0000000..0ec7bcf --- /dev/null +++ b/src/physical-sensor/macro.h @@ -0,0 +1,70 @@ +/* + * 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); +} + +static inline void int_to_bytes(int value, int width, char data[]) +{ + /* Big-endian */ + for (int i = width - 1; i >= 0; i--) { + data[i] = (value & 0xff); + value = value >> 8; + } +} + +static inline unsigned int bytes_to_uint(char data[], int &cursor, int width) +{ + unsigned int sum = 0; + + /* Big-endian */ + for (int i = 0; i < width; ++i) + sum = (sum << 8) + (unsigned char)data[cursor++]; + + return sum; +} + +#define _cleanup_free_ _cleanup_(__freep) +#define _cleanup_close_ _cleanup_(__closep) +#define _cleanup_fclose_ _cleanup_(__fclosep) +#define GET_BYTES(value, width, data) int_to_bytes(value, width, data) +#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/src/sensor/accel/accel_sensor.cpp b/src/sensor/accel/accel_sensor.cpp deleted file mode 100644 index 892ecb0..0000000 --- a/src/sensor/accel/accel_sensor.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 - -accel_sensor::accel_sensor() -{ - _I("accel_sensor is created : %#x", this); -} - -accel_sensor::~accel_sensor() -{ -} - -sensor_type_t accel_sensor::get_type(void) -{ - return ACCELEROMETER_SENSOR; -} diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp deleted file mode 100644 index 98c1ccb..0000000 --- a/src/sensor/gesture/face_down_sensor.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#define SENSOR_NAME "SENSOR_FACE_DOWN" - -#define SENSOR_FREQUENCY 50 - -face_down_sensor::face_down_sensor() -: m_gravity_sensor(NULL) -, m_time(0) -, m_state(false) -{ -} - -face_down_sensor::~face_down_sensor() -{ - _I("%s is destroyed!", SENSOR_NAME); -} - -bool face_down_sensor::init(void) -{ - m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); - - if (!m_gravity_sensor) { - _W("cannot load gravity sensor sensor[%s]", SENSOR_NAME); - return false; - } - - m_alg = get_alg(); - if (!m_alg) - return false; - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t face_down_sensor::get_type(void) -{ - return GESTURE_FACE_DOWN_SENSOR; -} - -unsigned int face_down_sensor::get_event_type(void) -{ - return CONVERT_TYPE_EVENT(GESTURE_FACE_DOWN_SENSOR); -} - -const char *face_down_sensor::get_name(void) -{ - return SENSOR_NAME; -} - -bool face_down_sensor::get_sensor_info(sensor_info & info) -{ - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void face_down_sensor::synthesize(const sensor_event_t & event) -{ - if (event.event_type != GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME) - return; - - m_time = event.data->timestamp; - m_alg->push_event(event); - m_state = m_alg->get_face_down(); - if (!m_state) - return; - - sensor_event_t *face_down_event; - sensor_data_t *face_down_data; - int data_length; - - face_down_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - retm_if(!face_down_event, "Failed to allocate memory"); - - get_data(&face_down_data, &data_length); - face_down_event->sensor_id = get_id(); - face_down_event->event_type = FACE_DOWN_RAW_DATA_EVENT; - face_down_event->data_length = data_length; - face_down_event->data = face_down_data; - - push(face_down_event); - - _I("[face_down_sensor] : True"); -} - -int face_down_sensor::get_data(sensor_data_t ** data, int *length) -{ - sensor_data_t *sensor_data; - sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); - - sensor_data->accuracy = SENSOR_ACCURACY_GOOD; - sensor_data->timestamp = m_time; - sensor_data->value_count = 1; - sensor_data->values[0] = m_state; - - *data = sensor_data; - *length = sizeof(sensor_data_t); - - return 0; -} - -bool face_down_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool face_down_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool face_down_sensor::on_start(void) -{ - if (m_gravity_sensor) - m_gravity_sensor->start(); - - m_time = 0; - m_state = false; - return activate(); -} - -bool face_down_sensor::on_stop(void) -{ - if (m_gravity_sensor) - m_gravity_sensor->stop(); - - m_time = 0; - m_state = false; - - return deactivate(); -} - -bool face_down_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_gravity_sensor->add_interval(client_id, interval, true); - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool face_down_sensor::delete_interval(int client_id, bool is_processor) -{ - m_gravity_sensor->delete_interval(client_id, true); - return sensor_base::delete_interval(client_id, is_processor); -} - -face_down_alg_impl *face_down_sensor::get_alg(void) -{ - face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl(); - retvm_if(!alg, NULL, "Failed to allocate memory"); - - return alg; -} diff --git a/src/sensor/gesture/face_down_sensor.h b/src/sensor/gesture/face_down_sensor.h deleted file mode 100644 index 7bb0809..0000000 --- a/src/sensor/gesture/face_down_sensor.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 __FACE_DOWN_SENSOR_H__ -#define __FACE_DOWN_SENSOR_H__ - -#include -#include -#include - -class face_down_sensor : public virtual_sensor { -public: - face_down_sensor(); - ~face_down_sensor(); - - /* initialize sensor */ - bool init(void); - - /* sensor info */ - sensor_type_t get_type(void); - unsigned int get_event_type(void); - const char *get_name(void); - - bool get_sensor_info(sensor_info & info); - - /* synthesize event */ - void synthesize(const sensor_event_t & event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - int get_data(sensor_data_t ** data, int *length); -private: - sensor_base * m_gravity_sensor; - face_down_alg_impl *m_alg; - - unsigned long long m_time; - bool m_state; - unsigned int m_interval; - - bool set_interval(unsigned long interval); - bool set_batch_latency(unsigned long latency); - - bool on_start(void); - bool on_stop(void); - face_down_alg_impl *get_alg(void); -}; - -#endif /* __FACE_DOWN_SENSOR_H__ */ diff --git a/src/sensor/hrm/hrm_sensor.cpp b/src/sensor/hrm/hrm_sensor.cpp deleted file mode 100644 index d29ff49..0000000 --- a/src/sensor/hrm/hrm_sensor.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 "hrm_sensor.h" - -hrm_sensor::hrm_sensor() -{ - set_permission(SENSOR_PERMISSION_BIO); - - _I("hrm_sensor is created : %#x", this); -} - -hrm_sensor::~hrm_sensor() -{ - _I("hrm_sensor is destroyed : %#x", this); -} diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp deleted file mode 100644 index c825e41..0000000 --- a/src/sensor/sensorhub/pedometer_sensor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 "pedometer_sensor.h" - -enum value_index { - IDX_STEPS = 0, - IDX_WALK_STEPS, - IDX_RUN_STEPS, - IDX_DISTANCE, - IDX_CALORIES, - IDX_SPEED, - IDX_FREQUENCY, - IDX_STATE, - IDX_WALK_UP, - IDX_WALK_DOWN, - IDX_RUN_UP, - IDX_RUN_DOWN, - IDX_STATE_EX, -}; - -pedometer_sensor::pedometer_sensor() -: m_steps(0) -, m_walk_steps(0) -, m_run_steps(0) -, m_walk_up_steps(0) -, m_walk_down_steps(0) -, m_run_up_steps(0) -, m_run_down_steps(0) -, m_distance(0) -, m_calories(0) -{ - set_permission(SENSOR_PERMISSION_BIO); - - _I("pedometer_sensor is created : %#x", this); -} - -pedometer_sensor::~pedometer_sensor() -{ -} - -bool pedometer_sensor::on_event(const sensor_data_t *data, int data_len, int remains) -{ - if (data_len == sizeof(sensorhub_data_t)) - return false; - - accumulate((sensor_pedometer_data_t*)data); - return true; -} - -void pedometer_sensor::accumulate(sensor_pedometer_data_t *data) -{ - m_steps += data->values[IDX_STEPS]; - m_walk_steps += data->values[IDX_WALK_STEPS]; - m_run_steps += data->values[IDX_RUN_STEPS]; - m_distance += data->values[IDX_DISTANCE]; - m_calories += data->values[IDX_CALORIES]; - - m_walk_up_steps += data->values[IDX_WALK_UP]; - m_walk_down_steps += data->values[IDX_WALK_DOWN]; - m_run_up_steps += data->values[IDX_RUN_UP]; - m_run_down_steps += data->values[IDX_RUN_DOWN]; - - data->values[IDX_STEPS] = m_steps; - data->values[IDX_WALK_STEPS] = m_walk_steps; - data->values[IDX_RUN_STEPS] = m_run_steps; - data->values[IDX_DISTANCE] = m_distance; - data->values[IDX_CALORIES] = m_calories; - - data->values[IDX_WALK_UP] = m_walk_up_steps; - data->values[IDX_WALK_DOWN] = m_walk_down_steps; - data->values[IDX_RUN_UP] = m_run_up_steps; - data->values[IDX_RUN_DOWN] = m_run_down_steps; -} diff --git a/src/sensorctl/info.cpp b/src/sensorctl/info.cpp index 43b73f1..149b98c 100644 --- a/src/sensorctl/info.cpp +++ b/src/sensorctl/info.cpp @@ -20,7 +20,6 @@ #include "info.h" #include -#include #include #include @@ -45,10 +44,7 @@ bool info_manager::run(int argc, char *argv[]) sensord_get_sensor_list(type, &sensors, &count); show_info(sensors, count); - if (sensors) { - free(sensors); - sensors = NULL; - } + delete sensors; return true; } diff --git a/src/sensorctl/injector.h b/src/sensorctl/injector.h index 1742200..b487c91 100644 --- a/src/sensorctl/injector.h +++ b/src/sensorctl/injector.h @@ -39,7 +39,7 @@ public: virtual bool teardown(void) { return true; } const std::string& name() const { return m_name; } - sensor_type_t type() { return m_type; } + const sensor_type_t type() const { return m_type; } virtual bool inject(int argc, char *argv[]) = 0; diff --git a/src/sensorctl/sensor_adapter.cpp b/src/sensorctl/sensor_adapter.cpp index 2ba6f59..13bc4e5 100644 --- a/src/sensorctl/sensor_adapter.cpp +++ b/src/sensorctl/sensor_adapter.cpp @@ -53,51 +53,39 @@ bool sensor_adapter::get_handle(sensor_info info, int &handle) { int err; int count; - sensor_t *sensors = NULL; + sensor_t *sensors; err = sensord_get_sensors(info.type, &sensors, &count); ASSERT_EQ(err, 0); handle = sensord_connect(sensors[info.index]); - ASSERT_FREE((handle < 0), sensors); ASSERT_GE(handle, 0); - free(sensors); - sensors = NULL; - return true; } bool sensor_adapter::start(sensor_info info, int &handle) { - sensor_t *sensors = NULL; + sensor_t *sensors; int count; int err; bool ret; err = sensord_get_sensors(info.type, &sensors, &count); ASSERT_EQ(err, 0); - - ASSERT_FREE((info.index >= count), sensors); ASSERT_LT(info.index, count); - - ASSERT_FREE((info.index < 0), sensors); ASSERT_GE(info.index, 0); handle = sensord_connect(sensors[info.index]); - ASSERT_FREE((handle < 0), sensors); ASSERT_GE(handle, 0); ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL); - ASSERT_FREE((ret != true), sensors); ASSERT_TRUE(ret); ret = sensord_start(handle, info.powersave); - ASSERT_FREE((ret != true), sensors); ASSERT_TRUE(ret); free(sensors); - sensors = NULL; return true; } diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp index 694d34e..7504341 100644 --- a/src/sensorctl/sensor_manager.cpp +++ b/src/sensorctl/sensor_manager.cpp @@ -70,6 +70,8 @@ static struct sensor_info sensor_infos[] = { {GESTURE_WRIST_UP_SENSOR, "wristup"}, {GESTURE_WRIST_DOWN_SENSOR, "wristdown"}, {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state"}, + {GESTURE_PICK_UP_SENSOR, "pickup"}, + {GESTURE_FACE_DOWN_SENSOR, "facedown"}, {WEAR_STATUS_SENSOR, "wear_status"}, {WEAR_ON_MONITOR_SENSOR, "wear_on"}, diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp index 415960f..a35e286 100644 --- a/src/sensorctl/sensorctl.cpp +++ b/src/sensorctl/sensorctl.cpp @@ -47,11 +47,11 @@ static sensor_manager *create_manager(char *command) if (!strcmp(command, "test")) manager = new(std::nothrow) tester_manager; - else if (!strcmp(command, "inject")) + if (!strcmp(command, "inject")) manager = new(std::nothrow) injector_manager; - else if (!strcmp(command, "info")) + if (!strcmp(command, "info")) manager = new(std::nothrow) info_manager; - else if (!strcmp(command, "loopback")) + if (!strcmp(command, "loopback")) manager = new(std::nothrow) loopback_manager; if (!manager) { diff --git a/src/sensorctl/test_bench.h b/src/sensorctl/test_bench.h index 9f51622..4e04b85 100644 --- a/src/sensorctl/test_bench.h +++ b/src/sensorctl/test_bench.h @@ -67,9 +67,6 @@ do { \ } \ } while (0) -#define ASSERT_FREE(expr, X) \ - do { if (expr) { free (X); X = NULL; } } while (0) - #define ASSERT_TRUE(condition) ASSERT(condition, ==, true) #define ASSERT_FALSE(condition) ASSERT(condition, ==, false) #define ASSERT_EQ(left, right) ASSERT(left, ==, right) diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index cd1833c..ebff117 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -59,7 +59,6 @@ TESTCASE(sensor_listener, get_sensors_p_1) err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count); ASSERT_EQ(err, 0); - ASSERT_FREE((count < 0), sensors); ASSERT_GT(count, 0); free(sensors); @@ -91,8 +90,8 @@ TESTCASE(sensor_listener, all_api_p_1) bool ret; int handle; sensor_t sensor; - sensor_t *list = NULL; - int count = 0; + sensor_t *list; + int count; called = false; @@ -103,37 +102,29 @@ TESTCASE(sensor_listener, all_api_p_1) ASSERT_EQ(err, 0); handle = sensord_connect(sensor); - ASSERT_FREE(((handle != 0) && list), list); - ASSERT_EQ(handle, 0); + ASSERT_EQ(err, 0); ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); ret = sensord_start(handle, 0); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); ret = sensord_change_event_interval(handle, 0, 100); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); ret = sensord_change_event_max_batch_latency(handle, 0, 100); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); mainloop::run(); ret = sensord_stop(handle); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); ret = sensord_unregister_event(handle, 1); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); ret = sensord_disconnect(handle); - ASSERT_FREE(((ret != true) && list), list); ASSERT_TRUE(ret); free(list); diff --git a/src/sensorctl/testcase/sensor_provider.cpp b/src/sensorctl/testcase/sensor_provider.cpp index a163325..9c76c21 100644 --- a/src/sensorctl/testcase/sensor_provider.cpp +++ b/src/sensorctl/testcase/sensor_provider.cpp @@ -86,8 +86,8 @@ static void add_mysensor(void) sensord_provider_set_resolution(provider, 0.01f); sensord_add_provider(provider); - sensord_remove_provider(provider); + sensord_remove_provider(provider); sensord_destroy_provider(provider); } diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 6be6472..b11a84d 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensord CXX) -SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session") +SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session vconf") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS}) diff --git a/src/server/application_sensor_handler.cpp b/src/server/application_sensor_handler.cpp index a5f9c0f..f2abadc 100644 --- a/src/server/application_sensor_handler.cpp +++ b/src/server/application_sensor_handler.cpp @@ -140,6 +140,26 @@ int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) { + ipc::message msg; + cmd_provider_attr_str_t *buf; + size_t size; + + size = sizeof(cmd_provider_attr_str_t) + len; + + buf = (cmd_provider_attr_str_t *) malloc(sizeof(char) * size); + retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); + + msg.set_type(CMD_PROVIDER_ATTR_STR); + memcpy(buf->value, value, len); + buf->attribute = attr; + buf->len = len; + + msg.enclose((char *)buf, size); + + m_ch->send_sync(&msg); + + _I("Set attribute[%d] to sensor[%s]", attr, m_info.get_uri().c_str()); + return OP_SUCCESS; } diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp deleted file mode 100644 index 0aa0b90..0000000 --- a/src/server/dbus_util.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * 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. - * - */ - -#include -#include -#include - -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; - -static const gchar introspection_xml[] = -"" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -""; - -static void method_call_handler(GDBusConnection *conn, - const gchar *sender, const gchar *object_path, - const gchar *iface_name, const gchar *method_name, - GVariant *parameters, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - int ret = DBUS_INIT; - - if (g_strcmp0(method_name, "check_privilege") == 0) { - _D("check_privilege called"); - ret = DBUS_SUCCESS; - } else if (g_strcmp0(method_name, "wristup_lcdon_cnt") == 0) { - _D("wristup_lcdon_cnt called, %d", wrist_up_lcdon_cnt); - ret = wrist_up_lcdon_cnt; - } 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; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", ret)); -} - -static const GDBusInterfaceVTable interface_vtable = -{ - method_call_handler, - NULL, - NULL -}; - -static void on_bus_acquired(GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - guint registration_id; - - if (!connection) { - _E("connection is null"); - return; - } - - registration_id = g_dbus_connection_register_object(connection, - SENSORD_OBJECT_PATH, - introspection_data->interfaces[0], - &interface_vtable, - NULL, /* user_data */ - NULL, /* user_data_free_func */ - NULL); /* GError** */ - - if (registration_id == 0) - _E("Failed to g_dbus_connection_register_object"); - - _I("Gdbus method call registrated"); -} - -static void on_name_acquired(GDBusConnection *conn, - const gchar *name, gpointer user_data) -{ -} - -static void on_name_lost(GDBusConnection *conn, - const gchar *name, gpointer user_data) -{ - _E("Dbus name is lost!"); -} - -int get_lcdon_count(void) -{ - return wrist_up_lcdon_cnt; -} - -void increase_lcdon_count(void) -{ - wrist_up_lcdon_cnt++; -} - -void reset_lcdon_count(void) -{ - wrist_up_lcdon_cnt = 0; -} - -int get_total_count(void) -{ - return wrist_up_total_cnt; -} - -void increase_total_count(void) -{ - wrist_up_total_cnt++; -} - -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 - g_type_init(); -#endif - - introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); - if (introspection_data == NULL) { - _E("Failed to init g_dbus_node_info_new_for_xml"); - return; - } - - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, - SENSORD_BUS_NAME, - (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT - | G_BUS_NAME_OWNER_FLAGS_REPLACE), - on_bus_acquired, - on_name_acquired, - on_name_lost, - NULL, - NULL); - wrist_up_total_cnt = 0; - wrist_up_lcdon_cnt = 0; -} - -void fini_dbus(void) -{ - if (owner_id != 0) - g_bus_unown_name(owner_id); - - if (introspection_data) - g_dbus_node_info_unref(introspection_data); -} diff --git a/src/server/dbus_util.h b/src/server/dbus_util.h deleted file mode 100644 index f729e3b..0000000 --- a/src/server/dbus_util.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - * - */ - -#ifndef _DBUS_UTIL_H_ -#define _DBUS_UTIL_H_ - -#define SENSORD_BUS_NAME "org.tizen.system.sensord" -#define SENSORD_OBJECT_PATH "/Org/Tizen/System/SensorD" -#define SENSORD_INTERFACE_NAME SENSORD_BUS_NAME - -enum dbus_ret { - DBUS_INIT = -1, - DBUS_FAILED = 0, - DBUS_SUCCESS = 1 -}; - -int get_lcdon_count(void); -void increase_lcdon_count(void); -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); - -#endif /* SENSORD_GDBUS_H_ */ diff --git a/src/server/main.cpp b/src/server/main.cpp index 8bb6cf3..2f0357f 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include @@ -59,12 +58,8 @@ int main(int argc, char *argv[]) std::set_new_handler(on_new_failed); - init_dbus(); - server::run(); - fini_dbus(); - _I("Stopped"); return 0; diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index f73ee5d..1b44a87 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -34,6 +34,7 @@ physical_sensor_handler::physical_sensor_handler(const sensor_info &info, , m_sensor(sensor) , m_hal_id(hal_id) , m_prev_interval(0) +, m_prev_latency(0) { } @@ -60,7 +61,6 @@ int physical_sensor_handler::get_poll_fd(void) int physical_sensor_handler::read_fd(std::vector &ids) { - retv_if(observer_count() == 0, OP_ERROR); retv_if(!m_device, -EINVAL); int size; @@ -90,15 +90,20 @@ int physical_sensor_handler::start(sensor_observer *ob) { retv_if(!m_device, -EINVAL); + bool ret; int policy = OP_DEFAULT; + ret = add_observer(ob); + retvm_if(!ret, OP_SUCCESS, "Listener is already added"); + if (m_sensor) { policy = m_sensor->start(ob); - retv_if(policy <= OP_ERROR, policy); + if (policy <= OP_ERROR) { + remove_observer(ob); + return policy; + } } - add_observer(ob); - if (policy == OP_DEFAULT) { if (observer_count() > 1) return OP_SUCCESS; /* already started */ @@ -187,11 +192,10 @@ int physical_sensor_handler::get_min_batch_latency(void) std::vector temp; for (auto it = m_batch_latency_map.begin(); it != m_batch_latency_map.end(); ++it) - if (it->second > 0) - temp.push_back(it->second); + temp.push_back(it->second); if (temp.empty()) - return 0; + return -1; batch_latency = *std::min_element(temp.begin(), temp.end()); @@ -203,7 +207,7 @@ int physical_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t late retv_if(!m_device, -EINVAL); bool ret = false; - int _latency = latency; + int32_t cur_latency = latency; int policy = OP_DEFAULT; if (m_sensor) { @@ -211,12 +215,36 @@ int physical_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t late retv_if(policy <= OP_ERROR, policy); } - m_batch_latency_map[ob] = _latency; + m_batch_latency_map[ob] = cur_latency; + + if (policy == OP_DEFAULT) + cur_latency = get_min_batch_latency(); + + retv_if(m_prev_latency == cur_latency, OP_SUCCESS); + + ret = m_device->set_batch_latency(m_hal_id, cur_latency); + + m_prev_latency = cur_latency; + + _I("Set batch latency[%d] to sensor[%s]", cur_latency, m_info.get_uri().c_str()); + + return (ret ? OP_SUCCESS : OP_ERROR); +} + +int physical_sensor_handler::delete_batch_latency(sensor_observer *ob) +{ + bool ret = false; + int policy = OP_DEFAULT; + int32_t latency; + + m_batch_latency_map.erase(ob); + + latency = get_min_batch_latency(); + retv_if(m_prev_latency == latency, OP_SUCCESS); - if (_latency <= latency) - return OP_SUCCESS; + ret = m_device->set_batch_latency(m_hal_id, latency); - ret = m_device->set_batch_latency(m_hal_id, _latency); + m_prev_latency = latency; return (ret ? OP_SUCCESS : OP_ERROR); } diff --git a/src/server/physical_sensor_handler.h b/src/server/physical_sensor_handler.h index 31ab410..608f854 100644 --- a/src/server/physical_sensor_handler.h +++ b/src/server/physical_sensor_handler.h @@ -50,6 +50,7 @@ public: int set_interval(sensor_observer *ob, int32_t interval); int set_batch_latency(sensor_observer *ob, int32_t latency); + int delete_batch_latency(sensor_observer *ob); int set_attribute(sensor_observer *ob, int32_t attr, int32_t value); int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len); int flush(sensor_observer *ob); @@ -63,6 +64,7 @@ private: physical_sensor *m_sensor; uint32_t m_hal_id; int32_t m_prev_interval; + int32_t m_prev_latency; std::unordered_map m_interval_map; std::unordered_map m_batch_latency_map; diff --git a/src/server/sensor_event_handler.cpp b/src/server/sensor_event_handler.cpp index a3422a7..2f7ddcf 100644 --- a/src/server/sensor_event_handler.cpp +++ b/src/server/sensor_event_handler.cpp @@ -27,55 +27,73 @@ using namespace sensor; static std::vector ids; -sensor_event_handler::sensor_event_handler(physical_sensor_handler *sensor) -: m_sensor(sensor) +sensor_event_handler::sensor_event_handler() { } +void sensor_event_handler::add_sensor(physical_sensor_handler *sensor) +{ + ret_if(!sensor); + + m_sensors.insert(sensor); +} + +void sensor_event_handler::remove_sensor(physical_sensor_handler *sensor) +{ + ret_if(!sensor); + + m_sensors.erase(sensor); +} + bool sensor_event_handler::handle(int fd, ipc::event_condition condition) { sensor_info info; - sensor_data_t *data = NULL; + sensor_data_t *data; + physical_sensor_handler *sensor; int length = 0; - int remains = 1; + int remains; - if (m_sensor->read_fd(ids) < 0) - return true; + retv_if(m_sensors.empty(), false); + + ids.clear(); - auto result = std::find(std::begin(ids), std::end(ids), m_sensor->get_hal_id()); + auto it = m_sensors.begin(); - if (result == std::end(ids)) - { - ids.clear(); + /* sensors using the same fd share read_fd in common. + * so just call read_fd on the first sensor */ + if ((*it)->read_fd(ids) < 0) return true; - } - while (remains > 0) { - remains = m_sensor->get_data(&data, &length); - if (remains < 0) { - _E("Failed to get sensor data"); - break; - } + for (; it != m_sensors.end(); ++it) { + remains = 1; + sensor = *it; - if (m_sensor->on_event(data, length, remains) < 0) { - free(data); - data = NULL; + /* check whether the id of this sensor is in id list(parameter) or not */ + auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id()); + if (result == std::end(ids)) continue; - } - info = m_sensor->get_sensor_info(); + while (remains > 0) { + remains = sensor->get_data(&data, &length); + if (remains < 0) { + _E("Failed to get sensor data"); + break; + } + + if (sensor->on_event(data, length, remains) < 0) { + free(data); + continue; + } + + info = sensor->get_sensor_info(); - //_I("[Data] allocate %p", data); - if (data) { - if (m_sensor->notify(info.get_uri().c_str(), data, length) < 0) { + //_I("[Data] allocate %p", data); + if (sensor->notify(info.get_uri().c_str(), data, length) < 0) { free(data); - data = NULL; } + info.clear(); } - info.clear(); } - ids.clear(); - return true; } diff --git a/src/server/sensor_event_handler.h b/src/server/sensor_event_handler.h index 53b5cd6..f956fdd 100644 --- a/src/server/sensor_event_handler.h +++ b/src/server/sensor_event_handler.h @@ -21,6 +21,8 @@ #define __SENSOR_EVENT_HANDLER__ #include +#include + #include "physical_sensor_handler.h" namespace sensor { @@ -28,12 +30,15 @@ namespace sensor { class sensor_event_handler : public ipc::event_handler { public: - sensor_event_handler(physical_sensor_handler *sensor); + sensor_event_handler(); + + void add_sensor(physical_sensor_handler *sensor); + void remove_sensor(physical_sensor_handler *sensor); bool handle(int fd, ipc::event_condition condition); private: - physical_sensor_handler *m_sensor; + std::set m_sensors; }; } diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index b9cdfca..3939d04 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -43,6 +43,9 @@ sensor_handler::sensor_handler(const sensor_info &info) case EXERCISE_STANDALONE_SENSOR: m_info.add_privilege(PRIVILEGE_LOCATION_URI); break; + case GPS_CTRL_SENSOR: + m_info.add_privilege(PRIVILEGE_PLATFORM_URI); + break; default: break; } @@ -58,11 +61,12 @@ bool sensor_handler::has_observer(sensor_observer *ob) return false; } -void sensor_handler::add_observer(sensor_observer *ob) +bool sensor_handler::add_observer(sensor_observer *ob) { - ret_if(has_observer(ob)); + retv_if(has_observer(ob), false); m_observers.push_back(ob); + return true; } void sensor_handler::remove_observer(sensor_observer *ob) @@ -83,13 +87,11 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len) for (auto it = m_observers.begin(); it != m_observers.end(); ++it) (*it)->update(uri, msg); - if (msg->ref_count() == 0) { - delete msg; - msg = NULL; - } - set_cache(data, len); + if (msg->ref_count() == 0) + msg->unref(); + return OP_SUCCESS; } @@ -100,15 +102,12 @@ uint32_t sensor_handler::observer_count(void) void sensor_handler::set_cache(sensor_data_t *data, int size) { - retm_if(data == NULL, "Nothing to copy from as source is NULL"); - retm_if(size <= 0, "data is of size 0"); - - if (m_last_data_size != size) { - m_last_data = (sensor_data_t*)realloc(m_last_data, size); + if (m_last_data == NULL) { + m_last_data = (sensor_data_t*)malloc(size); retm_if(m_last_data == NULL, "Memory allocation failed"); - m_last_data_size = size; } + m_last_data_size = size; memcpy(m_last_data, data, size); } @@ -124,3 +123,8 @@ int sensor_handler::get_cache(sensor_data_t **data, int *len) return 0; } + +int sensor_handler::delete_batch_latency(sensor_observer *ob) +{ + return 0; +} diff --git a/src/server/sensor_handler.h b/src/server/sensor_handler.h index db237e4..9f6e711 100644 --- a/src/server/sensor_handler.h +++ b/src/server/sensor_handler.h @@ -35,7 +35,7 @@ public: /* publisher */ bool has_observer(sensor_observer *ob); - void add_observer(sensor_observer *ob); + bool add_observer(sensor_observer *ob); void remove_observer(sensor_observer *ob); int notify(const char *type, sensor_data_t *data, int len); uint32_t observer_count(void); @@ -47,6 +47,7 @@ public: virtual int set_interval(sensor_observer *ob, int32_t interval) = 0; virtual int set_batch_latency(sensor_observer *ob, int32_t latency) = 0; + virtual int delete_batch_latency(sensor_observer *ob); virtual int set_attribute(sensor_observer *ob, int32_t attr, int32_t value) = 0; virtual int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) = 0; virtual int flush(sensor_observer *ob) = 0; diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 8d3c3bc..77a2ff7 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -26,6 +26,7 @@ #include #include "sensor_handler.h" +#include "sensor_policy_monitor.h" using namespace sensor; @@ -35,15 +36,18 @@ sensor_listener_proxy::sensor_listener_proxy(uint32_t id, , m_uri(uri) , m_manager(manager) , m_ch(ch) +, m_started(false) , m_passive(false) , m_pause_policy(SENSORD_PAUSE_ALL) , m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED) , m_last_accuracy(SENSOR_ACCURACY_UNDEFINED) { + sensor_policy_monitor::get_instance().add_listener(this); } sensor_listener_proxy::~sensor_listener_proxy() { + sensor_policy_monitor::get_instance().remove_listener(this); stop(); } @@ -93,33 +97,48 @@ void sensor_listener_proxy::update_accuracy(ipc::message *msg) m_ch->send(acc_msg); } -int sensor_listener_proxy::start(void) +int sensor_listener_proxy::start(bool policy) { + int ret; sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + retvm_if(m_started && !policy, OP_SUCCESS, "Sensor is already started"); _D("Listener[%d] try to start", get_id()); - /* TODO: listen pause policy */ - return sensor->start(this); + ret = sensor->start(this); + retv_if (ret < 0, OP_ERROR); + + /* m_started is changed only when it is explicitly called by user, + * not automatically determined by any pause policy. */ + if (policy) + return OP_SUCCESS; + + m_started = true; + return OP_SUCCESS; } -int sensor_listener_proxy::stop(void) +int sensor_listener_proxy::stop(bool policy) { sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); - - /* TODO: listen pause policy */ + retvm_if(!m_started && !policy, OP_SUCCESS, "Sensor is already stopped"); _D("Listener[%d] try to stop", get_id()); int ret = sensor->stop(this); retv_if(ret < 0, OP_ERROR); + /* attributes and m_started are changed only when it is explicitly called by user, + * not automatically determined by any policy. */ + if (policy) + return OP_SUCCESS; + /* unset attributes */ - set_interval(POLL_1HZ_MS); - set_max_batch_latency(0); + set_interval(POLL_MAX_HZ_MS); + delete_batch_latency(); + m_started = false; return OP_SUCCESS; } @@ -143,6 +162,16 @@ int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency) return sensor->set_batch_latency(this, max_batch_latency); } +int sensor_listener_proxy::delete_batch_latency(void) +{ + sensor_handler *sensor = m_manager->get_sensor(m_uri); + retv_if(!sensor, -EINVAL); + + _I("Listener[%d] try to delete batch latency", get_id()); + + return sensor->delete_batch_latency(this); +} + int sensor_listener_proxy::set_passive_mode(bool passive) { /* TODO: passive mode */ @@ -163,6 +192,8 @@ int sensor_listener_proxy::set_attribute(int attribute, int value) } else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) { m_axis_orientation = value; return OP_SUCCESS; + } else if (attribute == SENSORD_ATTRIBUTE_FLUSH) { + return flush(); } return sensor->set_attribute(this, attribute, value); @@ -202,3 +233,18 @@ std::string sensor_listener_proxy::get_required_privileges(void) sensor_info info = sensor->get_sensor_info(); return info.get_privilege(); } + +void sensor_listener_proxy::on_policy_changed(int policy, int value) +{ + ret_if(m_started == false); + ret_if(policy != SENSORD_ATTRIBUTE_PAUSE_POLICY); + ret_if(m_pause_policy == SENSORD_PAUSE_NONE); + + _D("power_save_state[%d], listener[%d] pause policy[%d]", + value, get_id(), m_pause_policy); + + if (value & m_pause_policy) + stop(true); + if (!(value & m_pause_policy)) + start(true); +} diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index 30e3976..8258f63 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -25,10 +25,11 @@ #include "sensor_manager.h" #include "sensor_observer.h" +#include "sensor_policy_listener.h" namespace sensor { -class sensor_listener_proxy : public sensor_observer { +class sensor_listener_proxy : public sensor_observer, sensor_policy_listener { public: sensor_listener_proxy(uint32_t id, std::string uri, sensor_manager *manager, ipc::channel *ch); @@ -39,11 +40,12 @@ public: /* sensor observer */ int update(const char *uri, ipc::message *msg); - int start(void); - int stop(void); + int start(bool policy = false); + int stop(bool policy = false); int set_interval(unsigned int interval); int set_max_batch_latency(unsigned int max_batch_latency); + int delete_batch_latency(void); int set_passive_mode(bool passive); int set_attribute(int attribute, int value); int set_attribute(int attribute, const char *value, int len); @@ -51,6 +53,9 @@ public: int get_data(sensor_data_t **data, int *len); std::string get_required_privileges(void); + /* sensor_policy_listener interface */ + void on_policy_changed(int policy, int value); + private: void update_event(ipc::message *msg); void update_accuracy(ipc::message *msg); @@ -61,6 +66,7 @@ private: sensor_manager *m_manager; ipc::channel *m_ch; + bool m_started; bool m_passive; int m_pause_policy; int m_axis_orientation; diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index 7ee0766..f6cc1f5 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -138,13 +138,11 @@ void sensor_manager::send_added_msg(sensor_info *info) int size; size = serialize(info, &bytes); - retm_if(size == -ENOMEM, "Failed to serialize"); ipc::message msg((const char *)bytes, size); msg.set_type(CMD_MANAGER_SENSOR_ADDED); send(msg); - delete []bytes; } void sensor_manager::send_removed_msg(const std::string &uri) @@ -240,6 +238,18 @@ std::vector sensor_manager::get_sensors(void) return sensors; } +static physical_sensor *create_physical_sensor(std::string uri, physical_sensor_registry_t &psensors) +{ + for (auto it = psensors.begin(); it != psensors.end(); ++it) { + if (uri.find((*it)->get_uri()) != std::string::npos) { + _D("%s, %s", uri.c_str(), (*it)->get_uri().c_str()); + return (*it)->clone(); + } + } + + return NULL; +} + void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices, physical_sensor_registry_t &psensors) { @@ -250,13 +260,19 @@ void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices, int count = (*it)->get_sensors(&info); for (int i = 0; i < count; ++i) { - /* TODO: psensors */ + physical_sensor *sensor = NULL; + sensor_info pinfo(info[i]); + std::string uri = pinfo.get_uri(); + + sensor = create_physical_sensor(uri, psensors); + if (sensor) + sensor->set_device(it->get()); + psensor = new(std::nothrow) physical_sensor_handler( - info[i], it->get(), info[i].id, NULL); + info[i], it->get(), info[i].id, sensor); retm_if(!psensor, "Failed to allocate memory"); - sensor_info sinfo = psensor->get_sensor_info(); - m_sensors[sinfo.get_uri()] = psensor; + m_sensors[uri] = psensor; } } } @@ -376,12 +392,25 @@ void sensor_manager::init_sensors(void) void sensor_manager::register_handler(physical_sensor_handler *sensor) { - ret_if(sensor->get_poll_fd() < 0); + sensor_event_handler *handler = NULL; + int fd = sensor->get_poll_fd(); + + ret_if(fd < 0); + + auto it = m_event_handlers.find(fd); - sensor_event_handler *handler = new(std::nothrow) sensor_event_handler(sensor); + if (it != m_event_handlers.end()) { + it->second->add_sensor(sensor); + return; + } + + handler = new(std::nothrow) sensor_event_handler(); retm_if(!handler, "Failed to allocate memory"); - m_loop->add_event(sensor->get_poll_fd(), + handler->add_sensor(sensor); + m_event_handlers[fd] = handler; + + m_loop->add_event(fd, ipc::EVENT_IN | ipc::EVENT_HUP | ipc::EVENT_NVAL, handler); } diff --git a/src/server/sensor_manager.h b/src/server/sensor_manager.h index 78692a8..aac7e93 100644 --- a/src/server/sensor_manager.h +++ b/src/server/sensor_manager.h @@ -34,6 +34,7 @@ #include "physical_sensor_handler.h" #include "fusion_sensor_handler.h" #include "external_sensor_handler.h" +#include "sensor_event_handler.h" namespace sensor { @@ -84,6 +85,7 @@ private: sensor_map_t m_sensors; std::vector m_channels; + std::map m_event_handlers; }; } diff --git a/src/sensor/hrm/hrm_sensor.h b/src/server/sensor_policy_listener.h similarity index 65% rename from src/sensor/hrm/hrm_sensor.h rename to src/server/sensor_policy_listener.h index 1c64bc5..383aad4 100644 --- a/src/sensor/hrm/hrm_sensor.h +++ b/src/server/sensor_policy_listener.h @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -17,16 +17,16 @@ * */ -#ifndef _HRM_SENSOR_H_ -#define _HRM_SENSOR_H_ +#ifndef __SENSOR_POLICY_LISTENER_H__ +#define __SENSOR_POLICY_LISTENER_H__ -#include - -class hrm_sensor : public physical_sensor { +namespace sensor { +class sensor_policy_listener { public: - hrm_sensor(); - virtual ~hrm_sensor(); -}; + virtual ~sensor_policy_listener() {} -#endif /* _HRM_SENSOR_H_ */ + virtual void on_policy_changed(int policy, int value) = 0; +}; +} +#endif /* __SENSOR_POLICY_LISTENER_H__ */ diff --git a/src/server/sensor_policy_monitor.cpp b/src/server/sensor_policy_monitor.cpp new file mode 100644 index 0000000..9ab0f2b --- /dev/null +++ b/src/server/sensor_policy_monitor.cpp @@ -0,0 +1,97 @@ +/* + * sensord + * + * Copyright (c) 2018 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 "sensor_policy_monitor.h" + +#include +#include + +#ifndef VCONFKEY_SETAPPL_PSMODE +#define VCONFKEY_SETAPPL_PSMODE "db/setting/psmode" +#endif + +using namespace sensor; + +static int get_power_save_state(void) +{ + int ret; + int state = 0; + int pm_state, ps_state; + + ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + + if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF) + state |= SENSORD_PAUSE_ON_DISPLAY_OFF; + + ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state); + + if (!ret && ps_state != SETTING_PSMODE_NORMAL) + state |= SENSORD_PAUSE_ON_POWERSAVE_MODE; + + return state; +} + +static void power_save_state_cb(keynode_t *node, void *data) +{ + int power_save_state = get_power_save_state(); + + sensor_policy_monitor::get_instance().on_policy_changed(SENSORD_ATTRIBUTE_PAUSE_POLICY, power_save_state); +} + +sensor_policy_monitor& sensor_policy_monitor::get_instance(void) +{ + static sensor_policy_monitor mon; + return mon; +} + +sensor_policy_monitor::sensor_policy_monitor() +{ + vconf_notify_key_changed(VCONFKEY_PM_STATE, power_save_state_cb, NULL); + vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb, NULL); +} + +sensor_policy_monitor::~sensor_policy_monitor() +{ + vconf_ignore_key_changed(VCONFKEY_PM_STATE, power_save_state_cb); + vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb); +} + +void sensor_policy_monitor::add_listener(sensor_policy_listener *listener) +{ + ret_if(!listener); + + m_listeners.insert(listener); +} + +void sensor_policy_monitor::remove_listener(sensor_policy_listener *listener) +{ + ret_if(!listener); + + m_listeners.erase(listener); +} + +void sensor_policy_monitor::on_policy_changed(int policy, int value) +{ + auto it = m_listeners.begin(); + + while (it != m_listeners.end()) { + (*it)->on_policy_changed(policy, value); + ++it; + } +} diff --git a/src/server/sensor_policy_monitor.h b/src/server/sensor_policy_monitor.h new file mode 100644 index 0000000..ba22199 --- /dev/null +++ b/src/server/sensor_policy_monitor.h @@ -0,0 +1,51 @@ +/* + * sensord + * + * Copyright (c) 2018 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_POLICY_MONITOR_H__ +#define __SENSOR_POLICY_MONITOR_H__ + +#include +#include +#include +#include + +#include "sensor_policy_listener.h" + +namespace sensor { + +class sensor_policy_monitor { +public: + ~sensor_policy_monitor(); + + static sensor_policy_monitor& get_instance(void); + + void add_listener(sensor_policy_listener *listener); + void remove_listener(sensor_policy_listener *listener); + + void on_policy_changed(int policy, int value); + +private: + sensor_policy_monitor(); + + std::set m_listeners; +}; + +} + +#endif /* __SENSOR_POLICY_MONITOR_H__ */ diff --git a/src/server/sensor_publisher.h b/src/server/sensor_publisher.h index 58bb996..160237c 100644 --- a/src/server/sensor_publisher.h +++ b/src/server/sensor_publisher.h @@ -31,7 +31,7 @@ public: virtual ~sensor_publisher() {} virtual bool has_observer(sensor_observer *ob) = 0; - virtual void add_observer(sensor_observer *ob) = 0; + virtual bool add_observer(sensor_observer *ob) = 0; virtual void remove_observer(sensor_observer *ob) = 0; virtual int notify(const char *type, sensor_data_t *data, int len) = 0; }; diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index a62b75b..780cc3d 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -141,18 +141,13 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) msg.disclose((char *)&buf); - sensor_listener_proxy *listener = NULL; + sensor_listener_proxy *listener; listener = new(std::nothrow) sensor_listener_proxy(listener_id, buf.sensor, m_manager, ch); retvm_if(!listener, OP_ERROR, "Failed to allocate memory"); - - if (!has_privileges(ch->get_fd(), listener->get_required_privileges())) { - delete listener; - listener = NULL; - _E("Permission denied[%d, %s]", listener_id, - m_listeners[listener_id]->get_required_privileges().c_str()); - return -EACCES; - } + retvm_if(!has_privileges(ch->get_fd(), listener->get_required_privileges()), + -EACCES, "Permission denied[%d, %s]", + listener_id, m_listeners[listener_id]->get_required_privileges().c_str()); buf.listener_id = listener_id; @@ -160,10 +155,8 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) reply.enclose((const char *)&buf, sizeof(buf)); reply.header()->err = OP_SUCCESS; - if (!ch->send_sync(&reply)) { - delete listener; + if (!ch->send_sync(&reply)) return OP_ERROR; - } _I("Connected sensor_listener[fd(%d) -> id(%u)]", ch->get_fd(), listener_id); m_listeners[listener_id] = listener; @@ -237,7 +230,7 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) } /* TODO : check return value */ if (ret < 0) - _W("Return : %d", ret); + _D("Return : %d", ret); return send_reply(ch, OP_SUCCESS); } @@ -265,7 +258,7 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) return -EACCES; } - int ret = m_listeners[id]->set_attribute(buf->attribute, (char *)&buf->value, buf->len); + int ret = m_listeners[id]->set_attribute(buf->attribute, buf->value, buf->len); if (ret < 0) { delete [] buf; return ret; diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index eb20325..11f605b 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensord-shared CXX) -SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0") +SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0 vconf libtzplatform-config") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(SHARED_PKGS REQUIRED ${DEPENDENTS}) diff --git a/src/shared/cbase_lock.cpp b/src/shared/cbase_lock.cpp new file mode 100644 index 0000000..38f2f84 --- /dev/null +++ b/src/shared/cbase_lock.cpp @@ -0,0 +1,154 @@ +/* + * sensord + * + * Copyright (c) 2013 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 +#include +#include +#include + +cbase_lock::cbase_lock() +{ + m_history_mutex = PTHREAD_MUTEX_INITIALIZER; +} + +cbase_lock::~cbase_lock() +{ + pthread_mutex_destroy(&m_history_mutex); +} + +void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line) +{ + int ret = 0; + char m_curent_info[OWNER_INFO_LEN]; + struct timeval sv; + unsigned long long lock_waiting_start_time = 0; + unsigned long long lock_acquired_time = 0; + unsigned long long waiting_time = 0; + + snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line); + + if (type == LOCK_TYPE_MUTEX) + ret = try_lock_impl(); + else if (type == LOCK_TYPE_READ) + ret = try_read_lock_impl(); + else if (type == LOCK_TYPE_WRITE) + ret = try_write_lock_impl(); + + if (ret == 0) { + pthread_mutex_lock(&m_history_mutex); + snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info); + pthread_mutex_unlock(&m_history_mutex); + return; + } + + gettimeofday(&sv, NULL); + lock_waiting_start_time = MICROSECONDS(sv); + + pthread_mutex_lock(&m_history_mutex); + _I("%s is waiting for getting %s(%#x) owned in %s", + m_curent_info, expr, this, m_owner_info); + pthread_mutex_unlock(&m_history_mutex); + + if (type == LOCK_TYPE_MUTEX) + lock_impl(); + else if (type == LOCK_TYPE_READ) + read_lock_impl(); + else if (type == LOCK_TYPE_WRITE) + write_lock_impl(); + + gettimeofday(&sv, NULL); + lock_acquired_time = MICROSECONDS(sv); + + waiting_time = lock_acquired_time - lock_waiting_start_time; + + pthread_mutex_lock(&m_history_mutex); + _I("%s acquires lock after waiting %lluus, %s(%#x) was previously owned in %s", + m_curent_info, waiting_time, expr, this, m_owner_info); + snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info); + pthread_mutex_unlock(&m_history_mutex); +} + +void cbase_lock::lock(lock_type type) +{ + if (type == LOCK_TYPE_MUTEX) + lock_impl(); + else if (type == LOCK_TYPE_READ) + read_lock_impl(); + else if (type == LOCK_TYPE_WRITE) + write_lock_impl(); +} + +void cbase_lock::unlock(void) +{ + unlock_impl(); +} + +int cbase_lock::lock_impl(void) +{ + return 0; +} + +int cbase_lock::read_lock_impl(void) +{ + return 0; +} + +int cbase_lock::write_lock_impl(void) +{ + return 0; +} + +int cbase_lock::try_lock_impl(void) +{ + return 0; +} + +int cbase_lock::try_read_lock_impl(void) +{ + return 0; +} + +int cbase_lock::try_write_lock_impl(void) +{ + return 0; +} + +int cbase_lock::unlock_impl(void) +{ + return 0; +} + +Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line) +: m_lock(m) +{ + m_lock.lock(type, expr, module, func, line); +} + +Autolock::Autolock(cbase_lock &m, lock_type type) +: m_lock(m) +{ + m_lock.lock(type); +} + +Autolock::~Autolock() +{ + m_lock.unlock(); +} diff --git a/src/shared/cbase_lock.h b/src/shared/cbase_lock.h new file mode 100644 index 0000000..2de5c7e --- /dev/null +++ b/src/shared/cbase_lock.h @@ -0,0 +1,87 @@ +/* + * sensord + * + * Copyright (c) 2013 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 _CBASE_LOCK_H_ +#define _CBASE_LOCK_H_ + +#include + +enum lock_type { + LOCK_TYPE_MUTEX, + LOCK_TYPE_READ, + LOCK_TYPE_WRITE, +}; + +#ifndef MICROSECONDS +#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec) +#endif + +#ifdef _LOCK_DEBUG +#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__) +#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__) +#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__) +#define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__) +#define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__) +#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__) +#define UNLOCK(x) (x).unlock() +#else +#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX) +#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ) +#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE) +#define LOCK(x) (x).lock() +#define LOCK_R(x) (x).lock(LOCK_TYPE_READ) +#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE) +#define UNLOCK(x) (x).unlock() +#endif + +class cbase_lock { +public: + cbase_lock(); + virtual ~cbase_lock(); + + void lock(lock_type type, const char* expr, const char *module, const char *func, int line); + void lock(lock_type type); + void unlock(void); + +protected: + virtual int lock_impl(void); + virtual int read_lock_impl(void); + virtual int write_lock_impl(void); + + virtual int try_lock_impl(void); + virtual int try_read_lock_impl(void); + virtual int try_write_lock_impl(void); + + virtual int unlock_impl(void); +private: + pthread_mutex_t m_history_mutex; + static const int OWNER_INFO_LEN = 256; + char m_owner_info[OWNER_INFO_LEN]; +}; + +class Autolock { +private: + cbase_lock& m_lock; +public: + Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line); + Autolock(cbase_lock &m, lock_type type); + ~Autolock(); +}; + +#endif /* _CBASE_LOCK_H_ */ diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index 639e9c1..f27e1d4 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -26,7 +26,7 @@ #include "sensor_log.h" #include "channel_event_handler.h" -#define SYSTEMD_SOCK_BUF_SIZE 40000 +#define SYSTEMD_SOCK_BUF_SIZE (128*1024) using namespace ipc; @@ -49,13 +49,8 @@ public: if (!m_ch->send_sync(m_msg)) return false; - if (m_msg) { + if (m_msg) m_msg->unref(); - if(m_msg->ref_count() <= 0) { - delete m_msg; - m_msg = NULL; - } - } return false; } @@ -100,14 +95,27 @@ channel::channel(socket *sock) , m_loop(NULL) , m_connected(false) { + _D("Created"); } channel::~channel() { - /* disconnect() should not be called here */ + _D("Destroyed[%llu]", m_event_id); + disconnect(); } -void channel::bind(channel_handler *handler, event_loop *loop) +uint64_t channel::bind(void) +{ + retv_if(!m_loop, 0); + m_event_id = m_loop->add_event(m_socket->get_fd(), + (EVENT_IN | EVENT_HUP | EVENT_NVAL), + dynamic_cast(m_handler)); + + _D("Bound[%llu]", m_event_id); + return m_event_id; +} + +uint64_t channel::bind(channel_handler *handler, event_loop *loop, bool loop_bind) { m_handler = handler; m_loop = loop; @@ -115,53 +123,71 @@ void channel::bind(channel_handler *handler, event_loop *loop) if (m_handler) m_handler->connected(this); -} -void channel::bind(void) -{ - ret_if(!m_loop); - m_event_id = m_loop->add_event(m_socket->get_fd(), - (EVENT_IN | EVENT_HUP | EVENT_NVAL), - dynamic_cast(m_handler)); + if (loop_bind) + bind(); + + return m_event_id; } -bool channel::connect(channel_handler *handler, event_loop *loop) +uint64_t channel::connect(channel_handler *handler, event_loop *loop, bool loop_bind) { if (!m_socket->connect()) return false; - bind(handler, loop); - return true; + bind(handler, loop, loop_bind); + + _D("Connected[%llu]", m_event_id); + return m_event_id; } void channel::disconnect(void) { - ret_if(!is_connected()); + if (!is_connected()) { + _D("Channel is not connected"); + return; + } + m_connected.store(false); + _D("Disconnecting..[%llu]", m_event_id); + if (m_handler) { m_handler->disconnected(this); m_handler = NULL; } if (m_loop) { + _D("Remove event[%llu]", m_event_id); m_loop->remove_event(m_event_id, true); m_loop = NULL; m_event_id = 0; } if (m_socket) { + _D("Release socket[%d]", m_socket->get_fd()); delete m_socket; m_socket = NULL; } + + _D("Disconnected"); } bool channel::send(message *msg) { + int retry_cnt = 0; + int cur_buffer_size = 0; + retv_if(!m_loop, false); - int cur_buffer_size = m_socket->get_current_buffer_size(); - retv_if(cur_buffer_size > SYSTEMD_SOCK_BUF_SIZE, false); + while (retry_cnt < 3) { + cur_buffer_size = m_socket->get_current_buffer_size(); + if (cur_buffer_size <= SYSTEMD_SOCK_BUF_SIZE) + break; + usleep(3000); + retry_cnt++; + } + retvm_if(retry_cnt >= 3, false, "Socket buffer[%d] is exceeded", cur_buffer_size); send_event_handler *handler = new(std::nothrow) send_event_handler(this, msg); retvm_if(!handler, false, "Failed to allocate memory"); @@ -176,20 +202,23 @@ bool channel::send(message *msg) bool channel::send_sync(message *msg) { - retv_if(!msg, false); + retvm_if(!msg, false, "Invalid message"); + retvm_if(msg->size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg->size()); ssize_t size = 0; char *buf = msg->body(); /* header */ size = m_socket->send(reinterpret_cast(msg->header()), - sizeof(message_header), true); - retv_if(size <= 0, false); - retv_if(msg->size() <= 0, true); + sizeof(message_header), true); + retvm_if(size <= 0, false, "Failed to send header"); + + /* if body size is zero, skip to send body message */ + retv_if(msg->size() == 0, true); /* body */ size = m_socket->send(buf, msg->size(), true); - retv_if(size <= 0, false); + retvm_if(size <= 0, false, "Failed to send body"); return true; } @@ -224,6 +253,11 @@ bool channel::read_sync(message &msg, bool select) } /* body */ + if (header.length >= MAX_MSG_CAPACITY) { + _E("header.length error %u", header.length); + return false; + } + if (header.length > 0) { size = m_socket->recv(&buf, header.length, select); retv_if(size <= 0, false); @@ -284,8 +318,3 @@ int channel::get_fd(void) const { return m_fd; } - -void channel::set_event_id(uint64_t id) -{ - m_event_id = id; -} diff --git a/src/shared/channel.h b/src/shared/channel.h index f8c525c..efdc481 100644 --- a/src/shared/channel.h +++ b/src/shared/channel.h @@ -38,11 +38,10 @@ public: channel(socket *sock); ~channel(); - /* TODO */ - void bind(void); - void bind(channel_handler *handler, event_loop *loop); + uint64_t bind(void); + uint64_t bind(channel_handler *handler, event_loop *loop, bool loop_bind); - bool connect(channel_handler *handler, event_loop *loop); + uint64_t connect(channel_handler *handler, event_loop *loop, bool loop_bind); void disconnect(void); bool is_connected(void); @@ -57,7 +56,6 @@ public: bool set_option(int type, int value); int get_fd(void) const; - void set_event_id(uint64_t id); private: int m_fd; diff --git a/src/shared/channel_event_handler.cpp b/src/shared/channel_event_handler.cpp index 8a6b64b..9c48c0d 100644 --- a/src/shared/channel_event_handler.cpp +++ b/src/shared/channel_event_handler.cpp @@ -45,12 +45,14 @@ bool channel_event_handler::handle(int fd, event_condition condition) return false; if (condition & (EVENT_HUP)) { + _D("The other proccess is dead"); m_ch->disconnect(); + m_ch = NULL; return false; } if (!m_ch->read_sync(msg, false)) { - m_ch->disconnect(); + m_ch = NULL; return false; } diff --git a/src/shared/cmutex.cpp b/src/shared/cmutex.cpp new file mode 100644 index 0000000..6245b6e --- /dev/null +++ b/src/shared/cmutex.cpp @@ -0,0 +1,64 @@ +/* + * sensord + * + * Copyright (c) 2013 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 + +cmutex::cmutex() +{ + pthread_mutexattr_t mutex_attr; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&m_mutex, &mutex_attr); + pthread_mutexattr_destroy(&mutex_attr); +} + +cmutex::~cmutex() +{ + pthread_mutex_destroy(&m_mutex); +} + +void cmutex::lock(void) +{ +#ifdef _LOCK_DEBUG + cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__); +#else + cbase_lock::lock(LOCK_TYPE_MUTEX); +#endif +} + +void cmutex::lock(const char* expr, const char *module, const char *func, int line) +{ + cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line); +} + +int cmutex::lock_impl(void) +{ + return pthread_mutex_lock(&m_mutex); +} + +int cmutex::try_lock_impl(void) +{ + return pthread_mutex_trylock(&m_mutex); +} + +int cmutex::unlock_impl(void) +{ + return pthread_mutex_unlock(&m_mutex); +} diff --git a/src/sensor/accel/accel_sensor.h b/src/shared/cmutex.h similarity index 58% rename from src/sensor/accel/accel_sensor.h rename to src/shared/cmutex.h index 309f91b..94aa2b6 100644 --- a/src/sensor/accel/accel_sensor.h +++ b/src/shared/cmutex.h @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2013 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. @@ -17,18 +17,26 @@ * */ -#ifndef _ACCEL_SENSOR_H_ -#define _ACCEL_SENSOR_H_ +#ifndef _CMUTEX_H_ +#define _CMUTEX_H_ -#include +#include "cbase_lock.h" -class accel_sensor : public physical_sensor { +class cmutex : public cbase_lock { public: - accel_sensor(); - ~accel_sensor(); + cmutex(); + virtual ~cmutex(); - sensor_type_t get_type(void); -}; + void lock(void); + void lock(const char* expr, const char *module, const char *func, int line); + +protected: + int lock_impl(void); + int try_lock_impl(void); + int unlock_impl(void); -#endif /* _ACCEL_SENSOR_H_ */ +private: + pthread_mutex_t m_mutex; +}; +#endif /* _CMUTEX_H_ */ diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 34cb5fc..0bc2de5 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -24,7 +24,7 @@ #include "sensor_info.h" #define SENSOR_CHANNEL_PATH "/run/.sensord.socket" -#define MAX_BUF_SIZE 10240 +#define MAX_BUF_SIZE (16*1024) /* TODO: OOP - create serializer interface */ enum cmd_type_e { @@ -53,6 +53,7 @@ enum cmd_type_e { CMD_PROVIDER_STOP, CMD_PROVIDER_ATTR_INT, CMD_PROVIDER_PUBLISH, + CMD_PROVIDER_ATTR_STR, /* Etc */ CMD_HAS_PRIVILEGE = 0x1000, @@ -110,6 +111,12 @@ typedef struct { int value; } cmd_provider_attr_int_t; +typedef struct { + int attribute; + int len; + char value[0]; +} cmd_provider_attr_str_t; + typedef struct { char sensor[NAME_MAX]; } cmd_has_privilege_t ; diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp index 881d39d..d923d78 100644 --- a/src/shared/event_loop.cpp +++ b/src/shared/event_loop.cpp @@ -95,17 +95,19 @@ event_loop::event_loop(GMainLoop *mainloop) , m_sequence(1) , m_term_fd(-1) { - if (m_mainloop) { - g_main_loop_quit(m_mainloop); - g_main_loop_unref(m_mainloop); - } - m_mainloop = mainloop; } event_loop::~event_loop() { - remove_all_events(); + _D("Destoryed"); +} + +void event_loop::set_mainloop(GMainLoop *mainloop) +{ + retm_if(!mainloop, "Invalid mainloop"); + + m_mainloop = mainloop; } uint64_t event_loop::add_event(const int fd, const event_condition cond, event_handler *handler) @@ -136,7 +138,7 @@ uint64_t event_loop::add_event(const int fd, const event_condition cond, event_h m_handlers[id] = info; - /* _D("Added[%llu](fd:%d)", id, fd); */ + /* _D("Added event[%llu], fd[%d]", id, fd); */ return id; } @@ -144,16 +146,16 @@ uint64_t event_loop::add_idle_event(unsigned int priority, idle_handler *handler { GSource *src; - retvm_if(m_terminating.load(), false, + retvm_if(m_terminating.load(), 0, "Failed to remove event, because event_loop is terminated"); src = g_idle_source_new(); - retvm_if(!src, false, "Failed to allocate memory"); + retvm_if(!src, 0, "Failed to allocate memory"); g_source_unref(src); /* Not Supported yet */ - return false; + return 0; } bool event_loop::remove_event(uint64_t id, bool close_channel) @@ -165,9 +167,9 @@ bool event_loop::remove_event(uint64_t id, bool close_channel) g_io_channel_shutdown(it->second->g_ch, TRUE, NULL); release_info(it->second); - m_handlers.erase(it); + m_handlers.erase(id); - /* _D("Removed[%llu]", id); */ + /* _D("Removed event[%llu]", id); */ return true; } @@ -182,11 +184,11 @@ void event_loop::remove_all_events(void) void event_loop::release_info(handler_info *info) { - ret_if(!info->g_ch || info->id == 0); + retm_if(!info->g_ch || info->id == 0, "Invalid handler information"); + /* _D("Releasing event..[%llu]", info->id); */ g_source_destroy(info->g_src); g_source_unref(info->g_src); - info->g_src = NULL; g_io_channel_unref(info->g_ch); info->g_ch = NULL; @@ -195,7 +197,8 @@ void event_loop::release_info(handler_info *info) info->handler = NULL; delete info; - info = NULL; + + /* _D("Released event[%llu]", info->id); */ } class terminator : public event_handler @@ -218,7 +221,7 @@ private: bool event_loop::run(int timeout) { retvm_if(!m_mainloop, false, "Invalid GMainLoop"); - retv_if(is_running(), false); + retvm_if(is_running(), false, "Already started"); if (timeout > 0) { GSource *src = g_timeout_source_new(timeout); diff --git a/src/shared/event_loop.h b/src/shared/event_loop.h index 870e6a3..f785c65 100644 --- a/src/shared/event_loop.h +++ b/src/shared/event_loop.h @@ -46,7 +46,7 @@ class event_loop; class handler_info { public: - handler_info(int64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop) + handler_info(uint64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop) : id(_id) , fd(_fd) , g_ch(_ch) @@ -72,6 +72,8 @@ public: event_loop(GMainLoop *mainloop); ~event_loop(); + void set_mainloop(GMainLoop *mainloop); + uint64_t add_event(const int fd, const event_condition cond, event_handler *handler); uint64_t add_idle_event(unsigned int priority, idle_handler *handler); diff --git a/src/shared/ipc_client.cpp b/src/shared/ipc_client.cpp index ea86baf..8c1dfa9 100644 --- a/src/shared/ipc_client.cpp +++ b/src/shared/ipc_client.cpp @@ -55,9 +55,6 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi socket *sock = NULL; channel *ch = NULL; channel_event_handler *ev_handler = NULL; - bool ret = false; - retvm_if(access(m_path.c_str(), F_OK), NULL, - "Failed to access to %s", m_path.c_str()); sock = new(std::nothrow) stream_socket(); retvm_if(!sock, NULL, "Failed to allocate memory"); @@ -78,25 +75,13 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi if (!ev_handler) { delete ch; delete sock; - _E("Faield to allocate memory"); + _E("Failed to allocate memory"); return NULL; } - ret = ch->connect(ev_handler, loop); - if(ret == false) { - delete ch; - delete sock; - delete ev_handler; - _E("Faield to connect"); - return NULL; - } + uint64_t id = ch->connect(ev_handler, loop, bind); - if (loop && bind) { - uint64_t id = loop->add_event(sock->get_fd(), - (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler); - ch->set_event_id(id); - } + _D("Connected[%llu]", id); - _I("Connected"); return ch; } diff --git a/src/shared/ipc_server.cpp b/src/shared/ipc_server.cpp index dba54f0..66431da 100644 --- a/src/shared/ipc_server.cpp +++ b/src/shared/ipc_server.cpp @@ -57,7 +57,7 @@ void ipc_server::accept(ipc::socket &cli_sock) { m_accept_sock.accept(cli_sock); - _I("Accepted[%d]", cli_sock.get_fd()); + _D("Accepted[%d]", cli_sock.get_fd()); } bool ipc_server::bind(channel_handler *handler, event_loop *loop) @@ -70,7 +70,7 @@ bool ipc_server::bind(channel_handler *handler, event_loop *loop) register_acceptor(); - _I("Bound[%d]", m_accept_sock.get_fd()); + _D("Bound[%d]", m_accept_sock.get_fd()); return true; } @@ -79,12 +79,12 @@ void ipc_server::register_channel(int fd, channel *ch) channel_event_handler *ev_handler = new(std::nothrow) channel_event_handler(ch, m_handler); retm_if(!ev_handler, "Failed to allocate memory"); - ch->bind(ev_handler, m_event_loop); - uint64_t id = m_event_loop->add_event(fd, - (event_condition)(EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler); + uint64_t id = ch->bind(ev_handler, m_event_loop, true); if (id == 0) delete ev_handler; + + _D("Registered event[%llu]", id); } void ipc_server::register_acceptor(void) @@ -109,6 +109,5 @@ bool ipc_server::close(void) m_handler = NULL; - _I("Closed"); return true; } diff --git a/src/shared/macro.h b/src/shared/macro.h index 7a5f036..0ec7bcf 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -42,7 +42,29 @@ static inline void __fclosep(FILE **f) fclose(*f); } +static inline void int_to_bytes(int value, int width, char data[]) +{ + /* Big-endian */ + for (int i = width - 1; i >= 0; i--) { + data[i] = (value & 0xff); + value = value >> 8; + } +} + +static inline unsigned int bytes_to_uint(char data[], int &cursor, int width) +{ + unsigned int sum = 0; + + /* Big-endian */ + for (int i = 0; i < width; ++i) + sum = (sum << 8) + (unsigned char)data[cursor++]; + + return sum; +} + #define _cleanup_free_ _cleanup_(__freep) #define _cleanup_close_ _cleanup_(__closep) #define _cleanup_fclose_ _cleanup_(__fclosep) +#define GET_BYTES(value, width, data) int_to_bytes(value, width, data) +#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/src/shared/message.cpp b/src/shared/message.cpp old mode 100755 new mode 100644 index f53dd5e..d7455eb --- a/src/shared/message.cpp +++ b/src/shared/message.cpp @@ -21,8 +21,6 @@ #include #include -#include - using namespace ipc; @@ -33,37 +31,31 @@ static std::atomic sequence(0); message::message(size_t capacity) : m_size(0) , m_capacity(capacity) -, m_msg(new(std::nothrow) char[sizeof(char) * capacity]) +, m_msg((char *)malloc(sizeof(char) * capacity)) , ref_cnt(0) { m_header.id = sequence++; m_header.type = UNDEFINED_TYPE; m_header.length = m_size; m_header.err = 0; - - for (int i = 0; i < MAX_HEADER_RESERVED; ++i) - m_header.ancillary[i] = NULL; } message::message(const void *msg, size_t sz) : m_size(sz) , m_capacity(sz) -, m_msg(new(std::nothrow) char[sizeof(char) * sz]) +, m_msg((char *)msg) , ref_cnt(0) { m_header.id = sequence++; m_header.type = UNDEFINED_TYPE; m_header.length = m_size; m_header.err = 0; - ::memcpy(m_msg, msg, sz); - for (int i = 0; i < MAX_HEADER_RESERVED; ++i) - m_header.ancillary[i] = NULL; } message::message(const message &msg) : m_size(msg.m_size) , m_capacity(msg.m_capacity) -, m_msg(new(std::nothrow) char[(sizeof(char) * msg.m_capacity)]) +, m_msg((char *)malloc(sizeof(char) * msg.m_capacity)) , ref_cnt(0) { ::memcpy(&m_header, &msg.m_header, sizeof(message_header)); @@ -80,15 +72,12 @@ message::message(int error) m_header.type = UNDEFINED_TYPE; m_header.length = 0; m_header.err = error; - - for (int i = 0; i < MAX_HEADER_RESERVED; ++i) - m_header.ancillary[i] = NULL; } message::~message() { - if (m_msg) { - delete [] m_msg; + if (m_msg && ref_cnt == 0) { + free(m_msg); m_msg = NULL; } } @@ -146,12 +135,12 @@ void message::unref(void) { ref_cnt--; - /*if (ref_cnt > 0 || !m_msg) + if (ref_cnt > 0 || !m_msg) return; - delete [] m_msg; + free(m_msg); m_msg = NULL; - delete this;*/ + delete this; } int message::ref_count(void) diff --git a/src/shared/message.h b/src/shared/message.h index 3b8fb67..118cf13 100644 --- a/src/shared/message.h +++ b/src/shared/message.h @@ -23,7 +23,7 @@ #include /* size_t */ #include -#define MAX_MSG_CAPACITY 10240 +#define MAX_MSG_CAPACITY (16*1024) #define MAX_HEADER_RESERVED 3 namespace ipc { diff --git a/src/shared/sensor_log.h b/src/shared/sensor_log.h index f2e0d49..46dcd32 100644 --- a/src/shared/sensor_log.h +++ b/src/shared/sensor_log.h @@ -67,4 +67,9 @@ #define LOG_DUMP(fp, fmt, arg...) \ do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0) +#define log_oom() ({ \ + _E("Out of memory"); \ + -ENOMEM;}) + + #endif /* __SENSOR_LOG_H__ */ diff --git a/src/shared/sensor_types_private.h b/src/shared/sensor_types_private.h index d0ed9e2..b76a6fe 100644 --- a/src/shared/sensor_types_private.h +++ b/src/shared/sensor_types_private.h @@ -34,6 +34,9 @@ #define PRIVILEGE_LOCATION_STR "location" #define PRIVILEGE_LOCATION_URI "http://tizen.org/privilege/location" +#define PRIVILEGE_PLATFORM_STR "platform" +#define PRIVILEGE_PLATFORM_URI "http://tizen.org/privilege/internal/default/platform" + #define URI_PRIV_INDEX 4 #define URI_SENSOR_TYPE_INDEX 5 diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 9bae0e6..b6e2eb2 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -62,6 +62,8 @@ static std::map types = { {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/general/gyroscope_rotation_vector"}, {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/general/geomagnetic_rotation_vector"}, + {SIGNIFICANT_MOTION_SENSOR, "http://tizen.org/sensor/general/significant_motion"}, + {HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/human_pedometer"}, {HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_monitor"}, {HUMAN_SLEEP_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_detector"}, @@ -76,7 +78,6 @@ static std::map types = { {EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.rowing"}, {EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.stepper"}, - {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/healthinfo/external_exercise"}, {FUSION_SENSOR, "http://tizen.org/sensor/general/fusion"}, {AUTO_ROTATION_SENSOR, "http://tizen.org/sensor/general/auto_rotation"}, @@ -86,13 +87,18 @@ static std::map types = { {GESTURE_WRIST_UP_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_up"}, {GESTURE_WRIST_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_down"}, {GESTURE_MOVEMENT_STATE_SENSOR, "http://tizen.org/sensor/general/gesture_movement_state"}, + {GESTURE_PICK_UP_SENSOR, "http://tizen.org/sensor/general/gesture_pick_up"}, {GESTURE_FACE_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_face_down"}, {ACTIVITY_TRACKER_SENSOR, "http://tizen.org/sensor/general/activity_tracker"}, {ACTIVITY_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/activity_level_monitor"}, {GPS_BATCH_SENSOR, "http://tizen.org/sensor/location/gps_batch"}, + {PPG_BATCH_SENSOR, "http://tizen.org/sensor/healthinfo/ppg_batch"}, + {GPS_TIMESYNC_SENSOR, "http://tizen.org/sensor/location/gps_timesync"}, {HRM_CTRL_SENSOR, "http://tizen.org/sensor/general/hrm_ctrl"}, + {REG_CTRL_SENSOR, "http://tizen.org/sensor/general/reg_ctrl"}, + {GPS_CTRL_SENSOR, "http://tizen.org/sensor/general/gps_ctrl"}, {WEAR_STATUS_SENSOR, "http://tizen.org/sensor/general/wear_status"}, {WEAR_ON_MONITOR_SENSOR, "http://tizen.org/sensor/general/wear_on_monitor"}, @@ -107,6 +113,17 @@ static std::map types = { {PRESSURE_INDICATOR_SENSOR, "http://tizen.org/sensor/general/pressure_indicator"}, {PRESSURE_ALERT_SENSOR, "http://tizen.org/sensor/general/pressure_alert"}, {HR_CALORIE_SENSOR, "http://tizen.org/sensor/healthinfo/hr_calorie"}, + {SWIMMING_TRACKER_SENSOR, "http://tizen.org/sensor/healthinfo/swimming_tracker"}, + {SWIMMING_OUTDOOR_SENSOR, "http://tizen.org/sensor/healthinfo/swimming_outdoor"}, + {AUTO_SWIMMING_SENSOR, "http://tizen.org/sensor/healthinfo/auto_swimming"}, + {INACTIVITY_DETECTOR_SENSOR, "http://tizen.org/sensor/general/inactivity_detector"}, + {STRESS_TRACKER_SENSOR, "http://tizen.org/sensor/healthinfo/stress_tracker"}, + {FAKE_MOTION_SENSOR, "http://tizen.org/sensor/general/fake_motion"}, + {GEOFENCE_SENSOR, "http://tizen.org/sensor/general/geofence"}, + {INACTIVITY_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/inactivity_detector"}, + {HRM_BP_SENSOR, "http://tizen.org/sensor/healthinfo/hrm_bp"}, + {ECG_SENSOR, "http://tizen.org/sensor/healthinfo/ecg"}, + {FALL_DETECTION_SENSOR, "http://tizen.org/sensor/general/fall_detection"}, {CONTEXT_SENSOR, "http://tizen.org/sensor/general/context"}, {MOTION_SENSOR, "http://tizen.org/sensor/general/motion"}, @@ -153,6 +170,8 @@ const char *sensor::utils::get_privilege(std::string uri) return PRIVILEGE_HEALTHINFO_URI; else if (uri.substr(start + 1, size) == PRIVILEGE_LOCATION_STR) return PRIVILEGE_LOCATION_URI; + else if (uri.substr(start + 1, size) == PRIVILEGE_PLATFORM_STR) + return PRIVILEGE_PLATFORM_URI; return ""; } diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp index 8849181..6d11076 100644 --- a/src/shared/socket.cpp +++ b/src/shared/socket.cpp @@ -29,7 +29,7 @@ #include "sensor_log.h" -#define SOCK_TIMEOUT 3 +#define SOCK_TIMEOUT 10 using namespace ipc; @@ -169,8 +169,6 @@ bool socket::connect(void) return false; } - _D("Connected[%d]", m_sock_fd); - return true; } @@ -206,8 +204,6 @@ bool socket::bind(void) return false; } - _D("Bound to path[%d, %s]", m_sock_fd, m_path.c_str()); - return true; } @@ -246,8 +242,6 @@ bool socket::accept(socket &client_sock) client_sock.set_fd(fd); /* TODO : socket type should be adjusted here */ - _D("Accepted[%d, %d]", m_sock_fd, fd); - return true; } @@ -327,12 +321,10 @@ ssize_t socket::recv(void* buffer, size_t size, bool select) const bool socket::create_by_type(const std::string &path, int type) { m_sock_fd = ::create_systemd_socket(path, type); - if (m_sock_fd < 0) { - _D("Creating the UDS instead of systemd socket.."); + if (m_sock_fd < 0) m_sock_fd = create_unix_socket(type); - } else { + else m_listening.store(true); - } retvm_if((m_sock_fd < 0), false, "Failed to create socket"); @@ -343,8 +335,6 @@ bool socket::create_by_type(const std::string &path, int type) /* TODO */ /*retvm_if(!set_reuse_addr(), false, "Failed to reuse address"); */ - _D("Created[%d]", m_sock_fd); - m_path = path; return true; -- 2.7.4 From fa62ccd81a86b1cc21dd99ee314b4703c7455439 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Tue, 12 Nov 2019 19:05:47 +0900 Subject: [PATCH 11/16] Add sensor APIs related to batch event * This patch also includes new tests to test batch events related APIs at sensorctl Change-Id: If59c1b43b10c6b39bf72687bfb67eb9e305fe62b Signed-off-by: Boram Bae --- include/sensor_hal_types.h | 1 - include/sensor_internal.h | 23 ++++++ src/client-dummy/client_dummy.cpp | 15 ++++ src/client/sensor_internal.cpp | 100 ++++++++++++++-------- src/client/sensor_provider.cpp | 15 +++- src/client/sensor_provider.h | 3 +- src/fusion-sensor/pedometer/pedometer.h | 1 - src/fusion-sensor/pedometer/step_detection.h | 1 - src/sensorctl/sensor_adapter.cpp | 14 +++- src/sensorctl/sensor_adapter.h | 32 +++++-- src/sensorctl/sensorctl.cpp | 13 ++- src/sensorctl/testcase/sensor_provider.cpp | 119 +++++++++++++++++++++++++++ src/sensorctl/tester_manual.cpp | 17 +++- src/server/sensor_handler.cpp | 8 +- src/server/sensor_listener_proxy.cpp | 2 +- src/server/server_channel_handler.cpp | 8 +- 16 files changed, 312 insertions(+), 60 deletions(-) diff --git a/include/sensor_hal_types.h b/include/sensor_hal_types.h index 1dfe2d4..217efb8 100644 --- a/include/sensor_hal_types.h +++ b/include/sensor_hal_types.h @@ -148,7 +148,6 @@ typedef enum { SENSOR_DEVICE_GSR, SENSOR_DEVICE_SIMSENSE, SENSOR_DEVICE_PPG, - } sensor_device_type; /* diff --git a/include/sensor_internal.h b/include/sensor_internal.h index d9f2b18..cb7eac3 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -38,6 +38,7 @@ extern "C" #endif typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); +typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t* events[], int events_count, void *user_data); typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data); typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data); @@ -240,6 +241,18 @@ bool sensord_disconnect(int handle); bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data); /** + * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor. + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] event_type an event type to register + * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. + * @param[in] cb a callback which is called when a given event occurs + * @param[in] user_data the callback is called with user_data + * @return true on success, otherwise false. + */ +bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data); + +/** * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor. * * @param[in] handle a handle represensting a connected context sensor. @@ -263,6 +276,15 @@ bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned in bool sensord_unregister_event(int handle, unsigned int event_type); /** + * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent. + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] event_type an event type to unregister. + * @return true on success, otherwise false. + */ +bool sensord_unregister_events(int handle, unsigned int event_type); + +/** * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed. * * @param[in] handle a handle represensting a connected sensor. @@ -427,6 +449,7 @@ typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, i int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data); int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data); +int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count); /* Deprecated */ typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data); diff --git a/src/client-dummy/client_dummy.cpp b/src/client-dummy/client_dummy.cpp index ee8cde3..074277e 100644 --- a/src/client-dummy/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -133,6 +133,16 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) return false; } +API bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_events(int handle, unsigned int event_type) +{ + return false; +} + API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) { return false; @@ -299,3 +309,8 @@ API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data { return OP_ERROR; } + +API int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count) +{ + return OP_ERROR; +} diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index a0f1e08..d9bd489 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -42,10 +42,12 @@ using namespace sensor; typedef struct { int listener_id; - sensor_cb_t cb; + void* cb; + bool is_events_cb; sensor_accuracy_changed_cb_t acc_cb; sensor_info *sensor; - sensor_data_t *data; + char* data; + size_t data_size; void *user_data; } callback_info_s; @@ -63,8 +65,20 @@ static gboolean callback_dispatcher(gpointer data) if (info->sensor) event_type = CONVERT_TYPE_EVENT(info->sensor->get_type()); - if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) - info->cb(info->sensor, event_type, info->data, info->user_data); + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + if (info->is_events_cb) { + size_t element_size = sizeof(sensor_data_t); + size_t count = info->data_size / element_size; + sensor_data_t *events[count]; + char* p = (char*)info->data; + for (size_t i = 0 ; i < count; ++i) { + events[i] = (sensor_data_t *)(p + i * element_size); + } + ((sensor_events_cb_t)info->cb)(info->sensor, event_type, events, count, info->user_data); + } else { + ((sensor_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, info->user_data); + } + } delete [] info->data; delete info; @@ -77,8 +91,10 @@ static gboolean accuracy_callback_dispatcher(gpointer data) AUTOLOCK(lock); - if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) - info->acc_cb(info->sensor, info->data->timestamp, info->data->accuracy, info->user_data); + if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + sensor_data_t * data = (sensor_data_t *)info->data; + info->acc_cb(info->sensor, data->timestamp, data->accuracy, info->user_data); + } delete [] info->data; delete info; @@ -88,11 +104,12 @@ static gboolean accuracy_callback_dispatcher(gpointer data) class sensor_event_handler : public ipc::channel_handler { public: - sensor_event_handler(int id, sensor_t sensor, sensor_cb_t cb, void *user_data) + sensor_event_handler(int id, sensor_t sensor, void* cb, bool is_events_cb, void *user_data) : m_listener_id(id) , m_sensor(reinterpret_cast(sensor)) , m_cb(cb) , m_user_data(user_data) + , m_is_events_cb(is_events_cb) {} void connected(ipc::channel *ch) {} @@ -100,16 +117,19 @@ public: void read(ipc::channel *ch, ipc::message &msg) { callback_info_s *info; - sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()]; + auto size = msg.size(); + char *data = new(std::nothrow) char[size]; - memcpy(data, msg.body(), msg.size()); + memcpy(data, msg.body(), size); info = new(std::nothrow) callback_info_s(); info->listener_id = m_listener_id; info->cb = m_cb; info->sensor = m_sensor; info->data = data; + info->data_size = size; info->user_data = m_user_data; + info->is_events_cb = m_is_events_cb; g_idle_add(callback_dispatcher, info); } @@ -120,8 +140,9 @@ public: private: int m_listener_id; sensor_info *m_sensor; - sensor_cb_t m_cb; + void* m_cb; void *m_user_data; + bool m_is_events_cb; }; class sensor_accuracy_handler : public ipc::channel_handler @@ -139,7 +160,7 @@ public: void read(ipc::channel *ch, ipc::message &msg) { callback_info_s *info; - sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()]; + char *data = new(std::nothrow) char[msg.size()]; memcpy(data, msg.body(), msg.size()); @@ -341,8 +362,8 @@ API bool sensord_disconnect(int handle) return true; } -API bool sensord_register_event(int handle, unsigned int event_type, - unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data) +static inline bool sensord_register_event_impl(int handle, unsigned int event_type, + unsigned int interval, unsigned int max_batch_latency, void* cb, bool is_events_callback, void *user_data) { sensor::sensor_listener *listener; int prev_interval; @@ -370,7 +391,7 @@ API bool sensord_register_event(int handle, unsigned int event_type, return false; } - handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, user_data); + handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, is_events_callback, user_data); if (!handler) { listener->set_max_batch_latency(prev_max_batch_latency); listener->set_interval(prev_interval); @@ -385,7 +406,13 @@ API bool sensord_register_event(int handle, unsigned int event_type, return true; } -API bool sensord_unregister_event(int handle, unsigned int event_type) +API bool sensord_register_event(int handle, unsigned int event_type, + unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data) +{ + return sensord_register_event_impl(handle, event_type, interval, max_batch_latency, (void*)cb, false, user_data); +} + +static inline bool sensord_unregister_event_imple(int handle) { sensor::sensor_listener *listener; @@ -403,6 +430,21 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) return true; } +API bool sensord_unregister_event(int handle, unsigned int event_type) +{ + return sensord_unregister_event_imple(handle); +} + +API bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data) +{ + return sensord_register_event_impl(handle, event_type, 0, max_batch_latency, (void*)cb, true, user_data); +} + +API bool sensord_unregister_events(int handle, unsigned int event_type) +{ + return sensord_unregister_event_imple(handle); +} + API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) { sensor::sensor_listener *listener; @@ -888,9 +930,18 @@ API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data sensor_provider *p = static_cast(provider); /* TODO: synchronous call is enough? */ - return p->publish(&data, sizeof(data)); + return p->publish(data); } +API int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count) +{ + retvm_if(!provider, -EINVAL, "Invalid paramter"); + + sensor_provider *p = static_cast(provider); + + return p->publish(events, count); +}; + /* deperecated */ API sensor_t sensord_get_sensor(sensor_type_t type) { @@ -957,23 +1008,6 @@ API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege) return true; } -static std::unordered_map external_providers; -static int provider_id = 0; - -typedef struct external_cb_info_s { - int id; - sensor_external_command_cb_t cb; - void *user_data; -} external_cb_info_s; - -static void external_attr_cb(sensord_provider_h provider, int attribute, const char *data, int cnt, void *user_data) -{ - external_cb_info_s *info = (external_cb_info_s *)user_data; - - if (info->cb) - info->cb(info->id, data, cnt, info->user_data); -} - /* deprecated */ API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data) { diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index 7afe921..a90f7c2 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -168,11 +168,22 @@ void sensor_provider::restore(void) _D("Restored provider[%s]", get_uri()); } -int sensor_provider::publish(sensor_data_t *data, int len) +int sensor_provider::publish(const sensor_data_t &data) { ipc::message msg; msg.set_type(CMD_PROVIDER_PUBLISH); - msg.enclose((const char *)data, len); + msg.enclose((const void *)(&data), sizeof(data)); + + m_channel->send_sync(&msg); + + return OP_SUCCESS; +} + +int sensor_provider::publish(const sensor_data_t data[], const int count) +{ + ipc::message msg; + msg.set_type(CMD_PROVIDER_PUBLISH); + msg.enclose((const void *)data, sizeof(sensor_data_t) * count); m_channel->send_sync(&msg); diff --git a/src/client/sensor_provider.h b/src/client/sensor_provider.h index 7b26754..974c796 100644 --- a/src/client/sensor_provider.h +++ b/src/client/sensor_provider.h @@ -49,7 +49,8 @@ public: void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data); void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data); - int publish(sensor_data_t *data, int len); + int publish(const sensor_data_t &data); + int publish(const sensor_data_t data[], const int count); private: class channel_handler; diff --git a/src/fusion-sensor/pedometer/pedometer.h b/src/fusion-sensor/pedometer/pedometer.h index f990906..9e94ec5 100644 --- a/src/fusion-sensor/pedometer/pedometer.h +++ b/src/fusion-sensor/pedometer/pedometer.h @@ -73,7 +73,6 @@ private: bool m_some_speed; sensor_frequency_compensator m_acceleration_compensator; - }; #endif /* __PEDOMETER_H__ */ diff --git a/src/fusion-sensor/pedometer/step_detection.h b/src/fusion-sensor/pedometer/step_detection.h index 613751c..b65cadd 100644 --- a/src/fusion-sensor/pedometer/step_detection.h +++ b/src/fusion-sensor/pedometer/step_detection.h @@ -79,7 +79,6 @@ private: /************************************************************************ */ bool is_slow_step(void); - }; #endif /* __STEP_DETECTION_H__ */ diff --git a/src/sensorctl/sensor_adapter.cpp b/src/sensorctl/sensor_adapter.cpp index 13bc4e5..979db25 100644 --- a/src/sensorctl/sensor_adapter.cpp +++ b/src/sensorctl/sensor_adapter.cpp @@ -27,6 +27,8 @@ #define SENSOR_EVENT(type) ((type) << 16 | 0x1) +bool sensor_adapter::is_batch_mode = false; + bool sensor_adapter::is_supported(sensor_type_t type) { sensor_t sensor; @@ -79,7 +81,11 @@ bool sensor_adapter::start(sensor_info info, int &handle) handle = sensord_connect(sensors[info.index]); ASSERT_GE(handle, 0); - ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL); + if (is_batch_mode) { + ret = sensord_register_events(handle, SENSOR_EVENT(info.type), info.batch_latency, info.events_cb, NULL); + } else { + ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL); + } ASSERT_TRUE(ret); ret = sensord_start(handle, info.powersave); @@ -97,7 +103,11 @@ bool sensor_adapter::stop(sensor_info info, int handle) ret = sensord_stop(handle); EXPECT_TRUE(ret); - ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type)); + if (is_batch_mode) { + ret = sensord_unregister_events(handle, SENSOR_EVENT(info.type)); + } else { + ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type)); + } EXPECT_TRUE(ret); ret = sensord_disconnect(handle); diff --git a/src/sensorctl/sensor_adapter.h b/src/sensorctl/sensor_adapter.h index 631c4e5..c470af1 100644 --- a/src/sensorctl/sensor_adapter.h +++ b/src/sensorctl/sensor_adapter.h @@ -23,6 +23,9 @@ class sensor_info { public: + sensor_info() + { } + sensor_info(sensor_type_t _type, int _index, int _interval, int _batch_latency, int _powersave, sensor_cb_t _cb, void *_user_data) : type(_type) , index(_index) @@ -33,13 +36,27 @@ public: , user_data(_user_data) { } - sensor_type_t type; - int index; - int interval; - int batch_latency; - int powersave; - sensor_cb_t cb; - void *user_data; + sensor_info(sensor_type_t _type, int _index, int _interval, int _batch_latency, int _powersave, sensor_events_cb_t _events_cb, void *_user_data) + : type(_type) + , index(_index) + , interval(_interval) + , batch_latency(_batch_latency) + , powersave(_powersave) + , events_cb(_events_cb) + , user_data(_user_data) + { } + + sensor_type_t type { UNKNOWN_SENSOR }; + int index { 0 }; + int interval { 0 }; + int batch_latency { 0 }; + int powersave { 0 }; + union + { + sensor_cb_t cb { NULL }; + sensor_events_cb_t events_cb; + }; + void *user_data { NULL }; }; class sensor_adapter { @@ -59,4 +76,5 @@ public: static bool get_data(int handle, sensor_type_t type, sensor_data_t &data); static bool flush(int handle); + static bool is_batch_mode; }; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp index a35e286..19ae106 100644 --- a/src/sensorctl/sensorctl.cpp +++ b/src/sensorctl/sensorctl.cpp @@ -28,6 +28,7 @@ #include "injector.h" #include "info.h" #include "loopback.h" +#include "sensor_adapter.h" static sensor_manager *manager; @@ -45,14 +46,18 @@ static sensor_manager *create_manager(char *command) { sensor_manager *manager = NULL; - if (!strcmp(command, "test")) + if (!strcmp(command, "test")) { manager = new(std::nothrow) tester_manager; - if (!strcmp(command, "inject")) + } else if (!strcmp(command, "batch_mode_test")) { + sensor_adapter::is_batch_mode = true; + manager = new(std::nothrow) tester_manager; + } else if (!strcmp(command, "inject")) { manager = new(std::nothrow) injector_manager; - if (!strcmp(command, "info")) + } else if (!strcmp(command, "info")) { manager = new(std::nothrow) info_manager; - if (!strcmp(command, "loopback")) + } else if (!strcmp(command, "loopback")) { manager = new(std::nothrow) loopback_manager; + } if (!manager) { _E("failed to allocate memory for manager\n"); diff --git a/src/sensorctl/testcase/sensor_provider.cpp b/src/sensorctl/testcase/sensor_provider.cpp index 9c76c21..bcd5101 100644 --- a/src/sensorctl/testcase/sensor_provider.cpp +++ b/src/sensorctl/testcase/sensor_provider.cpp @@ -27,9 +27,14 @@ #include "test_bench.h" #define MYSENSOR_URI "http://example.org/sensor/general/mysensor/mysensor" +#define MYSENSOR_BATCH_URI "http://example.org/sensor/general/mysensor/mysensor-batch" + #define MYSENSOR_NAME "mysensor" +#define MYSENSOR_BATCH_NAME "mysensor-batch" #define MYSENSOR_VENDOR "tizen" +#define NUMBER_OF_EVENT 100 + static bool started = false; static bool added = false; static bool called = false; @@ -39,6 +44,16 @@ static void event_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *da _I("[%llu] %f %f %f\n", data->timestamp, data->values[0], data->values[1], data->values[2]); } +static void events_cb(sensor_t sensor, unsigned int event_type, sensor_data_t* datas[], int events_count, void *user_data) +{ + for (int i = 0 ; i < events_count; i++) { + _I("[%llu]", datas[i]->timestamp); + for (int j = 0; j < datas[i]->value_count; j++) + _I(" %f", datas[i]->values[j]); + _I("\n"); + } +} + static void start_cb(sensord_provider_h provider, void *user_data) { started = true; @@ -75,6 +90,28 @@ static gboolean publish(gpointer gdata) return TRUE; } +static gboolean publish_batch_event(gpointer gdata) +{ + if (!started) return FALSE; + + sensord_provider_h *provider = reinterpret_cast(gdata); + + sensor_data_t data[NUMBER_OF_EVENT]; + + for (int i = 0 ; i < NUMBER_OF_EVENT; i++) { + data[i].accuracy = 3; + data[i].timestamp = sensor::utils::get_timestamp(); + data[i].value_count = 3; + data[i].values[0] = i; + data[i].values[1] = i; + data[i].values[2] = i; + } + sensord_provider_publish_events(provider, data, NUMBER_OF_EVENT); + _N("[ PUBLISH ] %d events\n", NUMBER_OF_EVENT); + g_timeout_add_seconds(1, publish_batch_event, provider); + return FALSE; +} + static void add_mysensor(void) { sensord_provider_h provider; @@ -237,3 +274,85 @@ TESTCASE(skip_sensor_provider, mysensor_with_listener_p_1) return true; } +/* TODO: change it from manual test to auto-test */ +TESTCASE(skip_sensor_provider, mysensor_batch_p) +{ + int err = 0; + sensor_t sensor; + sensord_provider_h provider; + + err = sensord_create_provider(MYSENSOR_BATCH_URI, &provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_name(provider, MYSENSOR_BATCH_NAME); + ASSERT_EQ(err, 0); + err = sensord_provider_set_vendor(provider, MYSENSOR_VENDOR); + ASSERT_EQ(err, 0); + err = sensord_provider_set_range(provider, 0.0f, 1.0f); + ASSERT_EQ(err, 0); + err = sensord_provider_set_resolution(provider, 0.01f); + ASSERT_EQ(err, 0); + + err = sensord_add_provider(provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_start_cb(provider, start_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_stop_cb(provider, stop_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_interval_changed_cb(provider, interval_cb, NULL); + ASSERT_EQ(err, 0); + + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &sensor); + ASSERT_EQ(err, 0); + + g_timeout_add_seconds(1, publish_batch_event, provider); + mainloop::run(); + + err = sensord_remove_provider(provider); + ASSERT_EQ(err, 0); + err = sensord_destroy_provider(provider); + ASSERT_EQ(err, 0); + + return true; +} + + +/* TODO: change it from manual test to auto-test */ +TESTCASE(skip_sensor_provider, mysensor_batch_with_listener_p_1) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ASSERT_EQ(err, 0); + + ret = sensord_register_events(handle, 1, 100, events_cb, NULL); + ASSERT_TRUE(ret); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + ret = sensord_change_event_interval(handle, 0, 100); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_unregister_events(handle, 1); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} diff --git a/src/sensorctl/tester_manual.cpp b/src/sensorctl/tester_manual.cpp index 7d8c311..1e48398 100644 --- a/src/sensorctl/tester_manual.cpp +++ b/src/sensorctl/tester_manual.cpp @@ -122,19 +122,34 @@ static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *dat _N("\n"); } +static void test_events_cb(sensor_t sensor, unsigned int event_type, sensor_data_t* datas[], int events_count, void *user_data) +{ + for (int i = 0 ; i < events_count; i++) { + _N("%llu ", datas[i]->timestamp); + for (int j = 0; j < datas[i]->value_count; j++) + _N(" %10f", datas[i]->values[j]); + _N("\n"); + } +} + TESTCASE(manual_test, sensor) { int handle; bool ret; int index = 0; sensor_data_t data; + sensor_info info; if (sensor_adapter::get_count(stype) > 1) { _N("There are more than 2 sensors. please enter the index : "); std::cin >> index; } - sensor_info info(stype, index, interval, latency, powersave, test_cb, NULL); + if (sensor_adapter::is_batch_mode) { + info = sensor_info(stype, index, interval, latency, powersave, test_events_cb, NULL); + } else { + info = sensor_info(stype, index, interval, latency, powersave, test_cb, NULL); + } ret = sensor_adapter::start(info, handle); ASSERT_TRUE(ret); diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index 3939d04..e969aae 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -102,8 +102,12 @@ uint32_t sensor_handler::observer_count(void) void sensor_handler::set_cache(sensor_data_t *data, int size) { - if (m_last_data == NULL) { - m_last_data = (sensor_data_t*)malloc(size); + if (m_last_data_size != size) { + m_last_data_size = size; + if (m_last_data) { + free(m_last_data); + } + m_last_data = (sensor_data_t*)malloc(m_last_data_size); retm_if(m_last_data == NULL, "Memory allocation failed"); } diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 77a2ff7..44f6c4f 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -107,7 +107,7 @@ int sensor_listener_proxy::start(bool policy) _D("Listener[%d] try to start", get_id()); ret = sensor->start(this); - retv_if (ret < 0, OP_ERROR); + retv_if(ret < 0, OP_ERROR); /* m_started is changed only when it is explicitly called by user, * not automatically determined by any pause policy. */ diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 780cc3d..c897243 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -330,13 +330,13 @@ int server_channel_handler::provider_publish(channel *ch, message &msg) auto it = m_app_sensors.find(ch); retv_if(it == m_app_sensors.end(), -EINVAL); - sensor_data_t *data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + size_t size = msg.header()->length; + void *data = (void *)malloc(size); retvm_if(!data, -ENOMEM, "Failed to allocate memory"); - msg.disclose((char *)data); - - it->second->publish(data, sizeof(sensor_data_t)); + msg.disclose(data); + it->second->publish((sensor_data_t*)data, size); return OP_SUCCESS; } -- 2.7.4 From 4856203b8ce91fd318a0d250f0d2eba8a1bb4e47 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Thu, 21 Nov 2019 10:14:11 +0900 Subject: [PATCH 12/16] Add new APIs skeleton to announce that attribute changed * Remove a build warning * Add sensorctl tests * Refactor some codes Change-Id: I048fa208303c18e7a52b7918c00beb3556e993d3 Signed-off-by: Boram Bae --- include/sensor_internal.h | 9 ++ src/client-dummy/client_dummy.cpp | 20 ++++ src/client/sensor_internal.cpp | 138 +++++++++++----------- src/client/sensor_reader.cpp | 2 +- src/sensorctl/testcase/sensor_listener.cpp | 181 +++++++++++++++++++++++++++++ 5 files changed, 282 insertions(+), 68 deletions(-) diff --git a/include/sensor_internal.h b/include/sensor_internal.h index cb7eac3..5727e23 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -41,6 +41,8 @@ typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_dat typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t* events[], int events_count, void *user_data); typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data); typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data); +typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *data); +typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *data); /** * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors. @@ -302,6 +304,13 @@ bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, v */ bool sensord_unregister_accuracy_cb(int handle); +bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data); + +bool sensord_unregister_attribute_int_changed_cb(int handle); + +bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data); + +bool sensord_unregister_attribute_str_changed_cb(int handle); /** * @brief Start listening events with a connected sensor. * diff --git a/src/client-dummy/client_dummy.cpp b/src/client-dummy/client_dummy.cpp index 074277e..d84e2ad 100644 --- a/src/client-dummy/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -153,6 +153,26 @@ API bool sensord_unregister_accuracy_cb(int handle) return false; } +API bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_attribute_int_changed_cb(int handle) +{ + return false; +} + +API bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_attribute_str_changed_cb(int handle) +{ + return false; +} + API bool sensord_start(int handle, int option) { return false; diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index d9bd489..0bad9a8 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -42,20 +42,20 @@ using namespace sensor; typedef struct { int listener_id; - void* cb; - bool is_events_cb; - sensor_accuracy_changed_cb_t acc_cb; sensor_info *sensor; + void* cb; char* data; size_t data_size; void *user_data; } callback_info_s; +typedef GSourceFunc callback_dispatcher_t; + static sensor::sensor_manager manager; static std::unordered_map listeners; static cmutex lock; -static gboolean callback_dispatcher(gpointer data) +static gboolean sensor_events_callback_dispatcher(gpointer data) { int event_type = 0; callback_info_s *info = (callback_info_s *)data; @@ -66,18 +66,33 @@ static gboolean callback_dispatcher(gpointer data) event_type = CONVERT_TYPE_EVENT(info->sensor->get_type()); if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { - if (info->is_events_cb) { - size_t element_size = sizeof(sensor_data_t); - size_t count = info->data_size / element_size; - sensor_data_t *events[count]; - char* p = (char*)info->data; - for (size_t i = 0 ; i < count; ++i) { - events[i] = (sensor_data_t *)(p + i * element_size); - } - ((sensor_events_cb_t)info->cb)(info->sensor, event_type, events, count, info->user_data); - } else { - ((sensor_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, info->user_data); + size_t element_size = sizeof(sensor_data_t); + size_t count = info->data_size / element_size; + sensor_data_t *events[count]; + char* p = (char*)info->data; + for (size_t i = 0 ; i < count; ++i) { + events[i] = (sensor_data_t *)(p + i * element_size); } + ((sensor_events_cb_t)info->cb)(info->sensor, event_type, events, count, info->user_data); + } + + delete [] info->data; + delete info; + return FALSE; +} + +static gboolean sensor_event_callback_dispatcher(gpointer data) +{ + int event_type = 0; + callback_info_s *info = (callback_info_s *)data; + + AUTOLOCK(lock); + + if (info->sensor) + event_type = CONVERT_TYPE_EVENT(info->sensor->get_type()); + + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + ((sensor_cb_t)info->cb)(info->sensor, event_type, (sensor_data_t*)info->data, info->user_data); } delete [] info->data; @@ -85,15 +100,15 @@ static gboolean callback_dispatcher(gpointer data) return FALSE; } -static gboolean accuracy_callback_dispatcher(gpointer data) +static gboolean sensor_accuracy_changed_callback_dispatcher(gpointer data) { callback_info_s *info = (callback_info_s *)data; AUTOLOCK(lock); - if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { sensor_data_t * data = (sensor_data_t *)info->data; - info->acc_cb(info->sensor, data->timestamp, data->accuracy, info->user_data); + ((sensor_accuracy_changed_cb_t)info->cb)(info->sensor, data->timestamp, data->accuracy, info->user_data); } delete [] info->data; @@ -101,15 +116,15 @@ static gboolean accuracy_callback_dispatcher(gpointer data) return FALSE; } -class sensor_event_handler : public ipc::channel_handler +class sensor_listener_handler : public ipc::channel_handler { public: - sensor_event_handler(int id, sensor_t sensor, void* cb, bool is_events_cb, void *user_data) + sensor_listener_handler(int id, sensor_t sensor, void* cb, void *user_data, callback_dispatcher_t dispatcher) : m_listener_id(id) , m_sensor(reinterpret_cast(sensor)) , m_cb(cb) , m_user_data(user_data) - , m_is_events_cb(is_events_cb) + , m_dispatcher(dispatcher) {} void connected(ipc::channel *ch) {} @@ -129,9 +144,8 @@ public: info->data = data; info->data_size = size; info->user_data = m_user_data; - info->is_events_cb = m_is_events_cb; - g_idle_add(callback_dispatcher, info); + g_idle_add(m_dispatcher, info); } void read_complete(ipc::channel *ch) {} @@ -142,46 +156,7 @@ private: sensor_info *m_sensor; void* m_cb; void *m_user_data; - bool m_is_events_cb; -}; - -class sensor_accuracy_handler : public ipc::channel_handler -{ -public: - sensor_accuracy_handler(int id, sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data) - : m_listener_id(id) - , m_sensor(reinterpret_cast(sensor)) - , m_cb(cb) - , m_user_data(user_data) - {} - - void connected(ipc::channel *ch) {} - void disconnected(ipc::channel *ch) {} - void read(ipc::channel *ch, ipc::message &msg) - { - callback_info_s *info; - char *data = new(std::nothrow) char[msg.size()]; - - memcpy(data, msg.body(), msg.size()); - - info = new(std::nothrow) callback_info_s(); - info->listener_id = m_listener_id; - info->acc_cb = m_cb; - info->sensor = m_sensor; - info->data = data; - info->user_data = m_user_data; - - g_idle_add(accuracy_callback_dispatcher, info); - } - - void read_complete(ipc::channel *ch) {} - void error_caught(ipc::channel *ch, int error) {} - -private: - int m_listener_id; - sensor_info *m_sensor; - sensor_accuracy_changed_cb_t m_cb; - void *m_user_data; + callback_dispatcher_t m_dispatcher; }; /* @@ -368,7 +343,7 @@ static inline bool sensord_register_event_impl(int handle, unsigned int event_ty sensor::sensor_listener *listener; int prev_interval; int prev_max_batch_latency; - sensor_event_handler *handler; + sensor_listener_handler *handler; AUTOLOCK(lock); @@ -391,7 +366,12 @@ static inline bool sensord_register_event_impl(int handle, unsigned int event_ty return false; } - handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, is_events_callback, user_data); + if (is_events_callback) { + handler = new(std::nothrow)sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_events_callback_dispatcher); + } else { + handler = new(std::nothrow)sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_event_callback_dispatcher); + } + if (!handler) { listener->set_max_batch_latency(prev_max_batch_latency); listener->set_interval(prev_interval); @@ -448,7 +428,7 @@ API bool sensord_unregister_events(int handle, unsigned int event_type) API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) { sensor::sensor_listener *listener; - sensor_accuracy_handler *handler; + sensor_listener_handler *handler; AUTOLOCK(lock); @@ -457,7 +437,7 @@ API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t c listener = it->second; - handler = new(std::nothrow) sensor_accuracy_handler(handle, listener->get_sensor(), cb, user_data); + handler = new(std::nothrow) sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_accuracy_changed_callback_dispatcher); retvm_if(!handler, false, "Failed to allocate memory"); listener->set_accuracy_handler(handler); @@ -481,6 +461,30 @@ API bool sensord_unregister_accuracy_cb(int handle) return true; } +API bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data) +{ + // TODO + return false; +} + +API bool sensord_unregister_attribute_int_changed_cb(int handle) +{ + // TODO + return false; +} + +API bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data) +{ + // TODO + return false; +} + +API bool sensord_unregister_attribute_str_changed_cb(int handle) +{ + // TODO + return false; +} + API bool sensord_start(int handle, int option) { sensor::sensor_listener *listener; diff --git a/src/client/sensor_reader.cpp b/src/client/sensor_reader.cpp index cdbad28..bc3a7a1 100644 --- a/src/client/sensor_reader.cpp +++ b/src/client/sensor_reader.cpp @@ -27,10 +27,10 @@ using namespace sensor; sensor_reader::sensor_reader() : m_reader(NULL) +, m_loop(NULL) , m_event_loop(NULL) , m_mutex() , m_cond() -, m_loop(NULL) , m_running(false) { m_event_loop = new(std::nothrow) ipc::event_loop(); diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index ebff117..3bdf4dc 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -246,3 +246,184 @@ TESTCASE(sensor_listener, attribute_string_1) return true; } + +void sensor_attribute_int_changed_callback(sensor_t sensor, int attribute, int value, void *data) +{ + _I("[ATTRIBUTE INT CHANGED] attribute : %d, value : %d\n", attribute, value); +} + +TESTCASE(skip_sensor_listener, register_attribute_int_changed) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ASSERT_EQ(err, 0); + + ret = sensord_register_attribute_int_changed_cb(handle, sensor_attribute_int_changed_callback, NULL); + ASSERT_TRUE(ret); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_unregister_attribute_int_changed_cb(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +static int attribute = 1; // 1 is SENSOR_ATTRIBUTE_AXIS_ORIENTATION of sensor_attribute_e in sensor.h +static int attribute_value = 0; + +static gboolean change_attribute_int(gpointer gdata) +{ + int *handle = reinterpret_cast(gdata); + + sensord_set_attribute_int(*handle, attribute, attribute_value); + + _N("[ SET ATTRIBUTE INT ] attribute %d, value : %d\n", attribute, attribute_value); + + g_timeout_add_seconds(1, change_attribute_int, handle); + + attribute_value ? attribute_value = 0 : attribute_value = 1; + + return FALSE; +} + +TESTCASE(skip_sensor_listener, attribute_int_changer) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ASSERT_EQ(err, 0); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + g_timeout_add_seconds(1, change_attribute_int, &handle); + mainloop::run(); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +void sensor_attribute_str_changed_callback(sensor_t sensor, int attribute, const char *value, int len, void *data) +{ + _I("[ATTRIBUTE STR CHANGED] attribute : %d, value : %s, len : %d\n", attribute, value, len); +} + +TESTCASE(skip_sensor_listener, register_attribute_str_changed) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ASSERT_EQ(err, 0); + + ret = sensord_register_attribute_str_changed_cb(handle, sensor_attribute_str_changed_callback, NULL); + ASSERT_TRUE(ret); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_unregister_attribute_int_changed_cb(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +static const char *attribute_value_str1 = "test_str_1"; +static const char *attribute_value_str2 = "test_str_2"; +static const char *attribute_value_str = attribute_value_str1; + +static gboolean change_attribute_str(gpointer gdata) +{ + int *handle = reinterpret_cast(gdata); + int len = strlen(attribute_value_str); + sensord_set_attribute_str(*handle, attribute, attribute_value_str, len); + + _N("[ SET ATTRIBUTE STR ] attribute %d, value : %s, len : %d\n", attribute, attribute_value_str, len); + + g_timeout_add_seconds(1, change_attribute_str, handle); + + if (attribute_value_str == attribute_value_str1) { + attribute_value_str = attribute_value_str2; + } else { + attribute_value_str = attribute_value_str1; + } + + return FALSE; +} + +TESTCASE(skip_sensor_listener, attribute_str_changer) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ASSERT_EQ(err, 0); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + g_timeout_add_seconds(1, change_attribute_str, &handle); + mainloop::run(); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} \ No newline at end of file -- 2.7.4 From 44fd8787cc7e1dde400c491bbac1044acbdb2e42 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Fri, 22 Nov 2019 12:54:28 +0900 Subject: [PATCH 13/16] Implement APIs related to attribute change notifications. Change-Id: Ibadf4b2feacb785bd71f880a3fa061e6863580f4 Signed-off-by: Boram Bae --- include/sensor_internal.h | 33 ++++++++- src/client/sensor_internal.cpp | 111 +++++++++++++++++++++++++---- src/client/sensor_listener.cpp | 85 +++++++++++++++++++++- src/client/sensor_listener.h | 9 +++ src/sensorctl/testcase/sensor_listener.cpp | 2 +- src/server/fusion_sensor_handler.h | 5 ++ src/server/sensor_handler.cpp | 59 +++++++++++++++ src/server/sensor_handler.h | 2 + src/server/sensor_listener_proxy.cpp | 24 +++++++ src/server/sensor_listener_proxy.h | 3 + src/server/sensor_observer.h | 1 + src/server/server_channel_handler.cpp | 18 ++++- 12 files changed, 330 insertions(+), 22 deletions(-) diff --git a/include/sensor_internal.h b/include/sensor_internal.h index 5727e23..fa7e76e 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -41,8 +41,8 @@ typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_dat typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t* events[], int events_count, void *user_data); typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data); typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data); -typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *data); -typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *data); +typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *user_data); +typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *user_data); /** * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors. @@ -304,13 +304,42 @@ bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, v */ bool sensord_unregister_accuracy_cb(int handle); +/** + * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed. + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] cb a callback which is called when he attributes of a sensor has changed. + * @param[in] user_data the callback is called with user_data + * @return true on success, otherwise false. + */ bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data); +/** + * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called. + * + * @param[in] handle a handle represensting a connected sensor. + * @return true on success, otherwise false. + */ bool sensord_unregister_attribute_int_changed_cb(int handle); +/** + * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed. + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] cb a callback which is called when he attributes of a sensor has changed. + * @param[in] user_data the callback is called with user_data + * @return true on success, otherwise false. + */ bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data); +/** + * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called. + * + * @param[in] handle a handle represensting a connected sensor. + * @return true on success, otherwise false. + */ bool sensord_unregister_attribute_str_changed_cb(int handle); + /** * @brief Start listening events with a connected sensor. * diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 0bad9a8..9d13857 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "sensor_reader.h" @@ -116,10 +117,42 @@ static gboolean sensor_accuracy_changed_callback_dispatcher(gpointer data) return FALSE; } -class sensor_listener_handler : public ipc::channel_handler +static gboolean sensor_attribute_int_changed_callback_dispatcher(gpointer data) +{ + callback_info_s *info = (callback_info_s *)data; + + AUTOLOCK(lock); + + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + cmd_listener_attr_int_t *d = (cmd_listener_attr_int_t *)info->data; + ((sensor_attribute_int_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, info->user_data); + } + + delete [] info->data; + delete info; + return FALSE; +} + +static gboolean sensor_attribute_str_changed_callback_dispatcher(gpointer data) +{ + callback_info_s *info = (callback_info_s *)data; + + AUTOLOCK(lock); + + if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end()) { + cmd_listener_attr_str_t *d = (cmd_listener_attr_str_t *)info->data; + ((sensor_attribute_str_changed_cb_t)info->cb)(info->sensor, d->attribute, d->value, d->len, info->user_data); + } + + delete [] info->data; + delete info; + return FALSE; +} + +class sensor_listener_channel_handler : public ipc::channel_handler { public: - sensor_listener_handler(int id, sensor_t sensor, void* cb, void *user_data, callback_dispatcher_t dispatcher) + sensor_listener_channel_handler(int id, sensor_t sensor, void* cb, void *user_data, callback_dispatcher_t dispatcher) : m_listener_id(id) , m_sensor(reinterpret_cast(sensor)) , m_cb(cb) @@ -343,7 +376,7 @@ static inline bool sensord_register_event_impl(int handle, unsigned int event_ty sensor::sensor_listener *listener; int prev_interval; int prev_max_batch_latency; - sensor_listener_handler *handler; + sensor_listener_channel_handler *handler; AUTOLOCK(lock); @@ -367,9 +400,9 @@ static inline bool sensord_register_event_impl(int handle, unsigned int event_ty } if (is_events_callback) { - handler = new(std::nothrow)sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_events_callback_dispatcher); + handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_events_callback_dispatcher); } else { - handler = new(std::nothrow)sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_event_callback_dispatcher); + handler = new(std::nothrow)sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_event_callback_dispatcher); } if (!handler) { @@ -428,7 +461,7 @@ API bool sensord_unregister_events(int handle, unsigned int event_type) API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) { sensor::sensor_listener *listener; - sensor_listener_handler *handler; + sensor_listener_channel_handler *handler; AUTOLOCK(lock); @@ -437,7 +470,7 @@ API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t c listener = it->second; - handler = new(std::nothrow) sensor_listener_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_accuracy_changed_callback_dispatcher); + handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_accuracy_changed_callback_dispatcher); retvm_if(!handler, false, "Failed to allocate memory"); listener->set_accuracy_handler(handler); @@ -463,26 +496,74 @@ API bool sensord_unregister_accuracy_cb(int handle) API bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data) { - // TODO - return false; + sensor::sensor_listener *listener; + sensor_listener_channel_handler *handler; + + AUTOLOCK(lock); + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); + + listener = it->second; + + handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_int_changed_callback_dispatcher); + retvm_if(!handler, false, "Failed to allocate memory"); + + listener->set_attribute_int_changed_handler(handler); + + return true; } API bool sensord_unregister_attribute_int_changed_cb(int handle) { - // TODO - return false; + sensor::sensor_listener *listener; + + AUTOLOCK(lock); + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); + + listener = it->second; + + listener->unset_attribute_int_changed_handler(); + + return true; } API bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data) { - // TODO - return false; + sensor::sensor_listener *listener; + sensor_listener_channel_handler *handler; + + AUTOLOCK(lock); + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); + + listener = it->second; + + handler = new(std::nothrow) sensor_listener_channel_handler(handle, listener->get_sensor(), (void *)cb, user_data, sensor_attribute_str_changed_callback_dispatcher); + retvm_if(!handler, false, "Failed to allocate memory"); + + listener->set_attribute_str_changed_handler(handler); + + return true; } API bool sensord_unregister_attribute_str_changed_cb(int handle) { - // TODO - return false; + sensor::sensor_listener *listener; + + AUTOLOCK(lock); + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); + + listener = it->second; + + listener->unset_attribute_str_changed_handler(); + + return true; } API bool sensord_start(int handle, int option) diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index e08e179..5e0e69d 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -36,6 +36,7 @@ public: listener_handler(sensor_listener *listener) : m_listener(listener) {} + void connected(ipc::channel *ch) {} void disconnected(ipc::channel *ch) { @@ -55,6 +56,16 @@ public: if (m_listener->get_accuracy_handler()) m_listener->get_accuracy_handler()->read(ch, msg); break; + case CMD_LISTENER_ATTR_INT: + if (m_listener->get_attribute_int_changed_handler()) + m_listener->get_attribute_int_changed_handler()->read(ch, msg); + break; + case CMD_LISTENER_ATTR_STR: + if (m_listener->get_attribute_str_changed_handler()) + m_listener->get_attribute_str_changed_handler()->read(ch, msg); + break; + default: + _W("Invalid command message"); } } @@ -74,6 +85,8 @@ sensor_listener::sensor_listener(sensor_t sensor) , m_handler(NULL) , m_evt_handler(NULL) , m_acc_handler(NULL) +, m_attr_int_changed_handler(NULL) +, m_attr_str_changed_handler(NULL) , m_connected(false) , m_started(false) { @@ -89,6 +102,8 @@ sensor_listener::sensor_listener(sensor_t sensor, ipc::event_loop *loop) , m_handler(NULL) , m_evt_handler(NULL) , m_acc_handler(NULL) +, m_attr_int_changed_handler(NULL) +, m_attr_str_changed_handler(NULL) , m_loop(loop) , m_connected(false) , m_started(false) @@ -135,6 +150,18 @@ void sensor_listener::deinit(void) delete m_client; m_client = NULL; + delete m_evt_handler; + m_evt_handler = NULL; + + delete m_acc_handler; + m_acc_handler = NULL; + + delete m_attr_int_changed_handler; + m_attr_int_changed_handler = NULL; + + delete m_attr_str_changed_handler; + m_attr_str_changed_handler = NULL; + m_attributes.clear(); _D("Deinitialized.."); } @@ -234,7 +261,9 @@ ipc::channel_handler *sensor_listener::get_event_handler(void) void sensor_listener::set_event_handler(ipc::channel_handler *handler) { AUTOLOCK(lock); - + if (m_evt_handler) { + delete m_evt_handler; + } m_evt_handler = handler; } @@ -248,20 +277,70 @@ void sensor_listener::unset_event_handler(void) ipc::channel_handler *sensor_listener::get_accuracy_handler(void) { + AUTOLOCK(lock); return m_acc_handler; } void sensor_listener::set_accuracy_handler(ipc::channel_handler *handler) { + AUTOLOCK(lock); + if (m_acc_handler) { + delete m_acc_handler; + } m_acc_handler = handler; } void sensor_listener::unset_accuracy_handler(void) { + AUTOLOCK(lock); delete m_acc_handler; m_acc_handler = NULL; } +ipc::channel_handler *sensor_listener::get_attribute_int_changed_handler(void) +{ + AUTOLOCK(lock); + return m_attr_int_changed_handler; +} + +void sensor_listener::set_attribute_int_changed_handler(ipc::channel_handler *handler) +{ + AUTOLOCK(lock); + if (m_attr_int_changed_handler) { + delete m_attr_int_changed_handler; + } + m_attr_int_changed_handler = handler; +} + +void sensor_listener::unset_attribute_int_changed_handler(void) +{ + AUTOLOCK(lock); + delete m_attr_int_changed_handler; + m_attr_int_changed_handler = NULL; +} + +ipc::channel_handler *sensor_listener::get_attribute_str_changed_handler(void) +{ + AUTOLOCK(lock); + return m_attr_str_changed_handler; +} + +void sensor_listener::set_attribute_str_changed_handler(ipc::channel_handler *handler) +{ + AUTOLOCK(lock); + if (m_attr_str_changed_handler) { + delete m_attr_str_changed_handler; + } + m_attr_str_changed_handler = handler; +} + +void sensor_listener::unset_attribute_str_changed_handler(void) +{ + AUTOLOCK(lock); + delete m_attr_str_changed_handler; + m_attr_str_changed_handler = NULL; +} + int sensor_listener::start(void) { ipc::message msg; @@ -435,7 +514,7 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) size = sizeof(cmd_listener_attr_str_t) + len; - buf = (cmd_listener_attr_str_t *) malloc(sizeof(char) * size); + buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); msg.set_type(CMD_LISTENER_ATTR_STR); @@ -453,6 +532,8 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) /* Message memory is released automatically after sending message, so it doesn't need to free memory */ + delete [] buf; + if (reply.header()->err < 0) return reply.header()->err; diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h index be53ee5..fd4d059 100644 --- a/src/client/sensor_listener.h +++ b/src/client/sensor_listener.h @@ -42,13 +42,19 @@ public: ipc::channel_handler *get_event_handler(void); ipc::channel_handler *get_accuracy_handler(void); + ipc::channel_handler *get_attribute_int_changed_handler(void); + ipc::channel_handler *get_attribute_str_changed_handler(void); /* TODO: modify the listener so that it can register multiple handlers(1:n) */ void set_event_handler(ipc::channel_handler *handler); void set_accuracy_handler(ipc::channel_handler *handler); + void set_attribute_int_changed_handler(ipc::channel_handler *handler); + void set_attribute_str_changed_handler(ipc::channel_handler *handler); void unset_event_handler(void); void unset_accuracy_handler(void); + void unset_attribute_int_changed_handler(void); + void unset_attribute_str_changed_handler(void); int start(void); int stop(void); @@ -86,6 +92,9 @@ private: ipc::channel_handler *m_handler; ipc::channel_handler *m_evt_handler; ipc::channel_handler *m_acc_handler; + ipc::channel_handler *m_attr_int_changed_handler; + ipc::channel_handler *m_attr_str_changed_handler; + ipc::event_loop *m_loop; std::atomic m_connected; std::atomic m_started; diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index 3bdf4dc..7a38371 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -382,7 +382,7 @@ static const char *attribute_value_str = attribute_value_str1; static gboolean change_attribute_str(gpointer gdata) { int *handle = reinterpret_cast(gdata); - int len = strlen(attribute_value_str); + int len = strlen(attribute_value_str) + 1; sensord_set_attribute_str(*handle, attribute, attribute_value_str, len); _N("[ SET ATTRIBUTE STR ] attribute %d, value : %s, len : %d\n", attribute, attribute_value_str, len); diff --git a/src/server/fusion_sensor_handler.h b/src/server/fusion_sensor_handler.h index 9feb67f..5e12f10 100644 --- a/src/server/fusion_sensor_handler.h +++ b/src/server/fusion_sensor_handler.h @@ -51,6 +51,11 @@ public: /* subscriber */ int update(const char *uri, ipc::message *msg); + int on_attribute_changed(ipc::message *msg) + { + // Do nothing + return OP_SUCCESS; + } /* sensor interface */ const sensor_info &get_sensor_info(void); diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index e969aae..0de7fd0 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace sensor; @@ -128,6 +129,64 @@ int sensor_handler::get_cache(sensor_data_t **data, int *len) return 0; } +bool sensor_handler::notify_attribute_changed(int attribute, int value) +{ + if (observer_count() == 0) + return OP_ERROR; + + cmd_listener_attr_int_t buf; + buf.attribute = attribute; + buf.value = value; + + ipc::message *msg; + msg = new(std::nothrow) ipc::message(); + retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); + + msg->set_type(CMD_LISTENER_ATTR_INT); + msg->enclose((char *)&buf, sizeof(buf)); + + for (auto it = m_observers.begin(); it != m_observers.end(); ++it) + (*it)->on_attribute_changed(msg); + + if (msg->ref_count() == 0) + msg->unref(); + + return OP_SUCCESS; +} + +bool sensor_handler::notify_attribute_changed(int attribute, const char *value, int len) +{ + if (observer_count() == 0) + return OP_ERROR; + + cmd_listener_attr_str_t *buf; + size_t size; + size = sizeof(cmd_listener_attr_str_t) + len; + buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; + retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); + + ipc::message *msg; + msg = new(std::nothrow) ipc::message(); + retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); + + buf->attribute = attribute; + memcpy(buf->value, value, len); + buf->len = len; + + msg->set_type(CMD_LISTENER_ATTR_STR); + msg->enclose((char *)buf, size); + + for (auto it = m_observers.begin(); it != m_observers.end(); ++it) + (*it)->on_attribute_changed(msg); + + if (msg->ref_count() == 0) + msg->unref(); + + delete[] buf; + + return OP_SUCCESS; +} + int sensor_handler::delete_batch_latency(sensor_observer *ob) { return 0; diff --git a/src/server/sensor_handler.h b/src/server/sensor_handler.h index 9f6e711..cb7bde8 100644 --- a/src/server/sensor_handler.h +++ b/src/server/sensor_handler.h @@ -55,6 +55,8 @@ public: void set_cache(sensor_data_t *data, int size); int get_cache(sensor_data_t **data, int *len); + bool notify_attribute_changed(int attribute, int value); + bool notify_attribute_changed(int attribute, const char *value, int len); protected: sensor_info m_info; diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 44f6c4f..a52927d 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -66,6 +66,14 @@ int sensor_listener_proxy::update(const char *uri, ipc::message *msg) return OP_CONTINUE; } +int sensor_listener_proxy::on_attribute_changed(ipc::message *msg) +{ + retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE); + + m_ch->send(msg); + return OP_CONTINUE; +} + void sensor_listener_proxy::update_event(ipc::message *msg) { /* TODO: check axis orientation */ @@ -248,3 +256,19 @@ void sensor_listener_proxy::on_policy_changed(int policy, int value) if (!(value & m_pause_policy)) start(true); } + +bool sensor_listener_proxy::notify_attribute_changed(int attribute, int value) +{ + sensor_handler *sensor = m_manager->get_sensor(m_uri); + retv_if(!sensor, -EINVAL); + + return sensor->notify_attribute_changed(attribute, value); +} + +bool sensor_listener_proxy::notify_attribute_changed(int attribute, const char *value, int len) +{ + sensor_handler *sensor = m_manager->get_sensor(m_uri); + retv_if(!sensor, -EINVAL); + + return sensor->notify_attribute_changed(attribute, value, len); +} \ No newline at end of file diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index 8258f63..f0d1dae 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -39,6 +39,7 @@ public: /* sensor observer */ int update(const char *uri, ipc::message *msg); + int on_attribute_changed(ipc::message *msg); int start(bool policy = false); int stop(bool policy = false); @@ -55,6 +56,8 @@ public: /* sensor_policy_listener interface */ void on_policy_changed(int policy, int value); + bool notify_attribute_changed(int attribute, int value); + bool notify_attribute_changed(int attribute, const char *value, int len); private: void update_event(ipc::message *msg); diff --git a/src/server/sensor_observer.h b/src/server/sensor_observer.h index ee04c20..02603b0 100644 --- a/src/server/sensor_observer.h +++ b/src/server/sensor_observer.h @@ -30,6 +30,7 @@ public: /* for performance, use message */ virtual int update(const char *uri, ipc::message *msg) = 0; + virtual int on_attribute_changed(ipc::message *msg) = 0; }; } diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index c897243..86606df 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -216,6 +216,8 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) -EACCES, "Permission denied[%d, %s]", id, m_listeners[id]->get_required_privileges().c_str()); + bool need_notify = false; + switch (buf.attribute) { case SENSORD_ATTRIBUTE_INTERVAL: ret = m_listeners[id]->set_interval(buf.value); break; @@ -227,12 +229,21 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) case SENSORD_ATTRIBUTE_AXIS_ORIENTATION: default: ret = m_listeners[id]->set_attribute(buf.attribute, buf.value); + if (ret == OP_SUCCESS) { + need_notify = true; + } } /* TODO : check return value */ if (ret < 0) _D("Return : %d", ret); - return send_reply(ch, OP_SUCCESS); + ret = send_reply(ch, OP_SUCCESS); + + if (need_notify) { + m_listeners[id]->notify_attribute_changed(buf.attribute, buf.value); + } + + return ret; } int server_channel_handler::listener_attr_str(channel *ch, message &msg) @@ -264,8 +275,11 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) return ret; } + ret = send_reply(ch, OP_SUCCESS); + m_listeners[id]->notify_attribute_changed(buf->attribute, buf->value, buf->len); + delete [] buf; - return send_reply(ch, OP_SUCCESS); + return ret; } int server_channel_handler::listener_get_data(channel *ch, message &msg) -- 2.7.4 From 3fce175a19d9258c545b66223885e75d0d95252a Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Wed, 27 Nov 2019 17:06:10 +0900 Subject: [PATCH 14/16] Add APIs to get an attribute value * Implement sensord_get_attribute_int/str * Update attribute of sensor_listener when another one changes the attribute * Remove an interface on_attribute_changed of sensor_observer * Add memebers to store attributes of sensor_listener and sensor_hander * Add command types Change-Id: I9e736699e2156a4779ddcb319a3f4a6206c9c4b1 Signed-off-by: Boram Bae --- include/sensor_internal.h | 27 +++++ src/client-dummy/client_dummy.cpp | 10 ++ src/client/sensor_internal.cpp | 37 ++++++ src/client/sensor_listener.cpp | 157 ++++++++++++++++++------ src/client/sensor_listener.h | 9 +- src/sensorctl/testcase/sensor_listener.cpp | 186 ++++++++++++++++++++++++++++- src/server/application_sensor_handler.cpp | 3 +- src/server/external_sensor_handler.cpp | 6 + src/server/fusion_sensor_handler.cpp | 4 + src/server/fusion_sensor_handler.h | 5 - src/server/physical_sensor_handler.cpp | 7 ++ src/server/sensor_handler.cpp | 71 +++++++++-- src/server/sensor_handler.h | 12 +- src/server/sensor_listener_proxy.cpp | 36 +++++- src/server/sensor_listener_proxy.h | 2 + src/server/sensor_observer.h | 1 - src/server/server_channel_handler.cpp | 106 +++++++++++++++- src/server/server_channel_handler.h | 6 +- src/shared/command_types.h | 10 +- 19 files changed, 622 insertions(+), 73 deletions(-) diff --git a/include/sensor_internal.h b/include/sensor_internal.h index fa7e76e..07638fd 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -404,6 +404,19 @@ bool sensord_set_option(int handle, int option); */ int sensord_set_attribute_int(int handle, int attribute, int value); +/* + * @brief Get the attribute to a connected sensor + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] attribute an attribute to get value + * @param[out] value an attribute value + * @return 0 on success, otherwise a negative error value + * @retval 0 Successful + * @retval -EINVAL Invalid parameter + * @retval -EPERM Operation not permitted + */ +int sensord_get_attribute_int(int handle, int attribute, int* value); + /** * @brief Set the attribute to a connected sensor * @@ -419,6 +432,20 @@ int sensord_set_attribute_int(int handle, int attribute, int value); int sensord_set_attribute_str(int handle, int attribute, const char *value, int len); /** + * @brief Get the attribute to a connected sensor + * + * @param[in] handle a handle represensting a connected sensor. + * @param[in] attribute an attribute to get value + * @param[out] value an attribute value, the caller should explicitly free this value + * @param[out] len the length of value + * @return 0 on success, otherwise a negative error value + * @retval 0 Successful + * @retval -EINVAL Invalid parameter + * @retval -EPERM Operation not permitted + */ +int sensord_get_attribute_str(int handle, int attribute, char **value, int *len); + +/** * @brief Send data to sensorhub * * @param[in] handle a handle represensting a connected context sensor. diff --git a/src/client-dummy/client_dummy.cpp b/src/client-dummy/client_dummy.cpp index d84e2ad..accc043 100644 --- a/src/client-dummy/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -203,11 +203,21 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return OP_ERROR; } +API int sensord_get_attribute_int(int handle, int attribute, int* value) +{ + return OP_ERROR; +} + API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) { return OP_ERROR; } +API int sensord_get_attribute_str(int handle, int attribute, char **value, int *len) +{ + return OP_ERROR; +} + API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len) { return false; diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 9d13857..376059c 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -714,6 +714,25 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return OP_SUCCESS; } +API int sensord_get_attribute_int(int handle, int attribute, int* value) +{ + sensor::sensor_listener *listener; + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle); + + listener = it->second; + + if (listener->get_attribute(attribute, value) < 0) { + _E("Failed to get attribute[%d]", attribute); + return -EIO; + } + + _D("Get attribute[%d, %d, %d]", listener->get_id(), attribute, *value); + + return OP_SUCCESS; +} + API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) { sensor::sensor_listener *listener; @@ -731,6 +750,24 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, return OP_SUCCESS; } +API int sensord_get_attribute_str(int handle, int attribute, char **value, int* len) +{ + sensor::sensor_listener *listener; + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), -EINVAL, "Invalid handle[%d]", handle); + + listener = it->second; + + if (listener->get_attribute(attribute, value, len) < 0) { + _E("Failed to get attribute[%d]", attribute); + return -EIO; + } + _D("Get attribute[%d, %d, %s]", listener->get_id(), attribute, *value); + + return OP_SUCCESS; +} + API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data) { sensor::sensor_listener *listener; diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index 5e0e69d..6cea7d3 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -49,21 +49,31 @@ public: { switch (msg.header()->type) { case CMD_LISTENER_EVENT: - if (m_listener->get_event_handler()) + if (m_listener->get_event_handler()) { m_listener->get_event_handler()->read(ch, msg); + } break; case CMD_LISTENER_ACC_EVENT: - if (m_listener->get_accuracy_handler()) + if (m_listener->get_accuracy_handler()) { m_listener->get_accuracy_handler()->read(ch, msg); + } break; - case CMD_LISTENER_ATTR_INT: - if (m_listener->get_attribute_int_changed_handler()) + case CMD_LISTENER_SET_ATTR_INT: { + if (m_listener->get_attribute_int_changed_handler()) { m_listener->get_attribute_int_changed_handler()->read(ch, msg); - break; - case CMD_LISTENER_ATTR_STR: - if (m_listener->get_attribute_str_changed_handler()) + } + + cmd_listener_attr_int_t* buf = (cmd_listener_attr_int_t*) msg.body(); + m_listener->update_attribute(buf->attribute, buf->value); + } break; + case CMD_LISTENER_SET_ATTR_STR: { + if (m_listener->get_attribute_str_changed_handler()) { m_listener->get_attribute_str_changed_handler()->read(ch, msg); - break; + } + + cmd_listener_attr_str_t* buf = (cmd_listener_attr_str_t*) msg.body(); + m_listener->update_attribute(buf->attribute, buf->value, buf->len); + } break; default: _W("Invalid command message"); } @@ -162,7 +172,8 @@ void sensor_listener::deinit(void) delete m_attr_str_changed_handler; m_attr_str_changed_handler = NULL; - m_attributes.clear(); + m_attributes_int.clear(); + m_attributes_str.clear(); _D("Deinitialized.."); } @@ -187,13 +198,13 @@ void sensor_listener::restore(void) if (m_started.load()) start(); - auto interval = m_attributes.find(SENSORD_ATTRIBUTE_INTERVAL); - if (interval != m_attributes.end()) - set_interval(m_attributes[SENSORD_ATTRIBUTE_INTERVAL]); + auto interval = m_attributes_int.find(SENSORD_ATTRIBUTE_INTERVAL); + if (interval != m_attributes_int.end()) + set_interval( m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL]); - auto latency = m_attributes.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY); - if (latency != m_attributes.end()) - set_max_batch_latency(m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]); + auto latency = m_attributes_int.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY); + if (latency != m_attributes_int.end()) + set_max_batch_latency( m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]); _D("Restored listener[%d]", get_id()); } @@ -398,34 +409,34 @@ int sensor_listener::stop(void) int sensor_listener::get_interval(void) { - auto it = m_attributes.find(SENSORD_ATTRIBUTE_INTERVAL); - retv_if(it == m_attributes.end(), -1); + auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_INTERVAL); + retv_if(it == m_attributes_int.end(), -1); - return m_attributes[SENSORD_ATTRIBUTE_INTERVAL]; + return m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL]; } int sensor_listener::get_max_batch_latency(void) { - auto it = m_attributes.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY); - retv_if(it == m_attributes.end(), -1); + auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY); + retv_if(it == m_attributes_int.end(), -1); - return m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]; + return m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]; } int sensor_listener::get_pause_policy(void) { - auto it = m_attributes.find(SENSORD_ATTRIBUTE_PAUSE_POLICY); - retv_if(it == m_attributes.end(), -1); + auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_PAUSE_POLICY); + retv_if(it == m_attributes_int.end(), -1); - return m_attributes[SENSORD_ATTRIBUTE_PAUSE_POLICY]; + return m_attributes_int[SENSORD_ATTRIBUTE_PAUSE_POLICY]; } int sensor_listener::get_passive_mode(void) { - auto it = m_attributes.find(SENSORD_ATTRIBUTE_PASSIVE_MODE); - retv_if(it == m_attributes.end(), -1); + auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_PASSIVE_MODE); + retv_if(it == m_attributes_int.end(), -1); - return m_attributes[SENSORD_ATTRIBUTE_PASSIVE_MODE]; + return m_attributes_int[SENSORD_ATTRIBUTE_PASSIVE_MODE]; } int sensor_listener::set_interval(unsigned int interval) @@ -444,7 +455,7 @@ int sensor_listener::set_interval(unsigned int interval) /* If it is not started, store the value only */ if (!m_started.load()) { - m_attributes[SENSORD_ATTRIBUTE_INTERVAL] = _interval; + m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL] = _interval; return OP_SUCCESS; } @@ -457,7 +468,7 @@ int sensor_listener::set_max_batch_latency(unsigned int max_batch_latency) /* If it is not started, store the value only */ if (!m_started.load()) { - m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency; + m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency; return OP_SUCCESS; } @@ -489,7 +500,7 @@ int sensor_listener::set_attribute(int attribute, int value) buf.listener_id = m_id; buf.attribute = attribute; buf.value = value; - msg.set_type(CMD_LISTENER_ATTR_INT); + msg.set_type(CMD_LISTENER_SET_ATTR_INT); msg.enclose((char *)&buf, sizeof(buf)); m_cmd_channel->send_sync(&msg); @@ -498,11 +509,47 @@ int sensor_listener::set_attribute(int attribute, int value) if (reply.header()->err < 0) return reply.header()->err; - m_attributes[attribute] = value; + update_attribute(attribute, value); return OP_SUCCESS; } +int sensor_listener::get_attribute(int attribute, int* value) +{ + auto it = m_attributes_int.find(attribute); + if (it == m_attributes_int.end()) { + ipc::message msg; + ipc::message reply; + cmd_listener_attr_int_t buf; + + buf.listener_id = m_id; + buf.attribute = attribute; + + msg.set_type(CMD_LISTENER_GET_ATTR_INT); + msg.enclose((char *)&buf, sizeof(buf)); + m_cmd_channel->send_sync(&msg); + + m_cmd_channel->read_sync(reply); + + if (reply.header()->err < 0) { + _D("reply.header()->err < 0"); + return reply.header()->err; + } + if (reply.header()->length && reply.body()) { + update_attribute(attribute, ((cmd_listener_attr_int_t *)reply.body())->value); + } + } + + *value = m_attributes_int[attribute]; + return OP_SUCCESS; +} + +void sensor_listener::update_attribute(int attribute, int value) +{ + m_attributes_int[attribute] = value; + _I("listener[%d]'s attribues(int) size : %d", get_id(), m_attributes_int.size()); +} + int sensor_listener::set_attribute(int attribute, const char *value, int len) { ipc::message msg; @@ -517,7 +564,7 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); - msg.set_type(CMD_LISTENER_ATTR_STR); + msg.set_type(CMD_LISTENER_SET_ATTR_STR); buf->listener_id = m_id; buf->attribute = attribute; @@ -537,9 +584,52 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) if (reply.header()->err < 0) return reply.header()->err; + update_attribute(attribute, value, len); + return OP_SUCCESS; } +int sensor_listener::get_attribute(int attribute, char **value, int* len) +{ + auto it = m_attributes_str.find(attribute); + if (it == m_attributes_str.end()) { + ipc::message msg; + ipc::message reply; + cmd_listener_attr_str_t buf; + + buf.listener_id = m_id; + buf.attribute = attribute; + + msg.set_type(CMD_LISTENER_GET_ATTR_STR); + msg.enclose((char *)&buf, sizeof(buf)); + m_cmd_channel->send_sync(&msg); + + m_cmd_channel->read_sync(reply); + if (reply.header()->err < 0) { + _D("reply.header()->err < 0"); + return reply.header()->err; + } + + if (reply.header()->length && reply.body()) { + cmd_listener_attr_str_t * recv_buf = (cmd_listener_attr_str_t *)reply.body(); + update_attribute(attribute, (char *)recv_buf->value, recv_buf->len); + } + } + + *len = m_attributes_str[attribute].size(); + *value = (char *) malloc(*len); + std::copy(m_attributes_str[attribute].begin(), m_attributes_str[attribute].end(), *value); + + return OP_SUCCESS; +} + +void sensor_listener::update_attribute(int attribute, const char *value, int len) +{ + m_attributes_str[attribute].clear(); + m_attributes_str[attribute].insert(m_attributes_str[attribute].begin(), value, value + len); + _I("listener[%d]'s attribues(str) size : %d", get_id(), m_attributes_str.size()); +} + int sensor_listener::get_sensor_data(sensor_data_t *data) { ipc::message msg; @@ -570,5 +660,4 @@ int sensor_listener::get_sensor_data(sensor_data_t *data) _D("Listener[%d] read sensor data", get_id()); return OP_SUCCESS; -} - +} \ No newline at end of file diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h index fd4d059..47cab20 100644 --- a/src/client/sensor_listener.h +++ b/src/client/sensor_listener.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace sensor { @@ -68,8 +69,11 @@ public: int set_max_batch_latency(unsigned int max_batch_latency); int set_passive_mode(bool passive); int set_attribute(int attribute, int value); + int get_attribute(int attribute, int* value); + void update_attribute(int attribute, int value); int set_attribute(int attribute, const char *value, int len); - + int get_attribute(int attribute, char **value, int *len); + void update_attribute(int attribute, const char *value, int len); int get_sensor_data(sensor_data_t *data); int flush(void); @@ -98,7 +102,8 @@ private: ipc::event_loop *m_loop; std::atomic m_connected; std::atomic m_started; - std::map m_attributes; + std::map m_attributes_int; + std::map> m_attributes_str; }; } diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index 7a38371..c5adee2 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -224,22 +224,202 @@ TESTCASE(sensor_listener, bad_disconnect_p_2) return true; } +TESTCASE(sensor_listener, set_get_attribute_int_1) +{ + int err = 0; + bool ret = true; + int handle = 0; + sensor_t sensor = NULL; + int attr = 1; + int value = -1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + err = sensord_set_attribute_int(handle, attr, 1); + ASSERT_EQ(err, 0); + + err = sensord_get_attribute_int(handle, attr, &value); + ASSERT_EQ(err, 0); + + ASSERT_EQ(value, 1); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(sensor_listener, set_get_attribute_int_2) +{ + int err = 0; + bool ret = true; + int handle = 0; + sensor_t sensor = NULL; + int attr = 20; + int value = -1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + err = sensord_set_attribute_int(handle, attr, 1); + ASSERT_EQ(err, 0); + + err = sensord_get_attribute_int(handle, attr, &value); + ASSERT_EQ(err, 0); + + ASSERT_EQ(value, 1); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(sensor_listener, get_attribute_int_1) +{ + int err = 0; + bool ret = true; + int handle = 0; + sensor_t sensor = NULL; + int attr = 100; + int value = -1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + + // attr 100 value is never set in these tests. + err = sensord_get_attribute_int(handle, attr, &value); + ASSERT_EQ(err, -5); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + #define TEST_STRING "TESTTESTTEST" -#define TEST_STRING_LEN 12 +#define TEST_STRING_LEN 13 + +TESTCASE(sensor_listener, set_attribute_string_1) +{ + int err = 0; + bool ret = true; + int handle = 0; + sensor_t sensor = NULL; + int attr = 1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + err = sensord_set_attribute_str(handle, attr, TEST_STRING, TEST_STRING_LEN); + ASSERT_EQ(err, 0); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(sensor_listener, set_get_attribute_string_1) +{ + int err = 0; + bool ret = true; + int handle = 0; + char *value = NULL; + int len = 0; + sensor_t sensor = NULL; + int attr = 1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + err = sensord_set_attribute_str(handle, attr, TEST_STRING, TEST_STRING_LEN); + ASSERT_EQ(err, 0); + + err = sensord_get_attribute_str(handle, attr, &value, &len); + ASSERT_EQ(err, 0); + ASSERT_EQ(len, TEST_STRING_LEN); + ASSERT_EQ(strncmp(value, TEST_STRING, len), 0); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + free(value); + return true; +} -TESTCASE(sensor_listener, attribute_string_1) +TESTCASE(sensor_listener, set_get_get_attribute_string_1) { int err; bool ret; int handle; + char *value = NULL; + int len = 0; sensor_t sensor; + int attr = 1; err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); ASSERT_EQ(err, 0); handle = sensord_connect(sensor); - err = sensord_set_attribute_str(handle, 1, TEST_STRING, TEST_STRING_LEN); + err = sensord_set_attribute_str(handle, attr, TEST_STRING, TEST_STRING_LEN); + ASSERT_EQ(err, 0); + + err = sensord_get_attribute_str(handle, attr, &value, &len); ASSERT_EQ(err, 0); + ASSERT_EQ(len, TEST_STRING_LEN); + ASSERT_EQ(strncmp(value, TEST_STRING, len), 0); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + free(value); + + value = NULL; + len = 0; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + + err = sensord_get_attribute_str(handle, attr, &value, &len); + ASSERT_EQ(err, 0); + ASSERT_EQ(len, TEST_STRING_LEN); + ASSERT_EQ(strncmp(value, TEST_STRING, len), 0); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + free(value); + return true; +} + +TESTCASE(sensor_listener, get_attribute_string_2) +{ + int err; + bool ret; + int handle; + char *value; + int len; + sensor_t sensor; + int attr = 100; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + + // attr 100 value is never set in these tests. + err = sensord_get_attribute_str(handle, attr, &value, &len); + ASSERT_EQ(err, -EIO); ret = sensord_disconnect(handle); ASSERT_TRUE(ret); diff --git a/src/server/application_sensor_handler.cpp b/src/server/application_sensor_handler.cpp index f2abadc..df5db08 100644 --- a/src/server/application_sensor_handler.cpp +++ b/src/server/application_sensor_handler.cpp @@ -135,6 +135,7 @@ int application_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t l int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int32_t value) { + update_attribute(attr, value); return OP_SUCCESS; } @@ -159,7 +160,7 @@ int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, m_ch->send_sync(&msg); _I("Set attribute[%d] to sensor[%s]", attr, m_info.get_uri().c_str()); - + update_attribute(attr, value, len); return OP_SUCCESS; } diff --git a/src/server/external_sensor_handler.cpp b/src/server/external_sensor_handler.cpp index 474f764..e0f74bf 100644 --- a/src/server/external_sensor_handler.cpp +++ b/src/server/external_sensor_handler.cpp @@ -211,6 +211,9 @@ int external_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, in if (m_policy == OP_DEFAULT) { /* default logic */ } + + update_attribute(attr, value); + return OP_SUCCESS; } @@ -226,6 +229,9 @@ int external_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, co if (m_policy == OP_DEFAULT) { /* default logic */ } + + update_attribute(attr, value, len); + return OP_SUCCESS; } diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index 6cbc692..5d5a8d1 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -199,6 +199,8 @@ int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int3 /* default logic */ } + update_attribute(attr, value); + return set_attribute_internal(attr, value); } @@ -215,6 +217,8 @@ int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, cons /* default logic */ } + update_attribute(attr, value, len); + return set_attribute_internal(attr, value, len); } diff --git a/src/server/fusion_sensor_handler.h b/src/server/fusion_sensor_handler.h index 5e12f10..9feb67f 100644 --- a/src/server/fusion_sensor_handler.h +++ b/src/server/fusion_sensor_handler.h @@ -51,11 +51,6 @@ public: /* subscriber */ int update(const char *uri, ipc::message *msg); - int on_attribute_changed(ipc::message *msg) - { - // Do nothing - return OP_SUCCESS; - } /* sensor interface */ const sensor_info &get_sensor_info(void); diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index 1b44a87..da82314 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -271,6 +271,9 @@ int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, in ret = m_device->set_attribute_int(m_hal_id, attr, value); + if (ret) { + update_attribute(attr, value); + } return (ret ? OP_SUCCESS : OP_ERROR); } @@ -296,6 +299,10 @@ int physical_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, co ret = m_device->set_attribute_str(m_hal_id, attr, const_cast(value), len); + if (ret) { + update_attribute(attr, value, len); + } + return (ret ? OP_SUCCESS : OP_ERROR); } diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index 0de7fd0..843c794 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace sensor; @@ -90,8 +91,9 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len) set_cache(data, len); - if (msg->ref_count() == 0) + if (msg->ref_count() == 0) { msg->unref(); + } return OP_SUCCESS; } @@ -129,12 +131,13 @@ int sensor_handler::get_cache(sensor_data_t **data, int *len) return 0; } -bool sensor_handler::notify_attribute_changed(int attribute, int value) +bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, int value) { if (observer_count() == 0) return OP_ERROR; cmd_listener_attr_int_t buf; + buf.listener_id = id; buf.attribute = attribute; buf.value = value; @@ -142,11 +145,16 @@ bool sensor_handler::notify_attribute_changed(int attribute, int value) msg = new(std::nothrow) ipc::message(); retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); - msg->set_type(CMD_LISTENER_ATTR_INT); + msg->set_type(CMD_LISTENER_SET_ATTR_INT); msg->enclose((char *)&buf, sizeof(buf)); - for (auto it = m_observers.begin(); it != m_observers.end(); ++it) - (*it)->on_attribute_changed(msg); + sensor_listener_proxy *proxy = NULL; + for (auto it = m_observers.begin(); it != m_observers.end(); ++it) { + proxy = dynamic_cast(*it); + if (proxy && proxy->get_id() != id) { + proxy->on_attribute_changed(msg); + } + } if (msg->ref_count() == 0) msg->unref(); @@ -154,7 +162,7 @@ bool sensor_handler::notify_attribute_changed(int attribute, int value) return OP_SUCCESS; } -bool sensor_handler::notify_attribute_changed(int attribute, const char *value, int len) +bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, const char *value, int len) { if (observer_count() == 0) return OP_ERROR; @@ -169,18 +177,26 @@ bool sensor_handler::notify_attribute_changed(int attribute, const char *value, msg = new(std::nothrow) ipc::message(); retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); + buf->listener_id = id; buf->attribute = attribute; memcpy(buf->value, value, len); buf->len = len; - msg->set_type(CMD_LISTENER_ATTR_STR); + msg->set_type(CMD_LISTENER_SET_ATTR_STR); msg->enclose((char *)buf, size); - for (auto it = m_observers.begin(); it != m_observers.end(); ++it) - (*it)->on_attribute_changed(msg); + _I("notify attribute changed by listener[%zu]\n", id); + sensor_listener_proxy *proxy = NULL; + for (auto it = m_observers.begin(); it != m_observers.end(); ++it) { + proxy = dynamic_cast(*it); + if (proxy && proxy->get_id() != id) { + proxy->on_attribute_changed(msg); + } + } - if (msg->ref_count() == 0) + if (msg->ref_count() == 0) { msg->unref(); + } delete[] buf; @@ -191,3 +207,38 @@ int sensor_handler::delete_batch_latency(sensor_observer *ob) { return 0; } + +int sensor_handler::get_attribute(int32_t attr, int32_t* value) +{ + auto it = m_attributes_int.find(attr); + retv_if(it == m_attributes_int.end(), OP_ERROR); + + *value = it->second; + return OP_SUCCESS; +} + +void sensor_handler::update_attribute(int32_t attr, int32_t value) +{ + m_attributes_int[attr] = value; + _I("[%s] attributes(int) size : %d", m_info.get_uri().c_str(), m_attributes_int.size()); +} + +int sensor_handler::get_attribute(int32_t attr, char **value, int *len) +{ + auto it = m_attributes_str.find(attr); + retv_if(it == m_attributes_str.end(), OP_ERROR); + + *len = it->second.size(); + *value = new(std::nothrow) char[*len]; + std::copy(it->second.begin(), it->second.end(), *value); + + return OP_SUCCESS; +} + +void sensor_handler::update_attribute(int32_t attr, const char *value, int len) +{ + m_attributes_str[attr].clear(); + m_attributes_str[attr].insert(m_attributes_str[attr].begin(), value, value + len); + _I("[%s] attributes(int) size : %d", m_info.get_uri().c_str(), m_attributes_int.size()); + +} \ No newline at end of file diff --git a/src/server/sensor_handler.h b/src/server/sensor_handler.h index cb7bde8..e42a8e3 100644 --- a/src/server/sensor_handler.h +++ b/src/server/sensor_handler.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include namespace sensor { @@ -49,17 +51,23 @@ public: virtual int set_batch_latency(sensor_observer *ob, int32_t latency) = 0; virtual int delete_batch_latency(sensor_observer *ob); virtual int set_attribute(sensor_observer *ob, int32_t attr, int32_t value) = 0; + virtual int get_attribute(int32_t attr, int32_t* value); + void update_attribute(int32_t attr, int32_t value); virtual int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) = 0; + virtual int get_attribute(int32_t attr, char **value, int *len); + void update_attribute(int32_t attr, const char *value, int len); virtual int flush(sensor_observer *ob) = 0; virtual int get_data(sensor_data_t **data, int *len) = 0; void set_cache(sensor_data_t *data, int size); int get_cache(sensor_data_t **data, int *len); - bool notify_attribute_changed(int attribute, int value); - bool notify_attribute_changed(int attribute, const char *value, int len); + bool notify_attribute_changed(uint32_t id, int attribute, int value); + bool notify_attribute_changed(uint32_t id, int attribute, const char *value, int len); protected: sensor_info m_info; + std::map m_attributes_int; + std::map> m_attributes_str; private: std::list m_observers; diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index a52927d..f184e45 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -69,7 +69,7 @@ int sensor_listener_proxy::update(const char *uri, ipc::message *msg) int sensor_listener_proxy::on_attribute_changed(ipc::message *msg) { retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE); - + _I("Proxy[%zu] call on_attribute_changed\n", get_id()); m_ch->send(msg); return OP_CONTINUE; } @@ -207,6 +207,26 @@ int sensor_listener_proxy::set_attribute(int attribute, int value) return sensor->set_attribute(this, attribute, value); } +int sensor_listener_proxy::get_attribute(int attribute, int *value) +{ + sensor_handler *sensor = m_manager->get_sensor(m_uri); + retv_if(!sensor, -EINVAL); + + _D("Listener[%d] try to get attribute[%d] int", get_id(), attribute); + + if (attribute == SENSORD_ATTRIBUTE_PAUSE_POLICY) { + *value = m_pause_policy; + return OP_SUCCESS; + } else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) { + *value = m_axis_orientation; + return OP_SUCCESS; + } else if (attribute == SENSORD_ATTRIBUTE_FLUSH) { + return -EINVAL; + } + + return sensor->get_attribute(attribute, value); +} + int sensor_listener_proxy::set_attribute(int attribute, const char *value, int len) { sensor_handler *sensor = m_manager->get_sensor(m_uri); @@ -217,6 +237,16 @@ int sensor_listener_proxy::set_attribute(int attribute, const char *value, int l return sensor->set_attribute(this, attribute, value, len); } +int sensor_listener_proxy::get_attribute(int attribute, char **value, int *len) +{ + sensor_handler *sensor = m_manager->get_sensor(m_uri); + retv_if(!sensor, -EINVAL); + + _D("Listener[%d] try to get attribute str[%d]", get_id(), attribute); + + return sensor->get_attribute(attribute, value, len); +} + int sensor_listener_proxy::flush(void) { sensor_handler *sensor = m_manager->get_sensor(m_uri); @@ -262,7 +292,7 @@ bool sensor_listener_proxy::notify_attribute_changed(int attribute, int value) sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); - return sensor->notify_attribute_changed(attribute, value); + return sensor->notify_attribute_changed(m_id, attribute, value); } bool sensor_listener_proxy::notify_attribute_changed(int attribute, const char *value, int len) @@ -270,5 +300,5 @@ bool sensor_listener_proxy::notify_attribute_changed(int attribute, const char * sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); - return sensor->notify_attribute_changed(attribute, value, len); + return sensor->notify_attribute_changed(m_id, attribute, value, len); } \ No newline at end of file diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index f0d1dae..f87447b 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -49,7 +49,9 @@ public: int delete_batch_latency(void); int set_passive_mode(bool passive); int set_attribute(int attribute, int value); + int get_attribute(int attribute, int *value); int set_attribute(int attribute, const char *value, int len); + int get_attribute(int attribute, char **value, int *len); int flush(void); int get_data(sensor_data_t **data, int *len); std::string get_required_privileges(void); diff --git a/src/server/sensor_observer.h b/src/server/sensor_observer.h index 02603b0..ee04c20 100644 --- a/src/server/sensor_observer.h +++ b/src/server/sensor_observer.h @@ -30,7 +30,6 @@ public: /* for performance, use message */ virtual int update(const char *uri, ipc::message *msg) = 0; - virtual int on_attribute_changed(ipc::message *msg) = 0; }; } diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 86606df..c8c8d0b 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -89,12 +89,16 @@ void server_channel_handler::read(channel *ch, message &msg) err = listener_start(ch, msg); break; case CMD_LISTENER_STOP: err = listener_stop(ch, msg); break; - case CMD_LISTENER_ATTR_INT: - err = listener_attr_int(ch, msg); break; - case CMD_LISTENER_ATTR_STR: - err = listener_attr_str(ch, msg); break; + case CMD_LISTENER_SET_ATTR_INT: + err = listener_set_attr_int(ch, msg); break; + case CMD_LISTENER_SET_ATTR_STR: + err = listener_set_attr_str(ch, msg); break; case CMD_LISTENER_GET_DATA: err = listener_get_data(ch, msg); break; + case CMD_LISTENER_GET_ATTR_INT: + err = listener_get_attr_int(ch, msg); break; + case CMD_LISTENER_GET_ATTR_STR: + err = listener_get_attr_str(ch, msg); break; case CMD_PROVIDER_CONNECT: err = provider_connect(ch, msg); break; case CMD_PROVIDER_PUBLISH: @@ -202,7 +206,7 @@ int server_channel_handler::listener_stop(channel *ch, message &msg) return send_reply(ch, OP_SUCCESS); } -int server_channel_handler::listener_attr_int(channel *ch, message &msg) +int server_channel_handler::listener_set_attr_int(channel *ch, message &msg) { cmd_listener_attr_int_t buf; msg.disclose((char *)&buf); @@ -246,7 +250,7 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) return ret; } -int server_channel_handler::listener_attr_str(channel *ch, message &msg) +int server_channel_handler::listener_set_attr_str(channel *ch, message &msg) { uint32_t id; cmd_listener_attr_str_t *buf; @@ -282,6 +286,96 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) return ret; } +int server_channel_handler::listener_get_attr_int(ipc::channel *ch, ipc::message &msg) +{ + cmd_listener_attr_int_t buf; + msg.disclose((char *)&buf); + uint32_t id = buf.listener_id; + + int ret = OP_SUCCESS; + + auto it = m_listeners.find(id); + retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); + + switch (buf.attribute) { + case SENSORD_ATTRIBUTE_INTERVAL: + case SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY: + case SENSORD_ATTRIBUTE_PASSIVE_MODE: + // TODO : Are these features required? + ret = OP_ERROR; + break; + case SENSORD_ATTRIBUTE_PAUSE_POLICY: + case SENSORD_ATTRIBUTE_AXIS_ORIENTATION: + default: + ret = m_listeners[id]->get_attribute(buf.attribute, &buf.value); + } + + if (ret == OP_SUCCESS) { + message reply((char *)&buf, sizeof(buf)); + reply.set_type(CMD_LISTENER_GET_ATTR_INT); + ret = ch->send_sync(&reply); + } else { + ret = send_reply(ch, OP_ERROR); + } + + return ret; +} + +int server_channel_handler::listener_get_attr_str(ipc::channel *ch, ipc::message &msg) +{ + uint32_t id; + cmd_listener_attr_str_t *buf; + + buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[msg.size()]; + retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); + + msg.disclose((char *)buf); + + id = buf->listener_id; + auto it = m_listeners.find(id); + auto attr = buf->attribute; + delete [] buf; + + if (it == m_listeners.end()) { + return -EINVAL; + } + + if (!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges())) { + _E("Permission denied[%d, %s]", id, m_listeners[id]->get_required_privileges().c_str()); + return -EACCES; + } + + char *value = NULL; + int len = 0; + int ret = m_listeners[id]->get_attribute(attr, &value, &len); + + if (ret == OP_SUCCESS) { + cmd_listener_attr_str_t *reply_buf; + size_t size = sizeof(cmd_listener_attr_str_t) + len; + reply_buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; + retvm_if(!reply_buf, -ENOMEM, "Failed to allocate memory"); + + reply_buf->attribute = attr; + memcpy(reply_buf->value, value, len); + reply_buf->len = len; + delete [] value; + + ipc::message reply; + reply.enclose((char *)reply_buf, size); + reply.set_type(CMD_LISTENER_GET_ATTR_STR); + + ret = ch->send_sync(&reply); + delete [] reply_buf; + } else { + ret = send_reply(ch, OP_ERROR); + } + + return ret; +} + int server_channel_handler::listener_get_data(channel *ch, message &msg) { ipc::message reply; diff --git a/src/server/server_channel_handler.h b/src/server/server_channel_handler.h index befa663..6befe1c 100644 --- a/src/server/server_channel_handler.h +++ b/src/server/server_channel_handler.h @@ -53,9 +53,11 @@ private: int listener_disconnect(ipc::channel *ch, ipc::message &msg); int listener_start(ipc::channel *ch, ipc::message &msg); int listener_stop(ipc::channel *ch, ipc::message &msg); - int listener_attr_int(ipc::channel *ch, ipc::message &msg); - int listener_attr_str(ipc::channel *ch, ipc::message &msg); + int listener_set_attr_int(ipc::channel *ch, ipc::message &msg); + int listener_set_attr_str(ipc::channel *ch, ipc::message &msg); int listener_get_data(ipc::channel *ch, ipc::message &msg); + int listener_get_attr_int(ipc::channel *ch, ipc::message &msg); + int listener_get_attr_str(ipc::channel *ch, ipc::message &msg); int provider_connect(ipc::channel *ch, ipc::message &msg); int provider_disconnect(ipc::channel *ch, ipc::message &msg); diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 0bc2de5..5d98e46 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -43,9 +43,11 @@ enum cmd_type_e { CMD_LISTENER_CONNECT, CMD_LISTENER_START, CMD_LISTENER_STOP, - CMD_LISTENER_ATTR_INT, - CMD_LISTENER_ATTR_STR, + CMD_LISTENER_SET_ATTR_INT, + CMD_LISTENER_SET_ATTR_STR, CMD_LISTENER_GET_DATA, + CMD_LISTENER_GET_ATTR_INT, + CMD_LISTENER_GET_ATTR_STR, /* Provider */ CMD_PROVIDER_CONNECT = 0x300, @@ -79,13 +81,13 @@ typedef struct { int listener_id; } cmd_listener_stop_t; -typedef struct { +typedef struct { int listener_id; int attribute; int value; } cmd_listener_attr_int_t; -typedef struct { +typedef struct { int listener_id; int attribute; int len; -- 2.7.4 From ccf9ba4209e4fd281cadf7a764c724e508a04113 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Fri, 29 Nov 2019 13:35:56 +0900 Subject: [PATCH 15/16] Implement sensord_get_data_list * Add a command type CMD_LISTENER_GET_DATA_LIST * Add sensorctl tests * Now, you can use sensor_get_data_list instead of sensor_get_data Change-Id: I2c90e680a6b3f86076df5702f3b29d5ff7eec1bf Signed-off-by: Boram Bae --- include/sensor_internal.h | 11 ++ src/client-dummy/client_dummy.cpp | 5 + src/client/sensor_internal.cpp | 19 ++++ src/client/sensor_listener.cpp | 51 ++++++++- src/client/sensor_listener.h | 1 + src/sensorctl/testcase/sensor_listener.cpp | 50 +++++++++ src/sensorctl/testcase/sensor_provider.cpp | 160 +++++++++++++++++++++++++++++ src/server/server_channel_handler.cpp | 46 +++++++++ src/server/server_channel_handler.h | 1 + src/shared/command_types.h | 8 ++ 10 files changed, 349 insertions(+), 3 deletions(-) diff --git a/include/sensor_internal.h b/include/sensor_internal.h index 07638fd..1fbfabe 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -467,6 +467,17 @@ bool sensord_send_command(int handle, const char *command, int command_len); bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data); /** + * @brief get sensor data from a connected sensor + * + * @param[in] handle a handle represensting a connected context sensor. + * @param[in] data_id it specifies data to get + * @param[out] sensor_data the data list from connected sensor, the caller should explicitly free this list. + * @param[out] count the count of data contained in the list. + * @return true on success, otherwise false. + */ +bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count); + +/** * @brief flush sensor data from a connected sensor * * @param[in] handle a handle represensting a connected context sensor. diff --git a/src/client-dummy/client_dummy.cpp b/src/client-dummy/client_dummy.cpp index accc043..8432ba2 100644 --- a/src/client-dummy/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -233,6 +233,11 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso return false; } +API bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count) +{ + return false; +} + API bool sensord_flush(int handle) { return false; diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 376059c..950c28d 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -787,6 +787,25 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso return true; } +API bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count) +{ + sensor::sensor_listener *listener; + + AUTOLOCK(lock); + + auto it = listeners.find(handle); + retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle); + + listener = it->second; + + if (listener->get_sensor_data_list(sensor_data, count) < 0) { + _E("Failed to get sensor data from listener"); + return false; + } + + return true; +} + API bool sensord_flush(int handle) { sensor::sensor_listener *listener; diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index 6cea7d3..c979244 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -532,7 +532,6 @@ int sensor_listener::get_attribute(int attribute, int* value) m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { - _D("reply.header()->err < 0"); return reply.header()->err; } if (reply.header()->length && reply.body()) { @@ -606,7 +605,6 @@ int sensor_listener::get_attribute(int attribute, char **value, int* len) m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { - _D("reply.header()->err < 0"); return reply.header()->err; } @@ -660,4 +658,51 @@ int sensor_listener::get_sensor_data(sensor_data_t *data) _D("Listener[%d] read sensor data", get_id()); return OP_SUCCESS; -} \ No newline at end of file +} + +int sensor_listener::get_sensor_data_list(sensor_data_t **data, int *count) +{ + ipc::message msg; + ipc::message reply; + cmd_listener_get_data_list_t buf; + + retvm_if(!m_cmd_channel, -EIO, "Failed to connect to server"); + + buf.listener_id = m_id; + msg.set_type(CMD_LISTENER_GET_DATA_LIST); + msg.enclose((char *)&buf, sizeof(buf)); + + m_cmd_channel->send_sync(&msg); + m_cmd_channel->read_sync(reply); + + if (reply.header()->err < 0) { + return reply.header()->err; + } + + size_t size = reply.size(); + cmd_listener_get_data_list_t* reply_buf = (cmd_listener_get_data_list_t *) new(std::nothrow) char[size]; + + retvm_if(!reply_buf, -ENOMEM, "Failed to allocate memory"); + + reply.disclose((char *)reply_buf); + + if (reply_buf->len <= 0) { + delete [] reply_buf; + return OP_ERROR; + } + + *count = reply_buf->data_count; + *data = (sensor_data_t*) malloc(reply_buf->len); + + if (!(*data)) { + _E("Memory allocation failed"); + delete [] reply_buf; + return -ENOMEM; + } + + memcpy(*data, reply_buf->data, reply_buf->len); + + _D("Listener[%d] read sensor data list", get_id()); + delete [] reply_buf; + return OP_SUCCESS; +} diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h index 47cab20..581b2a1 100644 --- a/src/client/sensor_listener.h +++ b/src/client/sensor_listener.h @@ -75,6 +75,7 @@ public: int get_attribute(int attribute, char **value, int *len); void update_attribute(int attribute, const char *value, int len); int get_sensor_data(sensor_data_t *data); + int get_sensor_data_list(sensor_data_t **data, int *count); int flush(void); void restore(void); diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index c5adee2..6fc6bf4 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -427,6 +427,56 @@ TESTCASE(sensor_listener, get_attribute_string_2) return true; } +#define SENSOR_SHIFT_TYPE 16 +TESTCASE(sensor_listener, get_data_list) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + sensor_type_t type; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + + sensord_get_type(sensor, &type); + ASSERT_EQ(err, 0); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + sensor_data_t* data_list = NULL; + int count = 0; + unsigned int data_id = type << SENSOR_SHIFT_TYPE | 0x1; + + ret = sensord_get_data_list(handle, data_id, &data_list, &count); + ASSERT_TRUE(ret); + ASSERT_EQ(count, 1); + + for (int i = 0 ; i < count; i++) { + _I("[%llu]", data_list[i].timestamp); + for (int j = 0; j < data_list[i].value_count; j++) + _I(" %f", data_list[i].values[j]); + _I("\n"); + } + free(data_list); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_unregister_events(handle, 1); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + void sensor_attribute_int_changed_callback(sensor_t sensor, int attribute, int value, void *data) { _I("[ATTRIBUTE INT CHANGED] attribute : %d, value : %d\n", attribute, value); diff --git a/src/sensorctl/testcase/sensor_provider.cpp b/src/sensorctl/testcase/sensor_provider.cpp index bcd5101..d7ed1bb 100644 --- a/src/sensorctl/testcase/sensor_provider.cpp +++ b/src/sensorctl/testcase/sensor_provider.cpp @@ -356,3 +356,163 @@ TESTCASE(skip_sensor_provider, mysensor_batch_with_listener_p_1) return true; } + +TESTCASE(skip_sensor_provider, mysensor_batch_events_once) +{ + int err = 0; + bool ret = false; + sensor_t sensor; + sensord_provider_h provider; + + err = sensord_create_provider(MYSENSOR_BATCH_URI, &provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_name(provider, MYSENSOR_BATCH_NAME); + ASSERT_EQ(err, 0); + err = sensord_provider_set_vendor(provider, MYSENSOR_VENDOR); + ASSERT_EQ(err, 0); + err = sensord_provider_set_range(provider, 0.0f, 1.0f); + ASSERT_EQ(err, 0); + err = sensord_provider_set_resolution(provider, 0.01f); + ASSERT_EQ(err, 0); + + err = sensord_add_provider(provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_start_cb(provider, start_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_stop_cb(provider, stop_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_interval_changed_cb(provider, interval_cb, NULL); + ASSERT_EQ(err, 0); + + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &sensor); + ASSERT_EQ(err, 0); + + int client_handle; + sensor_t client_sensor; + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &client_sensor); + ASSERT_EQ(err, 0); + client_handle = sensord_connect(client_sensor); + ASSERT_EQ(err, 0); + + ret = sensord_start(client_handle, 0); + ASSERT_TRUE(ret); + + sensor_data_t data[NUMBER_OF_EVENT]; + for (int i = 0 ; i < NUMBER_OF_EVENT; i++) { + data[i].accuracy = 3; + data[i].timestamp = sensor::utils::get_timestamp(); + data[i].value_count = 3; + data[i].values[0] = i; + data[i].values[1] = i; + data[i].values[2] = i; + } + err = sensord_provider_publish_events(provider, data, NUMBER_OF_EVENT); + ASSERT_EQ(err, 0); + + ret = sensord_stop(client_handle); + ASSERT_TRUE(ret); + ret = sensord_disconnect(client_handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + err = sensord_remove_provider(provider); + ASSERT_EQ(err, 0); + err = sensord_destroy_provider(provider); + ASSERT_EQ(err, 0); + + return true; +} + +TESTCASE(skip_sensor_provider, mysensor_batch_p_without_publish) +{ + int err = 0; + sensor_t sensor; + sensord_provider_h provider; + + err = sensord_create_provider(MYSENSOR_BATCH_URI, &provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_name(provider, MYSENSOR_BATCH_NAME); + ASSERT_EQ(err, 0); + err = sensord_provider_set_vendor(provider, MYSENSOR_VENDOR); + ASSERT_EQ(err, 0); + err = sensord_provider_set_range(provider, 0.0f, 1.0f); + ASSERT_EQ(err, 0); + err = sensord_provider_set_resolution(provider, 0.01f); + ASSERT_EQ(err, 0); + + err = sensord_add_provider(provider); + ASSERT_EQ(err, 0); + + err = sensord_provider_set_start_cb(provider, start_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_stop_cb(provider, stop_cb, NULL); + ASSERT_EQ(err, 0); + err = sensord_provider_set_interval_changed_cb(provider, interval_cb, NULL); + ASSERT_EQ(err, 0); + + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &sensor); + ASSERT_EQ(err, 0); + + mainloop::run(); + + err = sensord_remove_provider(provider); + ASSERT_EQ(err, 0); + err = sensord_destroy_provider(provider); + ASSERT_EQ(err, 0); + + return true; +} + +#define SENSOR_SHIFT_TYPE 16 +TESTCASE(skip_sensor_provider, mysensor_get_data_list) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + sensor_type_t type; + + called = false; + + err = sensord_get_default_sensor_by_uri(MYSENSOR_BATCH_URI, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + + sensord_get_type(sensor, &type); + ASSERT_EQ(err, 0); + + ret = sensord_start(handle, 0); + ASSERT_TRUE(ret); + + sensor_data_t* data_list = NULL; + int count = 0; + unsigned int data_id = type << SENSOR_SHIFT_TYPE | 0x1; + + ret = sensord_get_data_list(handle, data_id, &data_list, &count); + ASSERT_TRUE(ret); + ASSERT_EQ(count, NUMBER_OF_EVENT); + + for (int i = 0 ; i < count; i++) { + _I("[%llu]", data_list[i].timestamp); + for (int j = 0; j < data_list[i].value_count; j++) + _I(" %f", data_list[i].values[j]); + _I("\n"); + } + free(data_list); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_unregister_events(handle, 1); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} \ No newline at end of file diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index c8c8d0b..69f15f4 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -99,6 +99,8 @@ void server_channel_handler::read(channel *ch, message &msg) err = listener_get_attr_int(ch, msg); break; case CMD_LISTENER_GET_ATTR_STR: err = listener_get_attr_str(ch, msg); break; + case CMD_LISTENER_GET_DATA_LIST: + err = listener_get_data_list(ch, msg); break; case CMD_PROVIDER_CONNECT: err = provider_connect(ch, msg); break; case CMD_PROVIDER_PUBLISH: @@ -410,6 +412,50 @@ int server_channel_handler::listener_get_data(channel *ch, message &msg) return OP_SUCCESS; } +int server_channel_handler::listener_get_data_list(ipc::channel *ch, ipc::message &msg) +{ + ipc::message reply; + cmd_listener_get_data_list_t buf; + sensor_data_t *data; + int len; + uint32_t id; + + msg.disclose((char *)&buf); + id = buf.listener_id; + + auto it = m_listeners.find(id); + retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); + + int ret = m_listeners[id]->get_data(&data, &len); + retv_if(ret < 0, ret); + + size_t reply_size = sizeof(cmd_listener_get_data_list_t) + len; + cmd_listener_get_data_list_t* reply_buf = (cmd_listener_get_data_list_t *) malloc(reply_size); + if (!reply_buf) { + _E("Failed to allocate memory"); + free(data); + return -ENOMEM; + } + + memcpy(reply_buf->data, data, len); + reply_buf->len = len; + reply_buf->data_count = len / sizeof(sensor_data_t); + reply.enclose((const char *)reply_buf, reply_size); + reply.header()->err = OP_SUCCESS; + reply.header()->type = CMD_LISTENER_GET_DATA_LIST; + + ch->send_sync(&reply); + + free(data); + free(reply_buf); + + return OP_SUCCESS; + +} + int server_channel_handler::provider_connect(channel *ch, message &msg) { sensor_info info; diff --git a/src/server/server_channel_handler.h b/src/server/server_channel_handler.h index 6befe1c..456c4d1 100644 --- a/src/server/server_channel_handler.h +++ b/src/server/server_channel_handler.h @@ -58,6 +58,7 @@ private: int listener_get_data(ipc::channel *ch, ipc::message &msg); int listener_get_attr_int(ipc::channel *ch, ipc::message &msg); int listener_get_attr_str(ipc::channel *ch, ipc::message &msg); + int listener_get_data_list(ipc::channel *ch, ipc::message &msg); int provider_connect(ipc::channel *ch, ipc::message &msg); int provider_disconnect(ipc::channel *ch, ipc::message &msg); diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 5d98e46..7acf878 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -48,6 +48,7 @@ enum cmd_type_e { CMD_LISTENER_GET_DATA, CMD_LISTENER_GET_ATTR_INT, CMD_LISTENER_GET_ATTR_STR, + CMD_LISTENER_GET_DATA_LIST, /* Provider */ CMD_PROVIDER_CONNECT = 0x300, @@ -101,6 +102,13 @@ typedef struct { } cmd_listener_get_data_t; typedef struct { + int listener_id; + int len; + int data_count; + sensor_data_t data[0]; +} cmd_listener_get_data_list_t; + +typedef struct { char info[0]; } cmd_provider_connect_t; -- 2.7.4 From 638806e5844cc9401d0792e66caad4e07fb20040 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Tue, 3 Dec 2019 10:31:09 +0900 Subject: [PATCH 16/16] Use share_ptr to send message, Use reference to send_sync message * fix some memory leak Change-Id: I20bbc5e29fa1ed9f801b3f6bb904b49fea857506 Signed-off-by: Boram Bae --- src/client/sensor_internal.cpp | 3 +- src/client/sensor_listener.cpp | 18 +++++----- src/client/sensor_manager.cpp | 6 ++-- src/client/sensor_provider.cpp | 8 ++--- src/sensorctl/testcase/sensor_listener.cpp | 31 +++++++++++++++++ src/sensorctl/testcase/unit_ipc.cpp | 16 ++++----- src/server/application_sensor_handler.cpp | 8 ++--- src/server/fusion_sensor_handler.cpp | 2 +- src/server/fusion_sensor_handler.h | 2 +- src/server/sensor_handler.cpp | 21 +++--------- src/server/sensor_listener_proxy.cpp | 11 ++++--- src/server/sensor_listener_proxy.h | 8 ++--- src/server/sensor_manager.cpp | 16 ++++++--- src/server/sensor_observer.h | 3 +- src/server/server_channel_handler.cpp | 19 ++++++----- src/shared/channel.cpp | 39 +++++++++++----------- src/shared/channel.h | 4 +-- src/shared/ipc_server.cpp | 1 + src/shared/message.cpp | 53 ++++++++---------------------- src/shared/message.h | 9 ++++- 20 files changed, 144 insertions(+), 134 deletions(-) diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 950c28d..0695e63 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -746,6 +746,7 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, _E("Failed to set attribute[%d, %s]", attribute, value); return -EIO; } + _D("Set attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, len); return OP_SUCCESS; } @@ -763,7 +764,7 @@ API int sensord_get_attribute_str(int handle, int attribute, char **value, int* _E("Failed to get attribute[%d]", attribute); return -EIO; } - _D("Get attribute[%d, %d, %s]", listener->get_id(), attribute, *value); + _D("Get attribute ID[%d], attr[%d], len[%d]", listener->get_id(), attribute, *len); return OP_SUCCESS; } diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index c979244..612c1ad 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -224,7 +224,7 @@ bool sensor_listener::connect(void) memcpy(buf.sensor, m_sensor->get_uri().c_str(), m_sensor->get_uri().size()); msg.set_type(CMD_LISTENER_CONNECT); msg.enclose((const char *)&buf, sizeof(buf)); - m_evt_channel->send_sync(&msg); + m_evt_channel->send_sync(msg); m_evt_channel->read_sync(reply); reply.disclose((char *)&buf); @@ -364,7 +364,7 @@ int sensor_listener::start(void) msg.set_type(CMD_LISTENER_START); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { @@ -392,7 +392,7 @@ int sensor_listener::stop(void) msg.set_type(CMD_LISTENER_STOP); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { @@ -503,7 +503,7 @@ int sensor_listener::set_attribute(int attribute, int value) msg.set_type(CMD_LISTENER_SET_ATTR_INT); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) @@ -527,7 +527,7 @@ int sensor_listener::get_attribute(int attribute, int* value) msg.set_type(CMD_LISTENER_GET_ATTR_INT); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); @@ -572,7 +572,7 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len) msg.enclose((char *)buf, size); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); /* Message memory is released automatically after sending message, @@ -601,7 +601,7 @@ int sensor_listener::get_attribute(int attribute, char **value, int* len) msg.set_type(CMD_LISTENER_GET_ATTR_STR); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { @@ -640,7 +640,7 @@ int sensor_listener::get_sensor_data(sensor_data_t *data) msg.set_type(CMD_LISTENER_GET_DATA); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); reply.disclose((char *)&buf); @@ -672,7 +672,7 @@ int sensor_listener::get_sensor_data_list(sensor_data_t **data, int *count) msg.set_type(CMD_LISTENER_GET_DATA_LIST); msg.enclose((char *)&buf, sizeof(buf)); - m_cmd_channel->send_sync(&msg); + m_cmd_channel->send_sync(msg); m_cmd_channel->read_sync(reply); if (reply.header()->err < 0) { diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index f16601f..64b623c 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -207,7 +207,7 @@ bool sensor_manager::connect_channel(void) retvm_if(!m_mon_channel, false, "Failed to connect to server"); msg.set_type(CMD_MANAGER_CONNECT); - m_mon_channel->send_sync(&msg); + m_mon_channel->send_sync(msg); m_connected.store(true); @@ -290,7 +290,7 @@ bool sensor_manager::get_sensors_internal(void) msg.set_type(CMD_MANAGER_SENSOR_LIST); - ret = m_cmd_channel->send_sync(&msg); + ret = m_cmd_channel->send_sync(msg); retvm_if(!ret, false, "Failed to send message"); ret = m_cmd_channel->read_sync(reply); @@ -316,7 +316,7 @@ bool sensor_manager::has_privilege(std::string &uri) memcpy(buf.sensor, uri.c_str(), uri.size()); msg.enclose((const char *)&buf, sizeof(buf)); - ret = m_cmd_channel->send_sync(&msg); + ret = m_cmd_channel->send_sync(msg); retvm_if(!ret, false, "Failed to send message"); ret = m_cmd_channel->read_sync(reply); diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index a90f7c2..414e83f 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -100,7 +100,7 @@ int sensor_provider::serialize(sensor_info *info, char **bytes) info->serialize(*raw); - *bytes = new(std::nothrow) char[raw->size()]; + *bytes = (char *) malloc(raw->size()); retvm_if(!*bytes, -ENOMEM, "Failed to allocate memory"); std::copy(raw->begin(), raw->end(), *bytes); @@ -121,7 +121,7 @@ int sensor_provider::send_sensor_info(sensor_info *info) ipc::message msg((const char *)bytes, size); msg.set_type(CMD_PROVIDER_CONNECT); - m_channel->send_sync(&msg); + m_channel->send_sync(msg); return OP_SUCCESS; } @@ -174,7 +174,7 @@ int sensor_provider::publish(const sensor_data_t &data) msg.set_type(CMD_PROVIDER_PUBLISH); msg.enclose((const void *)(&data), sizeof(data)); - m_channel->send_sync(&msg); + m_channel->send_sync(msg); return OP_SUCCESS; } @@ -185,7 +185,7 @@ int sensor_provider::publish(const sensor_data_t data[], const int count) msg.set_type(CMD_PROVIDER_PUBLISH); msg.enclose((const void *)data, sizeof(sensor_data_t) * count); - m_channel->send_sync(&msg); + m_channel->send_sync(msg); return OP_SUCCESS; } diff --git a/src/sensorctl/testcase/sensor_listener.cpp b/src/sensorctl/testcase/sensor_listener.cpp index 6fc6bf4..70050b0 100644 --- a/src/sensorctl/testcase/sensor_listener.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -355,6 +355,37 @@ TESTCASE(sensor_listener, set_get_attribute_string_1) return true; } +#define BUF_SIZE 4000 +TESTCASE(sensor_listener, set_get_attribute_string_2) +{ + int err = 0; + bool ret = true; + int handle = 0; + char *value = NULL; + int len = 0; + sensor_t sensor = NULL; + int attr = 1; + char attr_value[BUF_SIZE] = {1, }; + attr_value[BUF_SIZE - 1] = 1; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + err = sensord_set_attribute_str(handle, attr, attr_value, BUF_SIZE); + ASSERT_EQ(err, 0); + + err = sensord_get_attribute_str(handle, attr, &value, &len); + ASSERT_EQ(err, 0); + ASSERT_EQ(len, BUF_SIZE); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + free(value); + return true; +} + TESTCASE(sensor_listener, set_get_get_attribute_string_1) { int err; diff --git a/src/sensorctl/testcase/unit_ipc.cpp b/src/sensorctl/testcase/unit_ipc.cpp index c11d439..10e11e4 100644 --- a/src/sensorctl/testcase/unit_ipc.cpp +++ b/src/sensorctl/testcase/unit_ipc.cpp @@ -61,7 +61,7 @@ public: { char buf[MAX_BUF_SIZE]; - message *reply = new(std::nothrow) message(); + auto reply = message::create(); RETM_IF(!reply, "Failed to allocate memory"); msg.disclose(buf); @@ -117,7 +117,7 @@ static bool run_ipc_client_sleep_1s(const char *str, int size, int count) msg.enclose(buf, MAX_BUF_SIZE); SLEEP_1S; - ch->send_sync(&msg); + ch->send_sync(msg); /* Test */ SLEEP_1S; @@ -162,7 +162,7 @@ static bool run_ipc_client_small_buffer(const char *str, int size, int count) _I("After: Buffer size : %d\n", buf_size); for (int i = 0; i < 1024; ++i) { - ch->send_sync(&msg); + ch->send_sync(msg); ch->read_sync(reply); } @@ -197,7 +197,7 @@ static bool run_ipc_client_1M(const char *str, int size, int count) SLEEP_1S; for (int i = 0; i < 256; ++i) { - ch->send_sync(&msg); + ch->send_sync(msg); ch->read_sync(reply); } @@ -224,7 +224,7 @@ public: char buf[MAX_BUF_SIZE]; msg.disclose(buf); - message *reply = new(std::nothrow) message(); + auto reply = message::create(); if (!reply) return; reply->enclose("TEXTTEXTTEXTTEXT", 16); @@ -278,7 +278,7 @@ static bool run_ipc_client_2_channel_message(const char *str, int size, int coun ASSERT_NE(ch[0], 0); msg.enclose("TESTTESTTEST", 12); - ch[0]->send_sync(&msg); + ch[0]->send_sync(msg); SLEEP_1S; ch[0]->read_sync(reply); reply.disclose(buf); @@ -289,7 +289,7 @@ static bool run_ipc_client_2_channel_message(const char *str, int size, int coun ASSERT_NE(ch[1], 0); msg.enclose("TESTTESTTEST", 12); - ch[1]->send_sync(&msg); + ch[1]->send_sync(msg); SLEEP_1S; ch[1]->read_sync(reply); reply.disclose(buf); @@ -338,7 +338,7 @@ static bool run_ipc_client(const char *str, int size, int count) char buf[MAX_BUF_SIZE]; msg.enclose("TESTTESTTEST", 12); - ch->send_sync(&msg); + ch->send_sync(msg); SLEEP_1S; diff --git a/src/server/application_sensor_handler.cpp b/src/server/application_sensor_handler.cpp index df5db08..fe1aac3 100644 --- a/src/server/application_sensor_handler.cpp +++ b/src/server/application_sensor_handler.cpp @@ -58,7 +58,7 @@ int application_sensor_handler::start(sensor_observer *ob) ipc::message msg; msg.set_type(CMD_PROVIDER_START); - m_ch->send_sync(&msg); + m_ch->send_sync(msg); m_started.store(true); _I("Started[%s]", m_info.get_uri().c_str()); @@ -75,7 +75,7 @@ int application_sensor_handler::stop(sensor_observer *ob) ipc::message msg; msg.set_type(CMD_PROVIDER_STOP); - m_ch->send_sync(&msg); + m_ch->send_sync(msg); m_started.store(false); _I("Stopped[%s]", m_info.get_uri().c_str()); @@ -119,7 +119,7 @@ int application_sensor_handler::set_interval(sensor_observer *ob, int32_t interv msg.set_type(CMD_PROVIDER_ATTR_INT); msg.enclose((const char *)&buf, sizeof(cmd_provider_attr_int_t)); - m_ch->send_sync(&msg); + m_ch->send_sync(msg); m_prev_interval = cur_interval; @@ -157,7 +157,7 @@ int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, msg.enclose((char *)buf, size); - m_ch->send_sync(&msg); + m_ch->send_sync(msg); _I("Set attribute[%d] to sensor[%s]", attr, m_info.get_uri().c_str()); update_attribute(attr, value, len); diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index 5d5a8d1..1ede44c 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -43,7 +43,7 @@ void fusion_sensor_handler::add_required_sensor(uint32_t id, sensor_handler *sen m_required_sensors.emplace(info.get_uri(), required_sensor(id, sensor)); } -int fusion_sensor_handler::update(const char *uri, ipc::message *msg) +int fusion_sensor_handler::update(const char *uri, std::shared_ptr msg) { retv_if(!m_sensor, -EINVAL); diff --git a/src/server/fusion_sensor_handler.h b/src/server/fusion_sensor_handler.h index 9feb67f..e5d6db3 100644 --- a/src/server/fusion_sensor_handler.h +++ b/src/server/fusion_sensor_handler.h @@ -50,7 +50,7 @@ public: void add_required_sensor(uint32_t id, sensor_handler *sensor); /* subscriber */ - int update(const char *uri, ipc::message *msg); + int update(const char *uri, std::shared_ptr msg); /* sensor interface */ const sensor_info &get_sensor_info(void); diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index 843c794..9ae43a3 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -81,9 +81,8 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len) if (observer_count() == 0) return OP_ERROR; - ipc::message *msg; + auto msg = ipc::message::create((char *)data, len); - msg = new(std::nothrow) ipc::message((char *)data, len); retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); for (auto it = m_observers.begin(); it != m_observers.end(); ++it) @@ -91,10 +90,6 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len) set_cache(data, len); - if (msg->ref_count() == 0) { - msg->unref(); - } - return OP_SUCCESS; } @@ -141,8 +136,8 @@ bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, int va buf.attribute = attribute; buf.value = value; - ipc::message *msg; - msg = new(std::nothrow) ipc::message(); + auto msg = ipc::message::create(); + retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); msg->set_type(CMD_LISTENER_SET_ATTR_INT); @@ -156,9 +151,6 @@ bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, int va } } - if (msg->ref_count() == 0) - msg->unref(); - return OP_SUCCESS; } @@ -173,8 +165,7 @@ bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, const buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size]; retvm_if(!buf, -ENOMEM, "Failed to allocate memory"); - ipc::message *msg; - msg = new(std::nothrow) ipc::message(); + auto msg = ipc::message::create(); retvm_if(!msg, OP_ERROR, "Failed to allocate memory"); buf->listener_id = id; @@ -194,10 +185,6 @@ bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, const } } - if (msg->ref_count() == 0) { - msg->unref(); - } - delete[] buf; return OP_SUCCESS; diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index f184e45..0862774 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -56,7 +56,7 @@ uint32_t sensor_listener_proxy::get_id(void) return m_id; } -int sensor_listener_proxy::update(const char *uri, ipc::message *msg) +int sensor_listener_proxy::update(const char *uri, std::shared_ptr msg) { retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE); @@ -66,7 +66,7 @@ int sensor_listener_proxy::update(const char *uri, ipc::message *msg) return OP_CONTINUE; } -int sensor_listener_proxy::on_attribute_changed(ipc::message *msg) +int sensor_listener_proxy::on_attribute_changed(std::shared_ptr msg) { retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE); _I("Proxy[%zu] call on_attribute_changed\n", get_id()); @@ -74,7 +74,7 @@ int sensor_listener_proxy::on_attribute_changed(ipc::message *msg) return OP_CONTINUE; } -void sensor_listener_proxy::update_event(ipc::message *msg) +void sensor_listener_proxy::update_event(std::shared_ptr msg) { /* TODO: check axis orientation */ msg->header()->type = CMD_LISTENER_EVENT; @@ -83,7 +83,7 @@ void sensor_listener_proxy::update_event(ipc::message *msg) m_ch->send(msg); } -void sensor_listener_proxy::update_accuracy(ipc::message *msg) +void sensor_listener_proxy::update_accuracy(std::shared_ptr msg) { sensor_data_t *data = reinterpret_cast(msg->body()); @@ -95,7 +95,8 @@ void sensor_listener_proxy::update_accuracy(ipc::message *msg) sensor_data_t acc_data; acc_data.accuracy = m_last_accuracy; - ipc::message *acc_msg = new(std::nothrow) ipc::message(); + auto acc_msg = ipc::message::create(); + retm_if(!acc_msg, "Failed to allocate memory"); acc_msg->header()->type = CMD_LISTENER_ACC_EVENT; diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index f87447b..084ffe2 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -38,8 +38,8 @@ public: uint32_t get_id(void); /* sensor observer */ - int update(const char *uri, ipc::message *msg); - int on_attribute_changed(ipc::message *msg); + int update(const char *uri, std::shared_ptr msg); + int on_attribute_changed(std::shared_ptr msg); int start(bool policy = false); int stop(bool policy = false); @@ -62,8 +62,8 @@ public: bool notify_attribute_changed(int attribute, const char *value, int len); private: - void update_event(ipc::message *msg); - void update_accuracy(ipc::message *msg); + void update_event(std::shared_ptr msg); + void update_accuracy(std::shared_ptr msg); uint32_t m_id; std::string m_uri; diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index f6cc1f5..6173800 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -115,7 +115,7 @@ int sensor_manager::serialize(sensor_info *info, char **bytes) info->serialize(*raw); - *bytes = new(std::nothrow) char[raw->size()]; + *bytes = (char *) malloc(raw->size()); retvm_if(!*bytes, -ENOMEM, "Failed to allocate memory"); std::copy(raw->begin(), raw->end(), *bytes); @@ -129,7 +129,7 @@ int sensor_manager::serialize(sensor_info *info, char **bytes) void sensor_manager::send(ipc::message &msg) { for (auto it = m_channels.begin(); it != m_channels.end(); ++it) - (*it)->send_sync(&msg); + (*it)->send_sync(msg); } void sensor_manager::send_added_msg(sensor_info *info) @@ -410,8 +410,16 @@ void sensor_manager::register_handler(physical_sensor_handler *sensor) handler->add_sensor(sensor); m_event_handlers[fd] = handler; - m_loop->add_event(fd, - ipc::EVENT_IN | ipc::EVENT_HUP | ipc::EVENT_NVAL, handler); + if (m_loop->add_event(fd, ipc::EVENT_IN | ipc::EVENT_HUP | ipc::EVENT_NVAL, handler) == 0) { + _D("Failed to add sensor event handler"); + handler->remove_sensor(sensor); + + auto iter = m_event_handlers.find(fd); + if (iter != m_event_handlers.end()) { + m_event_handlers.erase(iter); + } + delete handler; + } } void sensor_manager::show(void) diff --git a/src/server/sensor_observer.h b/src/server/sensor_observer.h index ee04c20..9c86061 100644 --- a/src/server/sensor_observer.h +++ b/src/server/sensor_observer.h @@ -28,8 +28,7 @@ class sensor_observer { public: virtual ~sensor_observer() {} - /* for performance, use message */ - virtual int update(const char *uri, ipc::message *msg) = 0; + virtual int update(const char *uri, std::shared_ptr msg) = 0; }; } diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 69f15f4..0058c17 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -112,7 +112,7 @@ void server_channel_handler::read(channel *ch, message &msg) if (err != 0) { message reply(err); - ch->send_sync(&reply); + ch->send_sync(reply); } } @@ -133,7 +133,7 @@ int server_channel_handler::manager_get_sensor_list(channel *ch, message &msg) reply.enclose((const char *)bytes, size); reply.header()->err = OP_SUCCESS; - ch->send_sync(&reply); + ch->send_sync(reply); delete [] bytes; @@ -161,7 +161,7 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) reply.enclose((const char *)&buf, sizeof(buf)); reply.header()->err = OP_SUCCESS; - if (!ch->send_sync(&reply)) + if (!ch->send_sync(reply)) return OP_ERROR; _I("Connected sensor_listener[fd(%d) -> id(%u)]", ch->get_fd(), listener_id); @@ -316,9 +316,10 @@ int server_channel_handler::listener_get_attr_int(ipc::channel *ch, ipc::message } if (ret == OP_SUCCESS) { - message reply((char *)&buf, sizeof(buf)); + message reply; + reply.enclose((char *)&buf, sizeof(buf)); reply.set_type(CMD_LISTENER_GET_ATTR_INT); - ret = ch->send_sync(&reply); + ret = ch->send_sync(reply); } else { ret = send_reply(ch, OP_ERROR); } @@ -369,7 +370,7 @@ int server_channel_handler::listener_get_attr_str(ipc::channel *ch, ipc::message reply.enclose((char *)reply_buf, size); reply.set_type(CMD_LISTENER_GET_ATTR_STR); - ret = ch->send_sync(&reply); + ret = ch->send_sync(reply); delete [] reply_buf; } else { ret = send_reply(ch, OP_ERROR); @@ -405,7 +406,7 @@ int server_channel_handler::listener_get_data(channel *ch, message &msg) reply.header()->err = OP_SUCCESS; reply.header()->type = CMD_LISTENER_GET_DATA; - ch->send_sync(&reply); + ch->send_sync(reply); free(data); @@ -447,7 +448,7 @@ int server_channel_handler::listener_get_data_list(ipc::channel *ch, ipc::messag reply.header()->err = OP_SUCCESS; reply.header()->type = CMD_LISTENER_GET_DATA_LIST; - ch->send_sync(&reply); + ch->send_sync(reply); free(data); free(reply_buf); @@ -514,7 +515,7 @@ int server_channel_handler::has_privileges(channel *ch, message &msg) int server_channel_handler::send_reply(channel *ch, int error) { message reply(error); - retvm_if(!ch->send_sync(&reply), OP_ERROR, "Failed to send reply"); + retvm_if(!ch->send_sync(reply), OP_ERROR, "Failed to send reply"); return OP_SUCCESS; } diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index f27e1d4..6df1d2f 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -33,7 +33,7 @@ using namespace ipc; class send_event_handler : public event_handler { public: - send_event_handler(channel *ch, message *msg) + send_event_handler(channel *ch, std::shared_ptr msg) : m_ch(ch) , m_msg(msg) { } @@ -46,18 +46,15 @@ public: if (condition & (EVENT_IN | EVENT_HUP)) return false; - if (!m_ch->send_sync(m_msg)) + if (!m_ch->send_sync(*m_msg)) return false; - if (m_msg) - m_msg->unref(); - return false; } private: channel *m_ch; - message *m_msg; + std::shared_ptr m_msg; }; class read_event_handler : public event_handler @@ -173,7 +170,7 @@ void channel::disconnect(void) _D("Disconnected"); } -bool channel::send(message *msg) +bool channel::send(std::shared_ptr msg) { int retry_cnt = 0; int cur_buffer_size = 0; @@ -192,32 +189,32 @@ bool channel::send(message *msg) send_event_handler *handler = new(std::nothrow) send_event_handler(this, msg); retvm_if(!handler, false, "Failed to allocate memory"); - msg->ref(); - - m_loop->add_event(m_socket->get_fd(), - (EVENT_OUT | EVENT_HUP | EVENT_NVAL) , handler); + if (m_loop->add_event(m_socket->get_fd(), (EVENT_OUT | EVENT_HUP | EVENT_NVAL) , handler) == 0) { + _D("Failed to add send event handler"); + delete handler; + return false; + } return true; } -bool channel::send_sync(message *msg) +bool channel::send_sync(message &msg) { - retvm_if(!msg, false, "Invalid message"); - retvm_if(msg->size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg->size()); + retvm_if(msg.size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg.size()); ssize_t size = 0; - char *buf = msg->body(); + char *buf = msg.body(); /* header */ - size = m_socket->send(reinterpret_cast(msg->header()), + size = m_socket->send(reinterpret_cast(msg.header()), sizeof(message_header), true); retvm_if(size <= 0, false, "Failed to send header"); /* if body size is zero, skip to send body message */ - retv_if(msg->size() == 0, true); + retv_if(msg.size() == 0, true); /* body */ - size = m_socket->send(buf, msg->size(), true); + size = m_socket->send(buf, msg.size(), true); retvm_if(size <= 0, false, "Failed to send body"); return true; @@ -230,7 +227,11 @@ bool channel::read(void) read_event_handler *handler = new(std::nothrow) read_event_handler(this); retvm_if(!handler, false, "Failed to allocate memory"); - m_loop->add_event(m_socket->get_fd(), (EVENT_IN | EVENT_HUP | EVENT_NVAL), handler); + if (m_loop->add_event(m_socket->get_fd(), (EVENT_IN | EVENT_HUP | EVENT_NVAL), handler) == 0) { + _D("Failed to add read event handler"); + delete handler; + return false; + } return true; } diff --git a/src/shared/channel.h b/src/shared/channel.h index efdc481..615fd26 100644 --- a/src/shared/channel.h +++ b/src/shared/channel.h @@ -46,8 +46,8 @@ public: bool is_connected(void); - bool send(message *msg); - bool send_sync(message *msg); + bool send(std::shared_ptr msg); + bool send_sync(message &msg); bool read(void); bool read_sync(message &msg, bool select = true); diff --git a/src/shared/ipc_server.cpp b/src/shared/ipc_server.cpp index 66431da..f847c4d 100644 --- a/src/shared/ipc_server.cpp +++ b/src/shared/ipc_server.cpp @@ -98,6 +98,7 @@ void ipc_server::register_acceptor(void) (event_condition)(EVENT_IN | EVENT_HUP | EVENT_NVAL), m_accept_handler); if (id == 0) { + _D("Failed to add accept event handler"); delete m_accept_handler; m_accept_handler = NULL; } diff --git a/src/shared/message.cpp b/src/shared/message.cpp index d7455eb..f28780d 100644 --- a/src/shared/message.cpp +++ b/src/shared/message.cpp @@ -29,10 +29,9 @@ using namespace ipc; static std::atomic sequence(0); message::message(size_t capacity) -: m_size(0) -, m_capacity(capacity) -, m_msg((char *)malloc(sizeof(char) * capacity)) -, ref_cnt(0) + : m_size(0) + , m_capacity(capacity) + , m_msg((char *)malloc(sizeof(char) * capacity)) { m_header.id = sequence++; m_header.type = UNDEFINED_TYPE; @@ -41,10 +40,9 @@ message::message(size_t capacity) } message::message(const void *msg, size_t sz) -: m_size(sz) -, m_capacity(sz) -, m_msg((char *)msg) -, ref_cnt(0) + : m_size(sz) + , m_capacity(sz) + , m_msg((char *)msg) { m_header.id = sequence++; m_header.type = UNDEFINED_TYPE; @@ -53,20 +51,18 @@ message::message(const void *msg, size_t sz) } message::message(const message &msg) -: m_size(msg.m_size) -, m_capacity(msg.m_capacity) -, m_msg((char *)malloc(sizeof(char) * msg.m_capacity)) -, ref_cnt(0) + : m_size(msg.m_size) + , m_capacity(msg.m_capacity) + , m_msg((char *)malloc(sizeof(char) * msg.m_capacity)) { ::memcpy(&m_header, &msg.m_header, sizeof(message_header)); ::memcpy(m_msg, msg.m_msg, msg.m_size); } message::message(int error) -: m_size(0) -, m_capacity(0) -, m_msg(NULL) -, ref_cnt(0) + : m_size(0) + , m_capacity(0) + , m_msg(NULL) { m_header.id = sequence++; m_header.type = UNDEFINED_TYPE; @@ -76,7 +72,7 @@ message::message(int error) message::~message() { - if (m_msg && ref_cnt == 0) { + if (m_msg) { free(m_msg); m_msg = NULL; } @@ -125,29 +121,6 @@ size_t message::size(void) return m_size; } -/* TODO: remove ref/unref and use reference counting automatically */ -void message::ref(void) -{ - ref_cnt++; -} - -void message::unref(void) -{ - ref_cnt--; - - if (ref_cnt > 0 || !m_msg) - return; - - free(m_msg); - m_msg = NULL; - delete this; -} - -int message::ref_count(void) -{ - return ref_cnt; -} - message_header *message::header(void) { return &m_header; diff --git a/src/shared/message.h b/src/shared/message.h index 118cf13..0d932b6 100644 --- a/src/shared/message.h +++ b/src/shared/message.h @@ -22,6 +22,7 @@ #include /* size_t */ #include +#include #define MAX_MSG_CAPACITY (16*1024) #define MAX_HEADER_RESERVED 3 @@ -38,6 +39,13 @@ typedef struct message_header { class message { public: + template + static std::shared_ptr create(Args&&... args) + noexcept(noexcept(message(std::forward(args)...))) + { + return std::shared_ptr(new (std::nothrow) message(std::forward(args)...)); + } + message(size_t capacity = MAX_MSG_CAPACITY); message(const void *msg, size_t size); message(const message &msg); @@ -66,7 +74,6 @@ private: size_t m_capacity; char *m_msg; - std::atomic ref_cnt; }; } -- 2.7.4