sensor-hal-tm1: modify Sensor HAL interface 77/58977/1
authorkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:35:52 +0000 (21:35 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:35:52 +0000 (21:35 +0900)
+ clean up boilerplate

Change-Id: I1c79151d4ee26d39ac6ea31ab8c37e506f250bd6
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/accel/accel.cpp
src/accel/accel.h
src/macro.h
src/sensor_hal.h
src/sensor_logs.h
src/util.cpp
src/util.h

index 98a9850..5029828 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * accel_device
- *
- * Copyright (c) 2014 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.
  * limitations under the License.
  *
  */
+
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <linux/input.h>
 #include <util.h>
-#include <macro.h>
 #include <sensor_logs.h>
+
 #include "accel.h"
 
 #define GRAVITY 9.80665
 
 #define SENSORHUB_ACCELEROMETER_ENABLE_BIT 0
 
-static const sensor_info_t accel_info = {
-       model_name : MODEL_NAME,
-       vendor : VENDOR,
-       min_range : MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       max_range : MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       resolution : RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
-       min_interval : MIN_INTERVAL,
-       max_batch_count : MAX_BATCH_COUNT,
-       wakeup_supported : false,
-};
-
-static const sensor_handle_t handles[] = {
-       {
-               id: 0x1,
-               name: "Accelerometer",
-               type: SENSOR_DEVICE_ACCELEROMETER,
-               event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001,
-               info : accel_info
-       },
-       {
-               id: 0x2,
-               name: "Accelerometer RAW",
-               type: SENSOR_DEVICE_ACCELEROMETER,
-               event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0002,
-               info : accel_info
-       }
+static const sensor_handle_t handle = {
+       id: 0x1,
+       name: "Accelerometer",
+       type: SENSOR_DEVICE_ACCELEROMETER,
+       event_type: (SENSOR_DEVICE_ACCELEROMETER << 16) | 0x0001,
+       model_name: MODEL_NAME,
+       vendor: VENDOR,
+       min_range: MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       max_range: MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       resolution: RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+       min_interval: MIN_INTERVAL,
+       max_batch_count: MAX_BATCH_COUNT,
+       wakeup_supported: false
 };
 
-static uint16_t event_ids[] = {
-       0x1,
-       0x2,
-};
+std::vector<uint16_t> accel_device::event_ids;
 
 accel_device::accel_device()
 : m_node_handle(-1)
@@ -130,10 +113,9 @@ int accel_device::get_poll_fd()
 
 int accel_device::get_sensors(const sensor_handle_t **sensors)
 {
-       int size = ARRAY_SIZE(handles);
-       *sensors = handles;
+       *sensors = &handle;
 
-       return size;
+       return 1;
 }
 
 bool accel_device::enable(uint16_t id)
@@ -180,6 +162,11 @@ bool accel_device::set_attribute(uint16_t id, int32_t attribute, int32_t value)
        return false;
 }
 
+bool accel_device::set_attribute_str(uint16_t id, char *attribute, char *value, int value_len)
+{
+       return false;
+}
+
 bool accel_device::update_value_input_event(void)
 {
        int accel_raw[3] = {0,};
@@ -252,18 +239,17 @@ bool accel_device::update_value_input_event(void)
 
 int accel_device::read_fd(uint16_t **ids)
 {
-       int size;
-
        if (!update_value_input_event()) {
                DBG("Failed to update value");
                return false;
        }
 
-       size = ARRAY_SIZE(event_ids);
+       event_ids.clear();
+       event_ids.push_back(handle.id);
 
-       *ids = event_ids;
+       *ids = &event_ids[0];
 
-       return size;
+       return event_ids.size();
 }
 
 int accel_device::get_data(uint16_t id, sensor_data_t **data, int *length)
index 0abc345..2135684 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * accel_device
- *
- * Copyright (c) 2014 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.
@@ -22,6 +20,7 @@
 
 #include <sensor_hal.h>
 #include <string>
+#include <vector>
 
 class accel_device : public sensor_device {
 public:
@@ -37,6 +36,7 @@ public:
        bool set_interval(uint16_t id, unsigned long val);
        bool set_batch_latency(uint16_t id, unsigned long val);
        bool set_attribute(uint16_t id, int32_t attribute, int32_t value);
+       bool set_attribute_str(uint16_t id, char *attribute, char *value, int value_len);
 
        int read_fd(uint16_t **ids);
        int get_data(uint16_t id, sensor_data_t **data, int *length);
@@ -56,6 +56,8 @@ private:
        std::string m_enable_node;
        std::string m_interval_node;
 
+       static std::vector<uint16_t> event_ids;
+
        bool update_value_input_event(void);
        void raw_to_base(sensor_data_t *data);
 };
index 5e2ca3e..64446af 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * libsensord-share
- *
- * Copyright (c) 2014 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.
index 8b51bad..5530c7c 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 {
@@ -174,6 +168,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 9682c42..3385aad 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * libsensord-share
- *
- * Copyright (c) 2014 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.
index a8d9d11..9c0dbd3 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * libsensord-share
- *
- * Copyright (c) 2014 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.
@@ -308,4 +306,3 @@ bool util::set_node_value(const string &node_path, unsigned long long value)
 
        return true;
 }
-
index 81488e0..70c600a 100644 (file)
@@ -1,7 +1,5 @@
 /*
- * libsensord-share
- *
- * Copyright (c) 2014 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.