sensord: [4/4] add the refactored HAL interface 71/58571/2
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Feb 2016 03:00:59 +0000 (12:00 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Feb 2016 03:59:15 +0000 (12:59 +0900)
* modify virtual sensor interface
* support auto_rotation sensor

Change-Id: Ie84dd34c3534bcd27edd41ce80ad692e876e157b
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
packaging/sensord.spec
src/server/plugins/auto_rotation/auto_rotation_sensor.cpp
src/server/plugins/auto_rotation/auto_rotation_sensor.h
src/server/sensor_event_dispatcher.cpp
src/server/virtual_sensor.cpp
src/server/virtual_sensor.h

index ab768f0..1e0b4d9 100644 (file)
@@ -21,7 +21,7 @@ BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
 Requires:   libsensord = %{version}-%{release}
 
-%define auto_rotation_state OFF
+%define auto_rotation_state ON
 %define orientation_state OFF
 %define gravity_state OFF
 %define linear_accel_state OFF
index c50c9fd..087a51e 100644 (file)
@@ -55,9 +55,11 @@ using std::vector;
 
 auto_rotation_sensor::auto_rotation_sensor()
 : m_accel_sensor(NULL)
+, m_alg(NULL)
 , m_rotation(0)
+, m_interval(1)
 , m_rotation_time(1) // rotation state is valid from initial state, so set rotation time to non-zero value
-, m_alg(NULL)
+, m_default_sampling_time(1)
 {
        virtual_sensor_config &config = virtual_sensor_config::get_instance();
 
@@ -92,6 +94,30 @@ auto_rotation_sensor::~auto_rotation_sensor()
        INFO("auto_rotation_sensor is destroyed!\n");
 }
 
+bool auto_rotation_sensor::init(void)
+{
+       m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
+
+       if (!m_accel_sensor) {
+               ERR("cannot load accel sensor_hal from %s", get_name());
+               return false;
+       }
+
+       m_alg = get_alg();
+
+       if (!m_alg) {
+               ERR("Not supported AUTO ROTATION sensor");
+               return false;
+       }
+
+       if (!m_alg->open())
+               return false;
+
+       INFO("%s is created!\n", get_name());
+
+       return true;
+}
+
 sensor_type_t auto_rotation_sensor::get_type(void)
 {
        return AUTO_ROTATION_SENSOR;
@@ -107,43 +133,88 @@ const char* auto_rotation_sensor::get_name(void)
        return SENSOR_NAME;
 }
 
-bool auto_rotation_sensor::check_lib(void)
+bool auto_rotation_sensor::get_sensor_info(sensor_info &info)
 {
-       if (access(AUTO_ROTATION_LIB, F_OK) < 0)
-               return false;
+       info.set_type(get_type());
+       info.set_id(get_id());
+       info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME
+       info.set_name("Auto Rotation Sensor");
+       info.set_vendor("Samsung Electronics");
+       info.set_min_range(AUTO_ROTATION_DEGREE_UNKNOWN);
+       info.set_max_range(AUTO_ROTATION_DEGREE_270);
+       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;
 }
 
-auto_rotation_alg *auto_rotation_sensor::get_alg()
+void auto_rotation_sensor::synthesize(const sensor_event_t& event)
 {
-       return new auto_rotation_alg_emul();
+       if (event.event_type != ACCELEROMETER_RAW_DATA_EVENT)
+               return;
+
+       int rotation;
+       float acc[3];
+       acc[0] = event.data->values[0];
+       acc[1] = event.data->values[1];
+       acc[2] = event.data->values[2];
+
+       if (!m_alg->get_rotation(acc, event.data->timestamp, m_rotation, rotation))
+               return;
+
+       m_rotation = rotation;
+       m_rotation_time = event.data->timestamp;
+
+       sensor_event_t *rotation_event;
+       sensor_data_t *rotation_data;
+       unsigned int data_length;
+
+       rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+       data_length = get_data(&rotation_data);
+
+       rotation_event->sensor_id = get_id();
+       rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT;
+       rotation_event->data_length = data_length;
+       rotation_event->data = rotation_data;
+
+       push(rotation_event, sizeof(sensor_event_t));
+
+       DBG("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f", rotation, event.data.values[0], event.data.values[1], event.data.values[2]);
+       return;
 }
 
-bool auto_rotation_sensor::init(void)
+int auto_rotation_sensor::get_data(sensor_data_t **data)
 {
-       m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
+       sensor_data_t *sensor_data;
+       sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
 
-       if (!m_accel_sensor) {
-               ERR("cannot load accel sensor_hal from %s", get_name());
-               return false;
-       }
+       sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+       sensor_data->timestamp = m_rotation_time;
+       sensor_data->values[0] = m_rotation;
+       sensor_data->value_count = 1;
 
-       m_alg = get_alg();
+       *data = sensor_data;
 
-       if (!m_alg) {
-               ERR("Not supported AUTO ROTATION sensor");
-               return false;
-       }
-
-       if (!m_alg->open())
-               return false;
+       return sizeof(sensor_data_t);
+}
 
-       set_privilege(SENSOR_PRIVILEGE_INTERNAL);
+bool auto_rotation_sensor::set_interval(unsigned long interval)
+{
+       return false;
+}
 
-       INFO("%s is created!\n", get_name());
+bool auto_rotation_sensor::set_batch_latency(unsigned long latency)
+{
+       return false;
+}
 
-       return true;
+bool auto_rotation_sensor::set_wakeup(int wakeup)
+{
+       return false;
 }
 
 bool auto_rotation_sensor::on_start(void)
@@ -166,56 +237,16 @@ bool auto_rotation_sensor::on_stop(void)
        return deactivate();
 }
 
