sensord: change the HAL interface 85/58985/1
authorkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:55:39 +0000 (21:55 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:55:39 +0000 (21:55 +0900)
* merge sensor_info_t and sensor_handle_t
* add set_attribute_str

Change-Id: I765e89dfc11f7580007053121896bd7939ccd10c
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/command_channel.cpp
src/server/command_worker.cpp
src/server/physical_sensor.cpp
src/server/physical_sensor.h
src/server/sensor_base.cpp
src/server/sensor_base.h
src/shared/sensor_hal.h
src/shared/sf_common.h

index 902ec76..02303a6 100644 (file)
@@ -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);
index afa3079..2b8c1db 100644 (file)
@@ -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))
index 59dc653..e0baec4 100644 (file)
@@ -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;
 }
index 1b6537c..1bb649b 100644 (file)
@@ -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);
index 9296123..e097358 100644 (file)
@@ -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);
index c94ed66..816dc40 100644 (file)
@@ -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);
index 8b51bad..55d84db 100644 (file)
@@ -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;
index 7bcc35f..6d2fda5 100644 (file)
@@ -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