sensord: modify HAL interface for batching 39/58639/2
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Feb 2016 10:45:42 +0000 (19:45 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Feb 2016 10:56:14 +0000 (19:56 +0900)
* int get_data(id, data, length)
  - return value: the remaining count of data

Change-Id: I153bc0a218667fd303a033b7550625b9e529723d
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/server/command_worker.cpp
src/server/physical_sensor.cpp
src/server/physical_sensor.h
src/server/plugins/auto_rotation/auto_rotation_sensor.cpp
src/server/plugins/auto_rotation/auto_rotation_sensor.h
src/server/sensor_base.cpp
src/server/sensor_base.h
src/server/sensor_event_poller.cpp
src/server/virtual_sensor.h
src/shared/sensor_hal.h

index e4d8191..afa3079 100644 (file)
@@ -758,6 +758,7 @@ bool command_worker::cmd_get_data(void *payload)
        const unsigned int GET_DATA_MIN_INTERVAL = 10;
        int state = OP_ERROR;
        bool adjusted = false;
+       int length;
 
        sensor_data_t *data;
 
@@ -770,7 +771,7 @@ bool command_worker::cmd_get_data(void *payload)
                goto out;
        }
 
-       state = m_module->get_data(&data);
+       state = m_module->get_data(&data, &length);
 
        // In case of not getting sensor data, wait short time and retry again
        // 1. changing interval to be less than 10ms
@@ -779,7 +780,7 @@ bool command_worker::cmd_get_data(void *payload)
        // 4. retrying to get data
        // 5. repeat 2 ~ 4 operations RETRY_CNT times
        // 6. reverting back to original interval
-       if ((state > 0) && !data->timestamp) {
+       if ((state >= 0) && !data->timestamp) {
                const int RETRY_CNT     = 5;
                const unsigned long long INIT_WAIT_TIME = 20000; //20ms
                const unsigned long WAIT_TIME = 100000; //100ms
@@ -792,10 +793,10 @@ bool command_worker::cmd_get_data(void *payload)
                        adjusted = true;
                }
 
-               while ((state > 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
+               while ((state >= 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
                        INFO("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry);
                        usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME);
-                       state = m_module->get_data(&data);
+                       state = m_module->get_data(&data, &length);
                }
 
                if (adjusted)
index fc0b3db..59dc653 100644 (file)
@@ -92,22 +92,22 @@ bool physical_sensor::read_fd(std::vector<uint16_t> &ids)
        return true;
 }
 
-int physical_sensor::get_data(sensor_data_t **data)
+int physical_sensor::get_data(sensor_data_t **data, int *length)
 {
        AUTOLOCK(m_mutex);
 
        if (!m_sensor_device)
-               return false;
+               return -1;
 
-       int length = -1;
-       length = m_sensor_device->get_data(m_handle.id, data);
+       int remains = 0;
+       remains = m_sensor_device->get_data(m_handle.id, data, length);
 
-       if (length < 0) {
+       if (*length < 0) {
                ERR("Failed to get sensor event");
                return -1;
        }
 
-       return length;
+       return remains;
 }
 
 bool physical_sensor::flush(void)
index b7aecd0..9df3a14 100644 (file)
@@ -42,7 +42,7 @@ public:
        int get_poll_fd();
 
        virtual bool read_fd(std::vector<uint16_t> &ids);
-       virtual int get_data(sensor_data_t **data);
+       virtual int get_data(sensor_data_t **data, int *length);
        virtual bool flush(void);
 private:
        static cmutex m_mutex;
index 1f0b19c..5b400b1 100644 (file)
@@ -171,10 +171,14 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event)
 
        sensor_event_t *rotation_event;
        sensor_data_t *rotation_data;
-       unsigned int data_length;
+       int data_length;
+       int remains;
 
        rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-       data_length = get_data(&rotation_data);
+       remains = get_data(&rotation_data, &data_length);
+
+       if (remains < 0)
+               return;
 
        rotation_event->sensor_id = get_id();
        rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT;
@@ -187,8 +191,11 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event)
        return;
 }
 
-int auto_rotation_sensor::get_data(sensor_data_t **data)
+int auto_rotation_sensor::get_data(sensor_data_t **data, int *length)
 {
+       /* if It is batch sensor, remains can be 2+ */
+       int remains = 1;
+
        sensor_data_t *sensor_data;
        sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
 
@@ -198,8 +205,9 @@ int auto_rotation_sensor::get_data(sensor_data_t **data)
        sensor_data->value_count = 1;
 
        *data = sensor_data;
+       *length = sizeof(sensor_data_t);
 
-       return sizeof(sensor_data_t);
+       return --remains;
 }
 
 bool auto_rotation_sensor::set_interval(unsigned long interval)
index b2a48b0..9b40c7c 100644 (file)
@@ -43,7 +43,7 @@ public:
        virtual void synthesize(const sensor_event_t& event);
 
        /* get data */
-       virtual int get_data(sensor_data_t **data);
+       virtual int get_data(sensor_data_t **data, int *length);
 private:
        sensor_base *m_accel_sensor;
        auto_rotation_alg *m_alg;
index c8711e4..9296123 100644 (file)
@@ -78,7 +78,7 @@ bool sensor_base::is_virtual()
        return false;
 }
 
-int sensor_base::get_data(sensor_data_t **data)
+int sensor_base::get_data(sensor_data_t **data, int *length)
 {
        return -1;
 }
index 90f644b..a955f34 100644 (file)
@@ -50,7 +50,7 @@ public:
        virtual bool is_virtual(void);
 
        /* set/get data */
-       virtual int get_data(sensor_data_t **data);
+       virtual int get_data(sensor_data_t **data, int *length);
 
        virtual bool flush(void);
        virtual int set_attribute(int32_t attribute, int32_t value);
index 4d2b9e1..3dd2efd 100644 (file)
@@ -126,6 +126,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector<uint16_t> &ids
                sensor_event_t *event;
                sensor_data_t *data;
                int data_length;
+               int remains = 1;
 
                sensor = it_sensor->second;
 
@@ -134,15 +135,18 @@ bool sensor_event_poller::process_event(int fd, const std::vector<uint16_t> &ids
                if (result == std::end(ids))
                        continue;
 
-               event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+               while (remains > 0) {
+                       event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
 
-               data_length = sensor->get_data(&data);
-               event->sensor_id = sensor->get_id();
-               event->event_type = sensor->get_event_type();
-               event->data_length = data_length;
-               event->data = data;
+                       remains = sensor->get_data(&data, &data_length);
 
-               sensor->push(event);
+                       event->sensor_id = sensor->get_id();
+                       event->event_type = sensor->get_event_type();
+                       event->data_length = data_length;
+                       event->data = data;
+
+                       sensor->push(event);
+               }
        }
 
        return true;
index c3176c3..993866f 100644 (file)
@@ -42,7 +42,7 @@ public:
        virtual void synthesize(const sensor_event_t& event) = 0;
 
        /* get data */
-       virtual int get_data(sensor_data_t **data) = 0;
+       virtual int get_data(sensor_data_t **data, int *length) = 0;
 
        bool is_virtual(void);
 
index 19681ed..04e3249 100644 (file)
@@ -176,7 +176,7 @@ public:
        virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0;
 
        virtual int read_fd(uint16_t **ids) = 0;
-       virtual int get_data(uint16_t id, sensor_data_t **data) = 0;
+       virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0;
 
        virtual bool flush(uint16_t id) = 0;
 };