-void auto_rotation_sensor::synthesize(const sensor_event_t& event, vector<sensor_event_t> &outs)
+bool auto_rotation_sensor::check_lib(void)
 {
-       if (event.event_type != ACCELEROMETER_RAW_DATA_EVENT)
-               return;
-
-       int rotation;
-       float acc[3];
-       acc[0] = event.data.values[0];
-       acc[1] = event.data.values[1];
-       acc[2] = event.data.values[2];
-
-       if (!m_alg->get_rotation(acc, event.data.timestamp, m_rotation, rotation))
-               return;
-
-       sensor_event_t rotation_event;
-
-       INFO("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f", rotation, event.data.values[0], event.data.values[1], event.data.values[2]);
-       rotation_event.sensor_id = get_id();
-       rotation_event.data.accuracy = SENSOR_ACCURACY_GOOD;
-       rotation_event.event_type = AUTO_ROTATION_CHANGE_STATE_EVENT;
-       rotation_event.data.timestamp = event.data.timestamp;
-       rotation_event.data.values[0] = rotation;
-       rotation_event.data.value_count = 1;
-       outs.push_back(rotation_event);
-       m_rotation = rotation;
-       m_rotation_time = event.data.timestamp;
+       if (access(AUTO_ROTATION_LIB, F_OK) < 0)
+               return false;
 
-       return;
+       return true;
 }
 
-int auto_rotation_sensor::get_sensor_data(sensor_data_t &data)
+auto_rotation_alg *auto_rotation_sensor::get_alg()
 {
-       data.accuracy = SENSOR_ACCURACY_GOOD;
-       data.timestamp = m_rotation_time;
-       data.values[0] = m_rotation;
-       data.value_count = 1;
-
-       return 0;
+       return new auto_rotation_alg_emul();
 }
 
