From 45f2e2acfb03341a15a410926da6b3b1d6c63a8b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 5 Feb 2016 21:55:39 +0900 Subject: [PATCH] sensord: change the HAL interface * merge sensor_info_t and sensor_handle_t * add set_attribute_str Change-Id: I765e89dfc11f7580007053121896bd7939ccd10c Signed-off-by: kibak.yoon --- src/client/command_channel.cpp | 2 +- src/server/command_worker.cpp | 2 +- src/server/physical_sensor.cpp | 35 +++++++++++++++++++++++--------- src/server/physical_sensor.h | 1 + src/server/sensor_base.cpp | 5 +++++ src/server/sensor_base.h | 1 + src/shared/sensor_hal.h | 45 ++++++++++++++++++++++++------------------ src/shared/sf_common.h | 2 +- 8 files changed, 62 insertions(+), 31 deletions(-) diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index 902ec76..02303a6 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -698,7 +698,7 @@ bool command_channel::cmd_send_sensorhub_data(const char* buffer, int data_len) cmd_send_sensorhub_data = (cmd_send_sensorhub_data_t*)packet->data(); cmd_send_sensorhub_data->data_len = data_len; - cmd_send_sensorhub_data->data = atoi(buffer); + memcpy(cmd_send_sensorhub_data->data, buffer, data_len); INFO("%s send cmd_send_sensorhub_data(client_id=%d, data_len = %d, buffer = 0x%x)", get_client_name(), m_client_id, data_len, buffer); diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index afa3079..2b8c1db 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -833,7 +833,7 @@ bool command_worker::cmd_send_sensorhub_data(void *payload) goto out; } - ret_value = m_module->set_attribute(cmd->data, cmd->data_len); + ret_value = m_module->set_attribute(cmd->data, cmd->data, cmd->data_len); out: if (!send_cmd_done(ret_value)) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 59dc653..e0baec4 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -39,7 +39,14 @@ void physical_sensor::set_sensor_handle(sensor_handle_t handle) m_handle.name = handle.name; m_handle.type = handle.type; m_handle.event_type = handle.event_type; - m_handle.info = handle.info; + m_handle.model_name = handle.model_name; + m_handle.vendor = handle.vendor; + m_handle.min_range = handle.min_range; + m_handle.max_range = handle.max_range; + m_handle.resolution = handle.resolution; + m_handle.min_interval = handle.min_interval; + m_handle.max_batch_count = handle.max_batch_count; + m_handle.wakeup_supported = handle.wakeup_supported; } void physical_sensor::set_sensor_device(sensor_device *device) @@ -154,6 +161,16 @@ int physical_sensor::set_attribute(int32_t attribute, int32_t value) return m_sensor_device->set_attribute(m_handle.id, attribute, value); } +int physical_sensor::set_attribute(char *attribute, char *value, int value_len) +{ + AUTOLOCK(m_mutex); + + if (!m_sensor_device) + return false; + + return m_sensor_device->set_attribute_str(m_handle.id, attribute, value, value_len); +} + bool physical_sensor::set_wakeup(int wakeup) { return false; @@ -184,16 +201,16 @@ bool physical_sensor::get_sensor_info(sensor_info &info) info.set_type(get_type()); info.set_id(get_id()); info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME - info.set_name(m_handle.info.model_name); - info.set_vendor(m_handle.info.vendor); - info.set_min_range(m_handle.info.min_range); - info.set_max_range(m_handle.info.max_range); - info.set_resolution(m_handle.info.resolution); - info.set_min_interval(m_handle.info.min_interval); + info.set_name(m_handle.model_name); + info.set_vendor(m_handle.vendor); + info.set_min_range(m_handle.min_range); + info.set_max_range(m_handle.max_range); + info.set_resolution(m_handle.resolution); + info.set_min_interval(m_handle.min_interval); info.set_fifo_count(0); // FIXME - info.set_max_batch_count(m_handle.info.max_batch_count); + info.set_max_batch_count(m_handle.max_batch_count); info.set_supported_event(get_event_type()); - info.set_wakeup_supported(m_handle.info.wakeup_supported); + info.set_wakeup_supported(m_handle.wakeup_supported); return true; } diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index 1b6537c..1bb649b 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -52,6 +52,7 @@ private: virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); virtual int set_attribute(int32_t attribute, int32_t value); + virtual int set_attribute(char *attribute, char *value, int value_len); virtual bool set_wakeup(int wakeup); virtual bool on_start(void); virtual bool on_stop(void); diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 9296123..e097358 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -93,6 +93,11 @@ int sensor_base::set_attribute(int32_t cmd, int32_t value) return -1; } +int sensor_base::set_attribute(char *attribute, char *value, int value_size) +{ + return -1; +} + bool sensor_base::start() { AUTOLOCK(m_client_mutex); diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index c94ed66..816dc40 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -53,6 +53,7 @@ public: virtual bool flush(void); virtual int set_attribute(int32_t attribute, int32_t value); + virtual int set_attribute(char *attribute, char *value, int value_size); /* start/stop */ bool start(void); diff --git a/src/shared/sensor_hal.h b/src/shared/sensor_hal.h index 8b51bad..55d84db 100644 --- a/src/shared/sensor_hal.h +++ b/src/shared/sensor_hal.h @@ -1,7 +1,5 @@ /* - * libsensord-share - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -100,17 +98,6 @@ typedef enum { SENSOR_DEVICE_ROTATION_VECTOR_RAW, } sensor_device_type; -typedef struct sensor_info_t { - const char *model_name; - const char *vendor; - float min_range; - float max_range; - float resolution; - int min_interval; - int max_batch_count; - bool wakeup_supported; -} sensor_info_t; - /* * A platform sensor handler is generated based on this handle * ID can be assigned from HAL developer. so it has to be unique in HAL. @@ -120,7 +107,14 @@ typedef struct sensor_handle_t { const char *name; sensor_device_type type; unsigned int event_type; // for Internal API - sensor_info_t info; + const char *model_name; + const char *vendor; + float min_range; + float max_range; + float resolution; + int min_interval; + int max_batch_count; + bool wakeup_supported; } sensor_handle_t; enum sensor_accuracy_t { @@ -141,17 +135,29 @@ typedef struct sensor_data_t { float values[SENSOR_DATA_VALUE_SIZE]; } sensor_data_t; -#ifdef __cplusplus -} -#endif /* __cplusplus */ +#define SENSORHUB_DATA_VALUE_SIZE 4096 + +#if 0 +/* sensorhub_data_t */ +typedef struct sensorhub_data_t { + int accuracy; + unsigned long long timestamp; + int value_count; + char values[SENSORHUB_DATA_VALUE_SIZE]; +} sensorhub_data_t; +#endif -#ifdef __cplusplus /* * Create devices */ typedef void *sensor_device_t; typedef int (*create_t)(sensor_device_t **devices); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#ifdef __cplusplus /* * Sensor device interface * 1 device must be abstracted from 1 device event node @@ -174,6 +180,7 @@ public: virtual bool set_interval(uint16_t id, unsigned long val) = 0; virtual bool set_batch_latency(uint16_t id, unsigned long val) = 0; virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0; + virtual bool set_attribute_str(uint16_t id, char *attribute, char *value, int value_len) = 0; virtual int read_fd(uint16_t **ids) = 0; virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0; diff --git a/src/shared/sf_common.h b/src/shared/sf_common.h index 7bcc35f..6d2fda5 100644 --- a/src/shared/sf_common.h +++ b/src/shared/sf_common.h @@ -149,7 +149,7 @@ typedef struct { typedef struct { int data_len; - int data; + char data[0]; } cmd_send_sensorhub_data_t; #define EVENT_CHANNEL_MAGIC 0xCAFECAFE -- 2.7.4