-bool auto_rotation_sensor::get_properties(sensor_properties_s &properties)
-{
-       properties.name = "Auto Rotation Sensor";
-       properties.vendor = "Samsung Electronics";
-       properties.min_range = AUTO_ROTATION_DEGREE_UNKNOWN;
-       properties.max_range = AUTO_ROTATION_DEGREE_270;
-       properties.min_interval = 1;
-       properties.resolution = 1;
-       properties.fifo_count = 0;
-       properties.max_batch_count = 0;
-
-       return true;
-}
index cc62e57..b2a48b0 100644 (file)
@@ -30,34 +30,41 @@ public:
        virtual ~auto_rotation_sensor();
 
        /* initialize sensor */
-       bool init();
+       bool init(void);
 
        /* sensor info */
-       virtual sensor_type_t get_type();
+       virtual sensor_type_t get_type(void);
        virtual unsigned int get_event_type(void);
        virtual const char* get_name(void);
 
-       void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs);
+       virtual bool get_sensor_info(sensor_info &info);
 
-       int get_sensor_data(sensor_data_t &data);
-       virtual bool get_properties(sensor_properties_s &properties);
+       /* synthesize event */
+       virtual void synthesize(const sensor_event_t& event);
+
+       /* get data */
+       virtual int get_data(sensor_data_t **data);
 private:
        sensor_base *m_accel_sensor;
-       cmutex m_value_mutex;
+       auto_rotation_alg *m_alg;
 
        int m_rotation;
        unsigned int m_interval;
        unsigned long long m_rotation_time;
-       auto_rotation_alg *m_alg;
 
        std::string m_vendor;
        std::string m_raw_data_unit;
        int m_default_sampling_time;
 
-       auto_rotation_alg *get_alg();
+       virtual bool set_interval(unsigned long interval);
+       virtual bool set_batch_latency(unsigned long latency);
+       virtual bool set_wakeup(int wakeup);
+
        virtual bool on_start(void);
        virtual bool on_stop(void);
+
        bool check_lib(void);
+       auto_rotation_alg *get_alg();
 };
 
 #endif
index 24d4f26..50e40f3 100644 (file)
@@ -158,7 +158,7 @@ void sensor_event_dispatcher::dispatch_event(void)
                        while (it_v_sensor != v_sensors.end()) {
                                int synthesized_cnt;
                                v_sensor_events.clear();
-                               (*it_v_sensor)->synthesize(*((sensor_event_t *)seed_event), v_sensor_events);
+                               (*it_v_sensor)->synthesize(*((sensor_event_t *)seed_event));
                                synthesized_cnt = v_sensor_events.size();
 
                                for (int i = 0; i < synthesized_cnt; ++i) {
index ae3f9be..232d7f1 100644 (file)
@@ -42,7 +42,6 @@ bool virtual_sensor::is_virtual(void)
        return true;
 }
 
-
 bool virtual_sensor::activate(void)
 {
        return sensor_event_dispatcher::get_instance().add_active_virtual_sensor(this);
index a9c998f..c3176c3 100644 (file)
@@ -36,14 +36,29 @@ public:
        virtual unsigned int get_event_type(void) = 0;
        virtual const char* get_name(void) = 0;
 
-       virtual void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs) = 0;
-       virtual int get_sensor_data(sensor_data_t &data) = 0;
-       virtual bool is_virtual(void);
+       virtual bool get_sensor_info(sensor_info &info) = 0;
+
+       /* synthesize event */
+       virtual void synthesize(const sensor_event_t& event) = 0;
+
+       /* get data */
+       virtual int get_data(sensor_data_t **data) = 0;
+
+       bool is_virtual(void);
+
 protected:
        bool activate(void);
        bool deactivate(void);
+
 private:
        bool m_hardware_fusion;
+
+       virtual bool set_interval(unsigned long interval) = 0;
+       virtual bool set_batch_latency(unsigned long latency) = 0;
+       virtual bool set_wakeup(int wakeup) = 0;
+
+       virtual bool on_start(void) = 0;
+       virtual bool on_stop(void) = 0;
 };
 
 #endif /* _VIRTUAL_SENSOR_H_ */