using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define GRAVITY 9.80665
#define G_TO_MG 1000
bool accel_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(ACCELEROMETER_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ACCELEROMETER);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t accel_sensor::get_type(void)
+void accel_sensor::get_types(vector<sensor_type_t> &types)
{
- return ACCELEROMETER_SENSOR;
+ types.push_back(ACCELEROMETER_SENSOR);
}
bool accel_sensor::working(void *inst)
return stop_poll();
}
-bool accel_sensor::get_properties(sensor_properties_s &properties)
+bool accel_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~accel_sensor();
bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+
private:
sensor_hal *m_sensor_hal;
cmutex m_value_mutex;
virtual bool on_start(void);
virtual bool on_stop(void);
-
void raw_to_base(sensor_data_t &data);
bool process_event(void);
};
#include <sys/poll.h>
using std::ifstream;
+using std::string;
#define GRAVITY 9.80665
#define G_TO_MG 1000
return m_model_id;
}
-sensor_type_t accel_sensor_hal::get_type(void)
+sensor_hal_type_t accel_sensor_hal::get_type(void)
{
- return ACCELEROMETER_SENSOR;
+ return SENSOR_HAL_TYPE_ACCELEROMETER;
}
bool accel_sensor_hal::enable(void)
#define _ACCEL_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
#include <functional>
-using std::string;
-
class accel_sensor_hal : public sensor_hal
{
public:
accel_sensor_hal();
virtual ~accel_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
unsigned long m_polling_interval;
unsigned long long m_fired_time;
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
int m_resolution;
float m_raw_data_unit;
int m_method;
- string m_data_node;
- string m_enable_node;
- string m_interval_node;
+ std::string m_data_node;
+ std::string m_enable_node;
+ std::string m_interval_node;
std::function<bool (bool)> update_value;
using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define SENSOR_NAME "AUTO_ROTATION_SENSOR"
#define SENSOR_TYPE_AUTO_ROTATION "AUTO_ROTATION"
return true;
}
-sensor_type_t auto_rotation_sensor::get_type(void)
+void auto_rotation_sensor::get_types(vector<sensor_type_t> &types)
{
- return AUTO_ROTATION_SENSOR;
+ types.push_back(AUTO_ROTATION_SENSOR);
}
bool auto_rotation_sensor::on_start(void)
return 0;
}
-bool auto_rotation_sensor::get_properties(sensor_properties_s &properties)
+bool auto_rotation_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.name = "Auto Rotation Sensor";
properties.vendor = "Samsung Electronics";
#define _AUTO_ROTATION_SENSOR_H_
#include <sensor_internal.h>
-#include <string>
#include <auto_rotation_alg.h>
class auto_rotation_sensor : public virtual_sensor {
virtual ~auto_rotation_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
- void synthesize(const sensor_event_t& event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
- virtual bool get_properties(sensor_properties_s &properties);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_base *m_accel_sensor;
cmutex m_value_mutex;
unsigned long long m_rotation_time;
auto_rotation_alg *m_alg;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
auto_rotation_alg *get_alg();
using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define SENSOR_NAME "BIO_LED_RED_SENSOR"
bool bio_led_red_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(BIO_LED_RED_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_BIO_LED_RED);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t bio_led_red_sensor::get_type(void)
+void bio_led_red_sensor::get_types(vector<sensor_type_t> &types)
{
- return BIO_LED_RED_SENSOR;
+ types.push_back(BIO_LED_RED_SENSOR);
}
bool bio_led_red_sensor::working(void *inst)
return stop_poll();
}
-bool bio_led_red_sensor::get_properties(sensor_properties_s &properties)
+bool bio_led_red_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~bio_led_red_sensor();
bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
private:
sensor_hal *m_sensor_hal;
#include <fstream>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_BIO_LED_RED "BIO_LED_RED"
#define ELEMENT_NAME "NAME"
}
-sensor_type_t bio_led_red_sensor_hal::get_type(void)
+sensor_hal_type_t bio_led_red_sensor_hal::get_type(void)
{
- return BIO_LED_RED_SENSOR;
+ return SENSOR_HAL_TYPE_BIO_LED_RED;
}
bool bio_led_red_sensor_hal::enable(void)
#define _BIO_LED_RED_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class bio_led_red_sensor_hal : public sensor_hal
{
public:
bio_led_red_sensor_hal();
virtual ~bio_led_red_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
int m_node_handle;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <cvirtual_sensor_config.h>
#include <algorithm>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "FUSION_SENSOR"
#define SENSOR_TYPE_FUSION "FUSION"
return true;
}
-sensor_type_t fusion_sensor::get_type(void)
+void fusion_sensor::get_types(vector<sensor_type_t> &types)
{
- return FUSION_SENSOR;
+ types.push_back(FUSION_SENSOR);
}
bool fusion_sensor::on_start(void)
return 0;
}
-bool fusion_sensor::get_properties(sensor_properties_s &properties)
+bool fusion_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.min_range = 0;
properties.max_range = 0;
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int data_id, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
float m_accel_static_bias[3];
float m_gyro_static_bias[3];
<P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">->In
the constructor use sensor_plugin_loader to check if the hal sensor
fusion is present or not:</FONT></P>
-<P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR)</FONT></P>
+<P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION)</FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Liberation Serif, serif">->If
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">sensor_hal
*fusion_sensor_hal =
-sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);</FONT></P>
+sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">if
(!fusion_sensor_hal)</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Courier 10 Pitch">  m_hardware_fusion
#include <geo_sensor.h>
#include <sensor_plugin_loader.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "GEOMAGNETIC_SENSOR"
geo_sensor::geo_sensor()
bool geo_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(GEOMAGNETIC_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GEOMAGNETIC);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t geo_sensor::get_type(void)
+void geo_sensor::get_types(vector<sensor_type_t> &types)
{
- return GEOMAGNETIC_SENSOR;
+ types.push_back(GEOMAGNETIC_SENSOR);
}
bool geo_sensor::working(void *inst)
{
geo_sensor *sensor = (geo_sensor*)inst;
- return sensor->process_event();;
+ return sensor->process_event();
}
bool geo_sensor::process_event(void)
return stop_poll();
}
-bool geo_sensor::get_properties(sensor_properties_s &properties)
+bool geo_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~geo_sensor();
virtual bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
#include <fstream>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_MAGNETIC "MAGNETIC"
#define ELEMENT_NAME "NAME"
return m_model_id;
}
-sensor_type_t geo_sensor_hal::get_type(void)
+sensor_hal_type_t geo_sensor_hal::get_type(void)
{
- return GEOMAGNETIC_SENSOR;
+ return SENSOR_HAL_TYPE_GEOMAGNETIC;
}
bool geo_sensor_hal::enable(void)
INFO("Interval is changed from %dms to %dms]", m_polling_interval, val);
m_polling_interval = val;
return true;
-
}
bool geo_sensor_hal::update_value(bool wait)
#define _GEO_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class geo_sensor_hal : public sensor_hal
{
public:
geo_sensor_hal();
virtual ~geo_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
virtual int get_sensor_data(sensor_data_t &data);
bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
float m_min_range;
float m_max_range;
int m_node_handle;
unsigned long m_polling_interval;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <sensor_plugin_loader.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define INITIAL_VALUE -1
#define GRAVITY 9.80665
{
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t gravity_sensor::get_type(void)
+void gravity_sensor::get_types(vector<sensor_type_t> &types)
{
- return GRAVITY_SENSOR;
+ types.push_back(GRAVITY_SENSOR);
}
bool gravity_sensor::on_start(void)
return 0;
}
-bool gravity_sensor::get_properties(sensor_properties_s &properties)
+bool gravity_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.min_range = -GRAVITY;
properties.max_range = GRAVITY;
virtual ~gravity_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
- bool get_properties(sensor_properties_s &properties);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_base *m_accel_sensor;
sensor_base *m_gyro_sensor;
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
- string m_orientation_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
+ std::string m_orientation_data_unit;
int m_default_sampling_time;
int m_gravity_sign_compensation[3];
int m_azimuth_rotation_compensation;
#include <gyro_sensor.h>
#include <sensor_plugin_loader.h>
+using std::string;
+using std::vector;
+
#define MS_TO_US 1000
#define DPS_TO_MDPS 1000
#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
bool gyro_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(GYROSCOPE_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GYROSCOPE);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t gyro_sensor::get_type(void)
+void gyro_sensor::get_types(vector<sensor_type_t> &types)
{
- return GYROSCOPE_SENSOR;
+ types.push_back(GYROSCOPE_SENSOR);
}
bool gyro_sensor::working(void *inst)
return stop_poll();
}
-bool gyro_sensor::get_properties(sensor_properties_s &properties)
+bool gyro_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~gyro_sensor();
virtual bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
float m_resolution;
#include <fstream>
using std::ifstream;
+using std::string;
#define DPS_TO_MDPS 1000
#define MIN_RANGE(RES) (-((1 << (RES))/2))
return m_model_id;
}
-sensor_type_t gyro_sensor_hal::get_type(void)
+sensor_hal_type_t gyro_sensor_hal::get_type(void)
{
- return GYROSCOPE_SENSOR;
+ return SENSOR_HAL_TYPE_GYROSCOPE;
}
bool gyro_sensor_hal::enable(void)
#define _GYRO_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class gyro_sensor_hal : public sensor_hal
{
public:
gyro_sensor_hal();
virtual ~gyro_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long ms_interval);
unsigned long m_polling_interval;
unsigned long long m_fired_time;
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
float m_min_range;
float m_max_range;
int m_resolution;
float m_raw_data_unit;
- string m_data_node;
- string m_enable_node;
- string m_interval_node;
+ std::string m_data_node;
+ std::string m_enable_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <common.h>
#include <sensor_info.h>
#include <sensor_info_manager.h>
+#include <vector>
+#include <algorithm>
+
+using std::vector;
#ifndef API
#define API __attribute__((visibility("default")))
#endif
+#define MIN_INTERVAL 10
+
static const int OP_SUCCESS = 0;
static const int OP_ERROR = -1;
}
}
- if (prev_rep.interval != cur_rep.interval) {
- unsigned int min_interval;
-
- if (cur_rep.interval == 0)
- min_interval= POLL_MAX_HZ_MS;
- else
- min_interval = cur_rep.interval;
-
- if (!cmd_channel->cmd_set_interval(min_interval)) {
- ERR("Sending cmd_set_interval(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), min_interval, get_client_name());
+ if ( (prev_rep.interval != cur_rep.interval) || (prev_rep.latency != cur_rep.latency)) {
+ if (!cmd_channel->cmd_set_batch(cur_rep.interval, cur_rep.latency)) {
+ ERR("Sending cmd_set_batch(%d, %s, %d, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.interval, cur_rep.latency, get_client_name());
return false;
}
}
return false;
}
} else {
- if (!cmd_channel->cmd_unset_interval()) {
+ if (!cmd_channel->cmd_unset_batch()) {
ERR("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
return false;
}
retvm_if (!sensor_info_manager::get_instance().is_valid(info),
OP_ERROR, "Invalid param: sensor (%p)", sensor);
- sensor_id_t sensor_id = info->get_id();
+ sensor_id_t sensor_id = info->get_id();
AUTOLOCK(lock);
sensor_registered = event_listener.is_sensor_registered(sensor_id);
handle = event_listener.create_handle(sensor_id);
- if (handle == MAX_HANDLE) {
+ if (handle == MAX_HANDLE_REACHED) {
ERR("Maximum number of handles reached, sensor: %s in client %s", get_sensor_name(sensor_id), get_client_name());
return OP_ERROR;
}
return false;
}
- if (interval == 0)
- interval = 1;
+ if (interval < MIN_INTERVAL)
+ interval = MIN_INTERVAL;
- INFO("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, cb: 0x%x, user_data: 0x%x", get_client_name(), get_event_name(event_type),
- event_type, get_sensor_name(sensor_id), handle, interval, cb, user_data);
+ INFO("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, latency: %d, cb: 0x%x, user_data: 0x%x",
+ get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id),
+ handle, interval, max_batch_latency, cb, user_data);
event_listener.get_sensor_rep(sensor_id, prev_rep);
- event_listener.register_event(handle, event_type, interval, cb_type, cb, user_data);
+ event_listener.register_event(handle, event_type, interval, max_batch_latency, cb_type, cb, user_data);
event_listener.get_sensor_rep(sensor_id, cur_rep);
ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
sensor_id_t sensor_id;
sensor_rep prev_rep, cur_rep;
bool ret;
- unsigned int prev_interval;
+ unsigned int prev_interval, prev_latency;
int prev_cb_type;
void *prev_cb;
void *prev_user_data;
event_type, get_sensor_name(sensor_id), handle);
event_listener.get_sensor_rep(sensor_id, prev_rep);
- event_listener.get_event_info(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data);
+ event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data);
if (!event_listener.unregister_event(handle, event_type)) {
ERR("%s try to unregister non registered event %s[0x%x] for sensor %s[%d]",
ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
if (!ret)
- event_listener.register_event(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data);
+ event_listener.register_event(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data);
return ret;
}
-API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
+static bool change_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
{
sensor_id_t sensor_id;
sensor_rep prev_rep, cur_rep;
bool ret;
- unsigned int prev_interval;
+ unsigned int prev_interval, prev_latency;
int prev_cb_type;
void *prev_cb;
void *prev_user_data;
return false;
}
- INFO("%s changes interval of event %s[0x%x] for %s[%d] to interval %d", get_client_name(), get_event_name(event_type),
- event_type, get_sensor_name(sensor_id), handle, interval);
+ if (interval == 0)
+ interval = 1;
+
+ INFO("%s changes batch of event %s[0x%x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type),
+ event_type, get_sensor_name(sensor_id), handle, interval, latency);
event_listener.get_sensor_rep(sensor_id, prev_rep);
- event_listener.get_event_info(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data);
+ event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data);
+
+ if (interval < MIN_INTERVAL)
+ interval = MIN_INTERVAL;
- if (!event_listener.set_event_interval(handle, event_type, interval))
+ if (!event_listener.set_event_batch(handle, event_type, interval, latency))
return false;
event_listener.get_sensor_rep(sensor_id, cur_rep);
ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
if (!ret)
- event_listener.set_event_interval(handle, event_type, prev_interval);
+ event_listener.set_event_batch(handle, event_type, prev_interval, prev_latency);
return ret;
-
}
-API bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency)
+API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
{
- return false;
+ unsigned int prev_interval, prev_latency;
+ int prev_cb_type;
+ void *prev_cb;
+ void *prev_user_data;
+
+ AUTOLOCK(lock);
+
+ if (!event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) {
+ ERR("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type);
+ return false;
+ }
+
+ INFO("handle = %d, event_type = 0x%x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency);
+ return change_event_batch(handle, event_type, interval, prev_latency);
}
+API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
+{
+ unsigned int prev_interval, prev_latency;
+ int prev_cb_type;
+ void *prev_cb;
+ void *prev_user_data;
+
+ AUTOLOCK(lock);
+
+ if (!event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) {
+ ERR("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type);
+ return false;
+ }
+
+ return change_event_batch(handle, event_type, prev_interval, max_batch_latency);
+}
API bool sensord_set_option(int handle, int option)
{
const char* get_sensor_name(sensor_id_t sensor_id)
{
- const int SENSOR_TYPE_MASK = 0x0000FFFF;
-
sensor_type_t sensor_type = (sensor_type_t) (sensor_id & SENSOR_TYPE_MASK);
return get_log_element_name(LOG_ID_SENSOR_TYPE, sensor_type);
packet->set_cmd(CMD_GET_ID);
cmd_get_id = (cmd_get_id_t *)packet->data();
- cmd_get_id->pid = getpid();
+
+ get_proc_name(getpid(), cmd_get_id->name);
INFO("%s send cmd_get_id()", get_client_name());
return true;
}
-bool command_channel::cmd_set_interval(unsigned int interval)
+bool command_channel::cmd_set_batch(unsigned int interval, unsigned int latency)
{
cpacket *packet;
- cmd_set_interval_t *cmd_set_interval;
+ cmd_set_batch_t *cmd_set_batch;
cmd_done_t *cmd_done;
- packet = new(std::nothrow) cpacket(sizeof(cmd_set_interval_t));
+ packet = new(std::nothrow) cpacket(sizeof(cmd_set_batch_t));
retvm_if(!packet, false, "Failed to allocate memory");
- packet->set_cmd(CMD_SET_INTERVAL);
+ packet->set_cmd(CMD_SET_BATCH);
- cmd_set_interval = (cmd_set_interval_t*)packet->data();
- cmd_set_interval->interval = interval;
+ cmd_set_batch = (cmd_set_batch_t*)packet->data();
+ cmd_set_batch->interval = interval;
+ cmd_set_batch->latency = latency;
- INFO("%s send cmd_set_interval(client_id=%d, %s, interval=%d)",
- get_client_name(), m_client_id, get_sensor_name(m_sensor_id), interval);
+ INFO("%s send cmd_set_batch(client_id=%d, %s, interval=%d, latency = %d)",
+ get_client_name(), m_client_id, get_sensor_name(m_sensor_id), interval, latency);
if (!command_handler(packet, (void **)&cmd_done)) {
- ERR("%s failed to send/receive command for sensor[%s] with client_id [%d], interval[%d]",
- get_client_name(), get_sensor_name(m_sensor_id), m_client_id, interval);
+ ERR("%s failed to send/receive command for sensor[%s] with client_id [%d], interval[%d], latency[%d]",
+ get_client_name(), get_sensor_name(m_sensor_id), m_client_id, interval, latency);
delete packet;
return false;
}
if (cmd_done->value < 0) {
- ERR("%s got error[%d] from server for sensor[%s] with client_id [%d], interval[%d]",
- get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, interval);
+ ERR("%s got error[%d] from server for sensor[%s] with client_id [%d], interval[%d], latency[%d]",
+ get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, interval, latency);
delete[] (char *)cmd_done;
delete packet;
return true;
}
-bool command_channel::cmd_unset_interval(void)
+bool command_channel::cmd_unset_batch(void)
{
cpacket *packet;
cmd_done_t *cmd_done;
- packet = new(std::nothrow) cpacket(sizeof(cmd_unset_interval_t));
+ packet = new(std::nothrow) cpacket(sizeof(cmd_unset_batch_t));
retvm_if(!packet, false, "Failed to allocate memory");
- packet->set_cmd(CMD_UNSET_INTERVAL);
+ packet->set_cmd(CMD_UNSET_BATCH);
- INFO("%s send cmd_unset_interval(client_id=%d, %s)",
+ INFO("%s send cmd_unset_batch(client_id=%d, %s)",
get_client_name(), m_client_id, get_sensor_name(m_sensor_id));
if (!command_handler(packet, (void **)&cmd_done)) {
#include <sensor_internal.h>
#include <cpacket.h>
#include <csocket.h>
-#include <vector>
-
-using std::vector;
class command_channel
{
bool cmd_register_events(event_type_vector &event_vec);
bool cmd_unregister_event(unsigned int event_type);
bool cmd_unregister_events(event_type_vector &event_vec);
- bool cmd_set_interval(unsigned int interval);
- bool cmd_unset_interval(void);
+ bool cmd_set_batch(unsigned int interval, unsigned int latency);
+ bool cmd_unset_batch(void);
bool cmd_set_command(unsigned int cmd, long value);
bool cmd_get_data(unsigned int type, sensor_data_t* values);
bool cmd_send_sensorhub_data(const char* buffer, int data_len);
int m_handle;
unsigned int type;
unsigned int m_interval;
+ unsigned int m_latency;
int m_cb_type;
void *m_cb;
void *m_user_data;
creg_event_info():m_id(0), m_handle(-1),
type(0), m_interval(POLL_1HZ_MS),
+ m_latency(0),
m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL),
m_previous_event_time(0), m_fired(false){}
#include <thread>
#include <chrono>
+#include <vector>
#define MS_TO_US 1000
#define MIN_DELIVERY_DIFF_FACTOR 0.75f
using std::thread;
using std::pair;
+using std::vector;
csensor_event_listener::csensor_event_listener()
: m_client_id(CLIENT_ID_INVALID)
}
bool csensor_event_listener::register_event(int handle, unsigned int event_type,
- unsigned int interval, int cb_type, void *cb, void* user_data)
+ unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data)
{
AUTOLOCK(m_handle_info_lock);
return false;
}
- if (!it_handle->second.add_reg_event_info(event_type, interval, cb_type, cb, user_data))
+ if (!it_handle->second.add_reg_event_info(event_type, interval, latency, cb_type, cb, user_data))
return false;
return true;
return true;
}
-bool csensor_event_listener::change_event_interval(int handle, unsigned int event_type,
- unsigned int interval)
-{
- AUTOLOCK(m_handle_info_lock);
-
- auto it_handle = m_sensor_handle_infos.find(handle);
-
- if (it_handle == m_sensor_handle_infos.end()) {
- ERR("Handle[%d] is not found for client %s", handle, get_client_name());
- return false;
- }
-
- if (!it_handle->second.change_reg_event_interval(event_type, interval))
- return false;
-
- return true;
-}
-
bool csensor_event_listener::register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data)
{
AUTOLOCK(m_handle_info_lock);
return true;
}
-bool csensor_event_listener::set_event_interval(int handle, unsigned int event_type, unsigned int interval)
+bool csensor_event_listener::set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
{
AUTOLOCK(m_handle_info_lock);
return false;
}
- if (!it_handle->second.change_reg_event_interval(event_type, interval))
+ if (!it_handle->second.change_reg_event_batch(event_type, interval, latency))
return false;
return true;
}
-bool csensor_event_listener::get_event_info(int handle, unsigned int event_type, unsigned int &interval, int &cb_type, void* &cb, void* &user_data)
+bool csensor_event_listener::get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data)
{
AUTOLOCK(m_handle_info_lock);
if (!event_info)
return NULL;
-
interval = event_info->m_interval;
+ latency = event_info->m_latency;
cb_type = event_info->m_cb_type;
cb = event_info->m_cb;
user_data = event_info->m_user_data;
void csensor_event_listener::get_sensor_rep(sensor_id_t sensor, sensor_rep& rep)
{
+ const unsigned int INVALID_BATCH_VALUE = std::numeric_limits<unsigned int>::max();
+
AUTOLOCK(m_handle_info_lock);
rep.active = is_sensor_active(sensor);
rep.option = get_active_option(sensor);
- rep.interval = get_active_min_interval(sensor);
- get_active_event_types(sensor, rep.event_types);
+ if (!get_active_batch(sensor, rep.interval, rep.latency)) {
+ rep.interval = INVALID_BATCH_VALUE;
+ rep.latency = INVALID_BATCH_VALUE;
+ }
+ get_active_event_types(sensor, rep.event_types);
}
void csensor_event_listener::operate_sensor(sensor_id_t sensor, int power_save_state)
m_client_id = client_id;
}
-unsigned int csensor_event_listener::get_active_min_interval(sensor_id_t sensor)
+bool csensor_event_listener::get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency)
{
unsigned int min_interval = POLL_MAX_HZ_MS;
+ unsigned int min_latency = std::numeric_limits<unsigned int>::max();
+
bool active_sensor_found = false;
- unsigned int interval;
+ unsigned int _interval;
+ unsigned int _latency;
AUTOLOCK(m_handle_info_lock);
if ((it_handle->second.m_sensor_id == sensor) &&
(it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) {
active_sensor_found = true;
- interval = it_handle->second.get_min_interval();
- min_interval = (interval < min_interval) ? interval : min_interval;
+ it_handle->second.get_batch(_interval, _latency);
+ min_interval = (_interval < min_interval) ? _interval : min_interval;
+ min_latency = (_latency < min_latency) ? _latency : min_latency;
}
++it_handle;
}
- if (!active_sensor_found)
+ if (!active_sensor_found) {
DBG("Active sensor[0x%x] is not found for client %s", sensor, get_client_name());
+ return false;
+ }
- return (active_sensor_found) ? min_interval : 0;
+ interval = min_interval;
+ latency = min_latency;
+ return true;
}
unsigned int csensor_event_listener::get_active_option(sensor_id_t sensor)
#include <cmutex.h>
#include <poller.h>
-using std::unordered_map;
-using std::vector;
-using std::string;
-using std::queue;
-using std::mutex;
-using std::lock_guard;
-using std::unique_lock;
-using std::condition_variable;
-
-typedef vector<unsigned int> handle_vector;
-typedef vector<sensor_id_t> sensor_id_vector;
-typedef unordered_map<int,csensor_handle_info> sensor_handle_info_map;
-typedef unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
+typedef std::vector<unsigned int> handle_vector;
+typedef std::vector<sensor_id_t> sensor_id_vector;
+typedef std::unordered_map<int,csensor_handle_info> sensor_handle_info_map;
+typedef std::unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
typedef struct {
unsigned long long event_id;
bool active;
int option;
unsigned int interval;
+ unsigned int latency;
event_type_vector event_types;
} sensor_rep;
bool delete_handle(int handle);
bool start_handle(int handle);
bool stop_handle(int handle);
- bool register_event(int handle, unsigned int event_type, unsigned int interval, int cb_type, void *cb, void* user_data);
+ bool register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data);
bool unregister_event(int handle, unsigned int event_type);
- bool change_event_interval(int handle, unsigned int event_type, unsigned int interval);
bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
bool unregister_accuracy_cb(int handle);
bool get_sensor_params(int handle, int &sensor_state, int &sensor_option);
bool set_sensor_state(int handle, int sensor_state);
bool set_sensor_option(int handle, int sensor_option);
- bool set_event_interval(int handle, unsigned int event_type, unsigned int interval);
- bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, int &cb_type, void* &cb, void* &user_data);
+ bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
+ bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data);
void operate_sensor(sensor_id_t sensor, int power_save_state);
void get_listening_sensors(sensor_id_vector &sensors);
- unsigned int get_active_min_interval(sensor_id_t sensor_id);
+ bool get_active_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency);
unsigned int get_active_option(sensor_id_t sensor_id);
void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types);
THREAD_STATE_STOP,
THREAD_STATE_TERMINATE,
};
- typedef lock_guard<mutex> lock;
- typedef unique_lock<mutex> ulock;
+ typedef std::lock_guard<std::mutex> lock;
+ typedef std::unique_lock<std::mutex> ulock;
sensor_handle_info_map m_sensor_handle_infos;
sensor_command_channel_map m_command_channels;
cmutex m_handle_info_lock;
thread_state m_thread_state;
- mutex m_thread_mutex;
- condition_variable m_thread_cond;
+ std::mutex m_thread_mutex;
+ std::condition_variable m_thread_cond;
hup_observer_t m_hup_observer;
#include <client_common.h>
#include <csensor_handle_info.h>
+#include <limits>
using std::pair;
}
}
-bool csensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, int cb_type, void *cb, void *user_data)
+bool csensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb, void *user_data)
{
creg_event_info event_info;
event_info.m_handle = m_handle;
event_info.type = event_type;
event_info.m_interval = interval;
+ event_info.m_latency = latency;
event_info.m_cb_type = cb_type;
event_info.m_cb = cb;
event_info.m_user_data = user_data;
return m_event_id++;
}
-bool csensor_handle_info::change_reg_event_interval(unsigned int event_type, unsigned int interval)
+bool csensor_handle_info::change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency)
{
auto it_event = m_reg_event_infos.find(event_type);
it_event->second.m_id = renew_event_id();
it_event->second.m_interval = interval;
+ it_event->second.m_latency = latency;
return true;
}
-unsigned int csensor_handle_info::get_min_interval(void)
+void csensor_handle_info::get_batch(unsigned int &interval, unsigned int &latency)
{
- unsigned int min_interval = POLL_MAX_HZ_MS;
- unsigned int interval;
-
if (m_reg_event_infos.empty()) {
DBG("No events are registered for client %s", get_client_name());
- return min_interval;
+ interval = POLL_MAX_HZ_MS;
+ latency = 0;
+ return;
}
+ unsigned int min_interval = POLL_MAX_HZ_MS;
+ unsigned int min_latency = std::numeric_limits<unsigned int>::max();
+
+ unsigned int _interval;
+ unsigned int _latency;
+
auto it_event = m_reg_event_infos.begin();
while (it_event != m_reg_event_infos.end()) {
- interval = it_event->second.m_interval;
- min_interval = (interval < min_interval) ? interval : min_interval;
+ _interval = it_event->second.m_interval;
+ _latency = it_event->second.m_latency;
+
+ min_interval = (_interval < min_interval) ? _interval : min_interval;
+ min_latency = (_latency < min_latency) ? _latency : min_latency;
++it_event;
}
- return min_interval;
+ interval = min_interval;
+ latency = min_latency;
}
unsigned int csensor_handle_info::get_reg_event_count(void)
#include <common.h>
#include <string.h>
#include <unordered_map>
-#include <vector>
-using std::unordered_map;
-using std::vector;
-typedef unordered_map<unsigned int,creg_event_info> event_info_map;
+typedef std::unordered_map<unsigned int,creg_event_info> event_info_map;
class csensor_handle_info {
public:
csensor_handle_info();
~csensor_handle_info();
- bool add_reg_event_info(unsigned int event_type, unsigned int interval, int cb_type, void *cb,void *user_data);
+ bool add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb,void *user_data);
bool delete_reg_event_info(unsigned int event_type);
- bool change_reg_event_interval(unsigned int event_type, unsigned int interval);
+ bool change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency);
creg_event_info* get_reg_event_info(const unsigned int event_type);
void get_reg_event_types(event_type_vector &event_types);
- unsigned int get_min_interval(void);
+ void get_batch(unsigned int &interval, unsigned int &latency);
unsigned int get_reg_event_count(void);
void clear_all_events(void);
#include <algorithm>
#include <queue>
-using std::queue;
-
class poller {
public:
poller(int fd);
bool poll(int &event);
private:
int m_epfd;
- queue<int> m_event_queue;
+ std::queue<int> m_event_queue;
bool create(int fd);
bool fill_event_queue(void);
#include <sensor_info_manager.h>
#include <utility>
+#include <vector>
using std::pair;
using std::make_pair;
+using std::vector;
sensor_info_manager::sensor_info_manager()
{
#include <unordered_map>
#include <unordered_set>
-using std::multimap;
-using std::unordered_map;
-using std::unordered_set;
-
class sensor_info_manager {
public:
static sensor_info_manager& get_instance(void);
const sensor_info* get_info(sensor_type_t type);
- vector<sensor_info *> get_infos(sensor_type_t type);
+ std::vector<sensor_info *> get_infos(sensor_type_t type);
const sensor_info* get_info(sensor_id_t id);
bool is_valid(sensor_info* info);
void add_info(sensor_info* info);
private:
- typedef multimap<sensor_type_t, sensor_info*> sensor_infos;
- typedef unordered_map<sensor_id_t, sensor_info*> id_to_info_map;
- typedef unordered_set<sensor_info*> info_set;
+ typedef std::multimap<sensor_type_t, sensor_info*> sensor_infos;
+ typedef std::unordered_map<sensor_id_t, sensor_info*> id_to_info_map;
+ typedef std::unordered_set<sensor_info*> info_set;
sensor_info_manager();
~sensor_info_manager();
#define DEPRECATED __attribute__((deprecated))
#endif
+#ifndef API
+#define API __attribute__((visibility("default")))
+#endif
+
#include "stdbool.h"
#ifdef __cplusplus
* @brief Change the max batch latency of a specifed event type in a connected sensor.
*
* @param[in] handle a handle represensting a connected sensor.
+ * @param[in] event_type an event type to change max batch latency
* @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
* @return true on success, otherwise false.
*/
-bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency);
+bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
/**
* @brief Change the option of a connected sensor.
};
enum proxi_change_state {
- PROXIMITY_STATE_FAR = 0,
+ PROXIMITY_STATE_FAR = 0,
PROXIMITY_STATE_NEAR = 1,
};
#include <light_sensor.h>
#include <sensor_plugin_loader.h>
#include <algorithm>
+#include <string>
using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define SENSOR_NAME "LIGHT_SENSOR"
bool light_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(LIGHT_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_LIGHT);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
}
INFO("%s is created!", sensor_base::get_name());
+
return true;
}
-sensor_type_t light_sensor::get_type(void)
+void light_sensor::get_types(vector<sensor_type_t> &types)
{
- return LIGHT_SENSOR;
+ types.push_back(LIGHT_SENSOR);
}
bool light_sensor::working(void *inst)
return stop_poll();
}
-bool light_sensor::get_properties(sensor_properties_s &properties)
+bool light_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
m_sensor_hal->get_properties(properties);
return true;
virtual ~light_sensor();
virtual bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(const unsigned int type, sensor_data_t &data);
-
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
static const int m_light_level[];
#include <sys/ioctl.h>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_LIGHT "LIGHT"
#define ELEMENT_NAME "NAME"
}
-sensor_type_t light_sensor_hal::get_type(void)
+sensor_hal_type_t light_sensor_hal::get_type(void)
{
- return LIGHT_SENSOR;
+ return SENSOR_HAL_TYPE_LIGHT;
}
bool light_sensor_hal::enable(void)
#define _LIGHT_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class light_sensor_hal : public sensor_hal
{
public:
light_sensor_hal();
virtual ~light_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
virtual int get_sensor_data(sensor_data_t &data);
bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
int m_node_handle;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <sensor_plugin_loader.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "LINEAR_ACCEL_SENSOR"
#define SENSOR_TYPE_LINEAR_ACCEL "LINEAR_ACCEL"
#define SENSOR_TYPE_GRAVITY "GRAVITY"
m_enable_linear_accel = 0;
register_supported_event(LINEAR_ACCEL_RAW_DATA_EVENT);
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t linear_accel_sensor::get_type(void)
+void linear_accel_sensor::get_types(vector<sensor_type_t> &types)
{
- return LINEAR_ACCEL_SENSOR;
+ types.push_back(LINEAR_ACCEL_SENSOR);
}
bool linear_accel_sensor::on_start(void)
return 0;
}
-bool linear_accel_sensor::get_properties(sensor_properties_s &properties)
+bool linear_accel_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
- m_accel_sensor->get_properties(properties);
+ m_accel_sensor->get_properties(ACCELEROMETER_SENSOR, properties);
properties.name = "Linear Acceleration Sensor";
properties.vendor = m_vendor;
properties.resolution = 0.000001;
virtual ~linear_accel_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
- bool get_properties(sensor_properties_s &properties);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_base *m_accel_sensor;
sensor_base *m_gyro_sensor;
unsigned int m_enable_linear_accel;
- string m_vendor;
- string m_raw_data_unit;
- string m_orientation_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
+ std::string m_orientation_data_unit;
int m_default_sampling_time;
float m_accel_static_bias[3];
int m_accel_rotation_direction_compensation[3];
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "ORIENTATION_SENSOR"
#define SENSOR_TYPE_ORIENTATION "ORIENTATION"
{
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t orientation_sensor::get_type(void)
+void orientation_sensor::get_types(vector<sensor_type_t> &types)
{
- return ORIENTATION_SENSOR;
+ types.push_back(ORIENTATION_SENSOR);
}
bool orientation_sensor::on_start(void)
return 0;
}
-bool orientation_sensor::get_properties(sensor_properties_s &properties)
+bool orientation_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
if(m_raw_data_unit == "DEGREES") {
properties.min_range = -180;
bool init(void);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
int m_azimuth_rotation_compensation;
int m_pitch_rotation_compensation;
using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define SENSOR_NAME "PRESSURE_SENSOR"
#define SENSOR_TYPE_PRESSURE "PRESSURE"
bool pressure_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PRESSURE_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PRESSURE);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t pressure_sensor::get_type(void)
+void pressure_sensor::get_types(vector<sensor_type_t> &types)
{
- return PRESSURE_SENSOR;
+ types.push_back(PRESSURE_SENSOR);
}
bool pressure_sensor::working(void *inst)
return stop_poll();
}
-bool pressure_sensor::get_properties(sensor_properties_s &properties)
+bool pressure_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~pressure_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
#include <fstream>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_PRESSURE "PRESSURE"
#define ELEMENT_NAME "NAME"
return m_model_id;
}
-sensor_type_t pressure_sensor_hal::get_type(void)
+sensor_hal_type_t pressure_sensor_hal::get_type(void)
{
- return PRESSURE_SENSOR;
+ return SENSOR_HAL_TYPE_PRESSURE;
}
bool pressure_sensor_hal::enable(void)
#define _PRESSURE_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class pressure_sensor_hal : public sensor_hal
{
public:
pressure_sensor_hal();
virtual ~pressure_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
virtual int get_sensor_data(sensor_data_t &data);
virtual bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
float m_pressure;
float m_sea_level_pressure;
unsigned long long m_fired_time;
int m_node_handle;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <proxi_sensor.h>
#include <sensor_plugin_loader.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "PROXI_SENSOR"
proxi_sensor::proxi_sensor()
bool proxi_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PROXIMITY_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PROXIMITY);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t proxi_sensor::get_type(void)
+void proxi_sensor::get_types(vector<sensor_type_t> &types)
{
- return PROXIMITY_SENSOR;
+ types.push_back(PROXIMITY_SENSOR);
}
bool proxi_sensor::working(void *inst)
return stop_poll();
}
-bool proxi_sensor::get_properties(sensor_properties_s &properties)
+bool proxi_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
m_sensor_hal->get_properties(properties);
virtual ~proxi_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
#include <sys/ioctl.h>
#include <fstream>
+using std::string;
using std::ifstream;
#define SENSOR_TYPE_PROXI "PROXI"
return m_model_id;
}
-sensor_type_t proxi_sensor_hal::get_type(void)
+sensor_hal_type_t proxi_sensor_hal::get_type(void)
{
- return PROXIMITY_SENSOR;
+ return SENSOR_HAL_TYPE_PROXIMITY;
}
bool proxi_sensor_hal::enable(void)
#define _PROXI_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class proxi_sensor_hal : public sensor_hal
{
proxi_sensor_hal();
virtual ~proxi_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool is_data_ready(bool wait);
virtual int get_sensor_data(sensor_data_t &data);
virtual bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
- string m_enable_node;
- string m_data_node;
+ std::string m_enable_node;
+ std::string m_data_node;
unsigned int m_state;
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "GAMING_RV_SENSOR"
#define SENSOR_TYPE_GAMING_RV "GAMING_ROTATION_VECTOR"
{
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t gaming_rv_sensor::get_type(void)
+void gaming_rv_sensor::get_types(vector<sensor_type_t> &types)
{
- return GAMING_RV_SENSOR;
+ types.push_back(GAMING_RV_SENSOR);
}
bool gaming_rv_sensor::on_start(void)
return 0;
}
-bool gaming_rv_sensor::get_properties(sensor_properties_s &properties)
+bool gaming_rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.vendor = m_vendor;
properties.name = SENSOR_NAME;
bool init(void);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t &event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
float m_accel_static_bias[3];
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "GEOMAGNETIC_RV_SENSOR"
#define SENSOR_TYPE_GEOMAGNETIC_RV "GEOMAGNETIC_ROTATION_VECTOR"
{
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t geomagnetic_rv_sensor::get_type(void)
+void geomagnetic_rv_sensor::get_types(vector<sensor_type_t> &types)
{
- return GEOMAGNETIC_RV_SENSOR;
+ types.push_back(GEOMAGNETIC_RV_SENSOR);
}
bool geomagnetic_rv_sensor::on_start(void)
return 0;
}
-bool geomagnetic_rv_sensor::get_properties(sensor_properties_s &properties)
+bool geomagnetic_rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.vendor = m_vendor;
properties.name = SENSOR_NAME;
bool init(void);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t &event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
bool on_start(void);
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "RV_SENSOR"
#define SENSOR_TYPE_RV "ROTATION_VECTOR"
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
// Will check if fusion_sensor is in the list of hal sensors.
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t rv_sensor::get_type(void)
+void rv_sensor::get_types(vector<sensor_type_t> &types)
{
- return ROTATION_VECTOR_SENSOR;
+ types.push_back(ROTATION_VECTOR_SENSOR);
}
bool rv_sensor::on_start(void)
return 0;
}
-bool rv_sensor::get_properties(sensor_properties_s &properties)
+bool rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.vendor = m_vendor;
properties.name = SENSOR_NAME;
bool init(void);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t &event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
bool on_start(void);
#include <rv_raw_sensor.h>
#include <sensor_plugin_loader.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "RV_RAW_SENSOR"
rv_raw_sensor::rv_raw_sensor()
bool rv_raw_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(RV_RAW_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_RV_RAW);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t rv_raw_sensor::get_type(void)
+void rv_raw_sensor::get_types(vector<sensor_type_t> &types)
{
- return RV_RAW_SENSOR;
+ types.push_back(RV_RAW_SENSOR);
}
bool rv_raw_sensor::working(void *inst)
return stop_poll();
}
-bool rv_raw_sensor::get_properties(sensor_properties_t &properties)
+bool rv_raw_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~rv_raw_sensor();
virtual bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_t &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
#include <fstream>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_RV_RAW "ROTATION_VECTOR"
#define ELEMENT_NAME "NAME"
return m_model_id;
}
-sensor_type_t rv_raw_sensor_hal::get_type(void)
+sensor_hal_type_t rv_raw_sensor_hal::get_type(void)
{
- return RV_RAW_SENSOR;
+ return SENSOR_HAL_TYPE_RV_RAW;
}
bool rv_raw_sensor_hal::enable(void)
#define _RV_RAW_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class rv_raw_sensor_hal : public sensor_hal
{
public:
rv_raw_sensor_hal();
virtual ~rv_raw_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
virtual int get_sensor_data(sensor_data_t &data);
virtual bool get_properties(sensor_properties_t &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
unsigned long m_polling_interval;
unsigned long long m_fired_time;
int m_node_handle;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <sensor_gravity.h>
#include <thread>
#include <string>
+#include <vector>
#include <utility>
#include <permission_checker.h>
#include <set>
using std::string;
+using std::vector;
using std::make_pair;
using std::set;
, m_permission(SENSOR_PERMISSION_NONE)
, m_socket(socket)
, m_module(NULL)
+, m_sensor_id(UNKNOWN_SENSOR)
{
static bool init = false;
m_cmd_handlers[CMD_REG] = &command_worker::cmd_register_event;
m_cmd_handlers[CMD_UNREG] = &command_worker::cmd_unregister_event;
m_cmd_handlers[CMD_SET_OPTION] = &command_worker::cmd_set_option;
- m_cmd_handlers[CMD_SET_INTERVAL] = &command_worker::cmd_set_interval;
- m_cmd_handlers[CMD_UNSET_INTERVAL] = &command_worker::cmd_unset_interval;
+ m_cmd_handlers[CMD_SET_BATCH] = &command_worker::cmd_set_batch;
+ m_cmd_handlers[CMD_UNSET_BATCH] = &command_worker::cmd_unset_batch;
m_cmd_handlers[CMD_SET_COMMAND] = &command_worker::cmd_set_command;
m_cmd_handlers[CMD_GET_DATA] = &command_worker::cmd_get_data;
m_cmd_handlers[CMD_SEND_SENSORHUB_DATA] = &command_worker::cmd_send_sensorhub_data;
sensors = sensor_plugin_loader::get_instance().get_sensors(ALL_SENSOR);
+ std::sort(sensors.begin(), sensors.end());
+ auto last = std::unique(sensors.begin(), sensors.end());
+
auto it_sensor = sensors.begin();
- while (it_sensor != sensors.end()) {
- (*it_sensor)->get_sensor_info(info);
- permission = (*it_sensor)->get_permission();
+ while (it_sensor != last) {
+
+ vector<sensor_type_t> types;
+ (*it_sensor)->get_types(types);
- sensor_raw_data_map::iterator it_sensor_raw_data;
- it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t()));
+ for (unsigned int i = 0; i < types.size(); ++i) {
+ (*it_sensor)->get_sensor_info(types[i], info);
+ permission = (*it_sensor)->get_permission();
- info.get_raw_data(it_sensor_raw_data->second);
- info.clear();
+ sensor_raw_data_map::iterator it_sensor_raw_data;
+ it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t()));
+
+ info.get_raw_data(it_sensor_raw_data->second);
+ info.clear();
+ }
++it_sensor;
}
}
if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
- get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_module->get_id(), event_vec);
+ get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_sensor_id, event_vec);
auto it_event = event_vec.begin();
++it_event;
}
- if (get_client_info_manager().is_started(inst->m_client_id, inst->m_module->get_id())) {
+ if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) {
WARN("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name());
inst->m_module->delete_interval(inst->m_client_id, false);
inst->m_module->stop();
}
- if (inst->m_module->get_id()) {
- if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_module->get_id())) {
- INFO("Removing sensor[0x%x] record for client_id[%d]", inst->m_module->get_id(), inst->m_client_id);
- get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_module->get_id());
+ if (inst->m_sensor_id) {
+ if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) {
+ INFO("Removing sensor[0x%x] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id);
+ get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id);
}
}
}
{
cmd_get_id_t *cmd;
int client_id;
+ struct ucred cr;
+ socklen_t opt_len = sizeof(cr);
DBG("CMD_GET_ID Handler invoked\n");
cmd = (cmd_get_id_t*)payload;
+ if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) {
+ ERR("Failed to get socket option with SO_PEERCRED");
+ return false;
+ }
+
client_id = get_client_info_manager().create_client_record();
- get_client_info_manager().set_client_info(client_id, cmd->pid);
+
+ get_client_info_manager().set_client_info(client_id, cr.pid, cmd->name);
m_permission = get_permission();
get_client_info_manager().set_permission(client_id, m_permission);
DBG("CMD_HELLO Handler invoked\n");
cmd = (cmd_hello_t*)payload;
+ m_sensor_id = cmd->sensor;
m_client_id = cmd->client_id;
if (m_permission == SENSOR_PERMISSION_NONE)
}
if (!is_permission_allowed()) {
- ERR("Permission denied to connect sensor[0x%x] for client [%d]", m_module->get_id(), m_client_id);
+ ERR("Permission denied to connect sensor[0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
goto out;
}
- DBG("Hello sensor [0x%x], client id [%d]", m_module->get_id(), m_client_id);
- get_client_info_manager().create_sensor_record(m_client_id, m_module->get_id());
- INFO("New sensor record created for sensor [0x%x], sensor name [%s] on client id [%d]\n", m_module->get_id(), m_module->get_name(), m_client_id);
+ DBG("Hello sensor [0x%x], client id [%d]", m_sensor_id, m_client_id);
+ get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id);
+ INFO("New sensor record created for sensor [0x%x], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id);
ret_value = OP_SUCCESS;
out:
if (!send_cmd_done(ret_value))
long ret_value = OP_ERROR;
if (!is_permission_allowed()) {
- ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id);
+ ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
goto out;
}
- DBG("CMD_BYEBYE for client [%d], sensor [0x%x]", m_client_id, m_module->get_id());
+ DBG("CMD_BYEBYE for client [%d], sensor [0x%x]", m_client_id, m_sensor_id);
- if (!get_client_info_manager().remove_sensor_record(m_client_id, m_module->get_id())) {
+ if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) {
ERR("Error removing sensor_record for client [%d]", m_client_id);
ret_value = OP_ERROR;
goto out;
long ret_value = OP_ERROR;
if (!is_permission_allowed()) {
- ERR("Permission denied to start sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id);
+ ERR("Permission denied to start sensor[0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
goto out;
}
- DBG("START Sensor [0x%x], called from client [%d]", m_module->get_id(), m_client_id);
+ DBG("START Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id);
if (m_module->start()) {
- get_client_info_manager().set_start(m_client_id, m_module->get_id(), true);
+ get_client_info_manager().set_start(m_client_id, m_sensor_id, true);
/*
* Rotation could be changed even LCD is off by pop sync rotation
* and a client listening rotation event with always-on option.
* To reflect the last rotation state, request it to event dispatcher.
*/
- get_event_dispathcher().request_last_event(m_client_id, m_module->get_id());
+ get_event_dispathcher().request_last_event(m_client_id, m_sensor_id);
ret_value = OP_SUCCESS;
} else {
- ERR("Failed to start sensor [0x%x] for client [%d]", m_module->get_id(), m_client_id);
+ ERR("Failed to start sensor [0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
}
long ret_value = OP_ERROR;
if (!is_permission_allowed()) {
- ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id);
+ ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
goto out;
}
- DBG("STOP Sensor [0x%x], called from client [%d]", m_module->get_id(), m_client_id);
+ DBG("STOP Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id);
if (m_module->stop()) {
- get_client_info_manager().set_start(m_client_id, m_module->get_id(), false);
+ get_client_info_manager().set_start(m_client_id, m_sensor_id, false);
ret_value = OP_SUCCESS;
} else {
- ERR("Failed to stop sensor [0x%x] for client [%d]", m_module->get_id(), m_client_id);
+ ERR("Failed to stop sensor [0x%x] for client [%d]", m_sensor_id, m_client_id);
ret_value = OP_ERROR;
}
goto out;
}
- if (!get_client_info_manager().register_event(m_client_id, m_module? m_module->get_id() : -1, cmd->event_type)) {
+ if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) {
INFO("Failed to register event [0x%x] for client [%d] to client info manager",
cmd->event_type, m_client_id);
ret_value = OP_ERROR;
goto out;
}
- if (!get_client_info_manager().unregister_event(m_client_id, m_module->get_id(), cmd->event_type)) {
+ if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) {
ERR("Failed to unregister event [0x%x] for client [%d] from client info manager",
cmd->event_type, m_client_id);
ret_value = OP_ERROR;
return true;
}
-bool command_worker::cmd_set_interval(void *payload)
+bool command_worker::cmd_set_batch(void *payload)
{
- cmd_set_interval_t *cmd;
+ cmd_set_batch_t *cmd;
long ret_value = OP_ERROR;
- cmd = (cmd_set_interval_t*)payload;
+ cmd = (cmd_set_batch_t*)payload;
if (!is_permission_allowed()) {
- ERR("Permission denied to register interval for client [%d], for sensor [0x%x] with interval [%d] to client info manager",
- m_client_id, m_module? m_module->get_id() : -1, cmd->interval);
+ ERR("Permission denied to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager",
+ m_client_id, m_sensor_id, cmd->interval, cmd->latency);
ret_value = OP_ERROR;
goto out;
}
- if (!get_client_info_manager().set_interval(m_client_id, m_module->get_id(), cmd->interval)) {
- ERR("Failed to register interval for client [%d], for sensor [0x%x] with interval [%d] to client info manager",
- m_client_id, m_module->get_id(), cmd->interval);
+ if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) {
+ ERR("Failed to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager",
+ m_client_id, m_sensor_id, cmd->interval, cmd->latency);
ret_value = OP_ERROR;
goto out;
}
if (!m_module->add_interval(m_client_id, cmd->interval, false)) {
ERR("Failed to set interval for client [%d], for sensor [0x%x] with interval [%d]",
- m_client_id, m_module->get_id(), cmd->interval);
+ m_client_id, m_sensor_id, cmd->interval);
ret_value = OP_ERROR;
goto out;
}
return true;
}
-bool command_worker::cmd_unset_interval(void *payload)
+bool command_worker::cmd_unset_batch(void *payload)
{
long ret_value = OP_ERROR;
if (!is_permission_allowed()) {
- ERR("Permission denied to unregister interval for client [%d], for sensor [0x%x] to client info manager",
- m_client_id, m_module? m_module->get_id() : -1);
+ ERR("Permission denied to unset batch for client [%d], for sensor [0x%x] to client info manager",
+ m_client_id, m_sensor_id);
ret_value = OP_ERROR;
goto out;
}
- if (!get_client_info_manager().set_interval(m_client_id, m_module->get_id(), 0)) {
- ERR("Failed to unregister interval for client [%d], for sensor [0x%x] to client info manager",
- m_client_id, m_module->get_id());
+ if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) {
+ ERR("Failed to unset batch for client [%d], for sensor [0x%x] to client info manager",
+ m_client_id, m_sensor_id);
ret_value = OP_ERROR;
goto out;
}
if (!is_permission_allowed()) {
ERR("Permission denied to set interval for client [%d], for sensor [0x%x] with option [%d] to client info manager",
- m_client_id, m_module? m_module->get_id() : -1, cmd->option);
+ m_client_id, m_sensor_id, cmd->option);
ret_value = OP_ERROR;
goto out;
}
- if (!get_client_info_manager().set_option(m_client_id, m_module->get_id(), cmd->option)) {
+ if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) {
ERR("Failed to set option for client [%d], for sensor [0x%x] with option [%d] to client info manager",
- m_client_id, m_module->get_id(), cmd->option);
+ m_client_id, m_sensor_id, cmd->option);
ret_value = OP_ERROR;
goto out;
}
if (!is_permission_allowed()) {
ERR("Permission denied to set command for client [%d], for sensor [0x%x] with cmd [%d]",
- m_client_id, m_module? m_module->get_id() : -1, cmd->cmd);
+ m_client_id, m_sensor_id, cmd->cmd);
ret_value = OP_ERROR;
goto out;
}
if (!is_permission_allowed()) {
ERR("Permission denied to get data for client [%d], for sensor [0x%x]",
- m_client_id, m_module? m_module->get_id() : -1);
+ m_client_id, m_sensor_id);
state = OP_ERROR;
goto out;
}
// 5. repeat 2 ~ 4 operations RETRY_CNT times
// 6. reverting back to original interval
if (!state && !data.timestamp) {
- const int RETRY_CNT = 3;
+ const int RETRY_CNT = 5;
const unsigned long long INIT_WAIT_TIME = 20000; //20ms
const unsigned long WAIT_TIME = 100000; //100ms
int retry = 0;
}
while (!state && !data.timestamp && (retry++ < RETRY_CNT)) {
- INFO("Wait sensor[0x%x] data updated for client [%d] #%d", m_module->get_id(), m_client_id, retry);
+ INFO("Wait sensor[0x%x] 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_sensor_data(cmd->type, data);
}
if (state) {
ERR("Failed to get data for client [%d], for sensor [0x%x]",
- m_client_id, m_module->get_id());
+ m_client_id, m_sensor_id);
}
out:
if (!is_permission_allowed()) {
ERR("Permission denied to send sensorhub_data for client [%d], for sensor [0x%x]",
- m_client_id, m_module? m_module->get_id() : -1);
+ m_client_id, m_sensor_id);
ret_value = OP_ERROR;
goto out;
}
#include <sensor_base.h>
#include <map>
-using std::multimap;
-
-typedef multimap<int, raw_data_t> sensor_raw_data_map;
+typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
void insert_priority_list(unsigned int);
class command_worker {
csocket m_socket;
worker_thread m_worker;
sensor_base *m_module;
+ sensor_id_t m_sensor_id;
static cmd_handler_t m_cmd_handlers[CMD_CNT];
static cpacket m_sensor_list;
static sensor_raw_data_map m_sensor_raw_data_map;
bool cmd_stop(void *payload);
bool cmd_register_event(void *payload);
bool cmd_unregister_event(void *payload);
- bool cmd_set_interval(void *payload);
- bool cmd_unset_interval(void *payload);
+ bool cmd_set_batch(void *payload);
+ bool cmd_unset_batch(void *payload);
bool cmd_set_option(void *payload);
bool cmd_set_command(void *payload);
bool cmd_get_data(void *payload);
bool cmd_send_sensorhub_data(void *payload);
- void get_info(string &info);
+ void get_info(std::string &info);
int get_permission(void);
bool is_permission_allowed(void);
#include <server.h>
#include <dbus_util.h>
#include <sensor_plugin_loader.h>
+#include <string>
+
+using std::string;
static void sig_term_handler(int signo, siginfo_t *info, void *data)
{
server::get_instance().stop();
- sensor_plugin_loader::get_instance().destroy();
-
INFO("Sensord terminated");
return 0;
}
m_permission_infos.push_back(std::make_shared<permission_info> (SENSOR_PERMISSION_STANDARD, false, ""));
m_permission_infos.push_back(std::make_shared<permission_info> (SENSOR_PERMISSION_BIO, true, "http://tizen.org/privilege/healthinfo"));
- vector<sensor_base *> sensors;
+ std::vector<sensor_base *> sensors;
sensors = sensor_plugin_loader::get_instance().get_sensors(ALL_SENSOR);
for (unsigned int i = 0; i < sensors.size(); ++i)
cclient_info_manager.cpp
cclient_sensor_record.cpp
cinterval_info_list.cpp
+ batch_info_list.cpp
sensor_plugin_loader.cpp
sensor_hal.cpp
sensor_base.cpp
cvirtual_sensor_config.h
csensor_event_queue.h
cinterval_info_list.h
+ batch_info_list.h
sensor_plugin_loader.h
sensor_hal.h
sensor_base.h
--- /dev/null
+/*
+ * libsensord-share
+ *
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <batch_info_list.h>
+#include <algorithm>
+
+using std::pair;
+using std::shared_ptr;
+
+batch_info::batch_info(unsigned int interval, unsigned int latency)
+{
+ this->interval = interval;
+ this->latency = latency;
+}
+
+bool batch_info_list::add_batch(int id, unsigned int interval, unsigned int latency)
+{
+ auto it_batch_info = m_batch_infos.find(id);
+
+ if (it_batch_info != m_batch_infos.end()) {
+ it_batch_info->second->interval = interval;
+ it_batch_info->second->latency = latency;
+ return true;
+ }
+
+ m_batch_infos.insert(pair<int, shared_ptr<batch_info>> (id, std::make_shared<batch_info> (interval, latency)));
+ return true;
+}
+
+bool batch_info_list::delete_batch(int id)
+{
+ auto it_batch_info = m_batch_infos.find(id);
+
+ if (it_batch_info == m_batch_infos.end())
+ return false;
+
+ m_batch_infos.erase(it_batch_info);
+ return true;
+}
+
+bool batch_info_list::get_batch(int id, unsigned int &interval, unsigned int &latency)
+{
+ auto it_batch_info = m_batch_infos.find(id);
+
+ if (it_batch_info == m_batch_infos.end())
+ return false;
+
+ interval = it_batch_info->second->interval;
+ latency = it_batch_info->second->latency;
+
+ return true;
+}
+
+bool batch_info_list::get_best_batch(unsigned int &interval, unsigned int &latency)
+{
+ if (m_batch_infos.empty())
+ return false;
+
+ auto get_min_interval = [](pair<const int, shared_ptr<batch_info>> &a, pair<const int, shared_ptr<batch_info>> &b){
+ return (a.second->interval < b.second->interval);
+ };
+
+ auto get_min_latency = [](pair<const int, shared_ptr<batch_info>> &a, pair<const int, shared_ptr<batch_info>> &b){
+ return (a.second->latency < b.second->latency);
+ };
+
+ auto it_interval_min = std::min_element(m_batch_infos.begin(), m_batch_infos.end(), get_min_interval);
+ auto it_latency_min = std::min_element(m_batch_infos.begin(), m_batch_infos.end(), get_min_latency);
+
+ interval = it_interval_min->second->interval;
+ latency = it_latency_min->second->latency;
+
+ return true;
+}
--- /dev/null
+/*
+ * libsensord-share
+ *
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _BATCH_INFO_LIST_CLASS_H_
+#define _BATCH_INFO_LIST_CLASS_H_
+
+#include <unordered_map>
+#include <memory>
+
+class batch_info
+{
+public:
+ batch_info(unsigned int interval, unsigned int latency);
+ unsigned int interval;
+ unsigned int latency;
+};
+
+class batch_info_list
+{
+private:
+ std::unordered_map<int, std::shared_ptr<batch_info>> m_batch_infos;
+
+public:
+ bool add_batch(int id, unsigned int interval, unsigned int latency);
+ bool delete_batch(int id);
+ bool get_batch(int id, unsigned int &interval, unsigned int &latency);
+ bool get_best_batch(unsigned int &interval, unsigned int &latency);
+};
+#endif
#include <csocket.h>
using std::pair;
+using std::string;
cclient_info_manager::cclient_info_manager()
{
return inst;
}
-
-unsigned int cclient_info_manager::get_interval(int client_id, sensor_id_t sensor_id)
-{
- AUTOLOCK(m_mutex);
-
- auto it_record = m_clients.find(client_id);
-
- if (it_record == m_clients.end()) {
- ERR("Client[%d] is not found", client_id);
- return 0;
- }
-
- return it_record->second.get_interval(sensor_id);
-}
-
bool cclient_info_manager::get_registered_events(int client_id, sensor_id_t sensor_id, event_type_vector &event_vec)
{
AUTOLOCK(m_mutex);
return true;
}
-bool cclient_info_manager::set_interval(int client_id, sensor_id_t sensor_id, unsigned int interval)
+bool cclient_info_manager::set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned latency)
{
AUTOLOCK(m_mutex);
return false;
}
- if(!it_record->second.set_interval(sensor_id, interval))
+ return it_record->second.set_batch(sensor_id, interval, latency);
+}
+
+bool cclient_info_manager::get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency)
+{
+ AUTOLOCK(m_mutex);
+
+ auto it_record = m_clients.find(client_id);
+
+ if (it_record == m_clients.end()) {
+ ERR("Client[%d] is not found", client_id);
return false;
+ }
- return true;
+ return it_record->second.get_batch(sensor_id, interval, latency);
}
bool cclient_info_manager::set_option(int client_id, sensor_id_t sensor_id, int option)
}
-void cclient_info_manager::set_client_info(int client_id, pid_t pid)
+void cclient_info_manager::set_client_info(int client_id, pid_t pid, const string &name)
{
AUTOLOCK(m_mutex);
return;
}
- it_record->second.set_client_info(pid);
+ it_record->second.set_client_info(pid, name);
return;
}
#include <unordered_map>
#include <common.h>
#include <cmutex.h>
-using std::unordered_map;
+#include <vector>
-typedef unordered_map<int,cclient_sensor_record> client_id_sensor_record_map;
-typedef vector<int> client_id_vec;
+typedef std::unordered_map<int,cclient_sensor_record> client_id_sensor_record_map;
+typedef std::vector<int> client_id_vec;
class cclient_info_manager {
bool remove_client_record(int client_id);
bool has_client_record(int client_id);
- void set_client_info(int client_id, pid_t pid);
+ void set_client_info(int client_id, pid_t pid, const std::string &name);
const char* get_client_info(int client_id);
bool set_permission(int client_id, int permission);
bool register_event(int client_id, sensor_id_t sensor_id, unsigned int event_type);
bool unregister_event(int client_id, sensor_id_t sensor_id, unsigned int event_type);
- bool set_interval(int client_id, sensor_id_t sensor_id, unsigned int interval);
- unsigned int get_interval(int client_id, sensor_id_t sensor_id);
+ bool set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned int latency);
+ bool get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency);
bool set_option(int client_id, sensor_id_t sensor_id, int option);
bool set_start(int client_id, sensor_id_t sensor_id, bool start);
#include <common.h>
using std::pair;
+using std::string;
cclient_sensor_record::cclient_sensor_record()
: m_client_id(0)
return true;
}
-bool cclient_sensor_record::set_interval(sensor_id_t sensor_id, unsigned int interval)
-{
- auto it_usage = m_sensor_usages.find(sensor_id);
-
- if (it_usage == m_sensor_usages.end()) {
- csensor_usage usage;
- usage.m_interval = interval;
- m_sensor_usages.insert(pair<sensor_id_t, csensor_usage>(sensor_id, usage));
- } else {
- it_usage->second.m_interval = interval;
- }
-
- return true;
-}
-
bool cclient_sensor_record::set_option(sensor_id_t sensor_id, int option)
{
auto it_usage = m_sensor_usages.find(sensor_id);
return it_usage->second.m_start;
}
+bool cclient_sensor_record::set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency)
+{
+ auto it_usage = m_sensor_usages.find(sensor_id);
+ if (it_usage == m_sensor_usages.end()) {
+ csensor_usage usage;
+ usage.m_interval = interval;
+ usage.m_latency = latency;
+ m_sensor_usages.insert(pair<sensor_id_t, csensor_usage>(sensor_id, usage));
+ } else {
+ it_usage->second.m_interval = interval;
+ it_usage->second.m_latency = latency;
+ }
-unsigned int cclient_sensor_record::get_interval(sensor_id_t sensor_id)
+ return true;
+}
+
+bool cclient_sensor_record::get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency)
{
auto it_usage = m_sensor_usages.find(sensor_id);
if (it_usage == m_sensor_usages.end()) {
ERR("Sensor[0x%x] is not found", sensor_id);
- return 0;
+ return false;
}
- return it_usage->second.m_interval;
+ interval = it_usage->second.m_interval;
+ latency = it_usage->second.m_latency;
+
+ return true;
}
bool cclient_sensor_record::is_listening_event(sensor_id_t sensor_id, unsigned int event_type)
m_client_id = client_id;
}
-void cclient_sensor_record::set_client_info(pid_t pid)
+void cclient_sensor_record::set_client_info(pid_t pid, const string &name)
{
char client_info[NAME_MAX + 32];
- char proc_name[NAME_MAX];
-
m_pid = pid;
- get_proc_name(pid, proc_name);
- snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", proc_name, m_pid, m_client_id);
+ snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", name.c_str(), m_pid, m_client_id);
m_client_info.assign(client_info);
-
}
const char* cclient_sensor_record::get_client_info(void)
#include <csensor_usage.h>
#include <csocket.h>
#include <unordered_map>
+#include <string>
-using std::unordered_map;
-
-typedef unordered_map<sensor_id_t, csensor_usage> sensor_usage_map;
+typedef std::unordered_map<sensor_id_t, csensor_usage> sensor_usage_map;
class cclient_sensor_record {
public:
void set_client_id(int client_id);
- void set_client_info(pid_t pid);
+ void set_client_info(pid_t pid, const std::string &name);
const char* get_client_info(void);
void set_permission(int permission);
bool register_event(sensor_id_t sensor_id, unsigned int event_type);
bool unregister_event(sensor_id_t sensor_id, unsigned int event_type);
- bool set_interval(sensor_id_t sensor_id, unsigned int interval);
- unsigned int get_interval(sensor_id_t sensor_id);
+ bool set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency);
+ bool get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency);
bool set_option(sensor_id_t sensor_id, int option);
bool set_start(sensor_id_t sensor_id, bool start);
int m_client_id;
pid_t m_pid;
int m_permission;
- string m_client_info;
+ std::string m_client_info;
csocket m_event_socket;
sensor_usage_map m_sensor_usages;
};
#include <cconfig.h>
#include <fstream>
+#include <string>
using std::ifstream;
+using std::string;
+using std::istringstream;
cconfig::cconfig(void)
{
#include <unordered_map>
#include <common.h>
-using std::unordered_map;
-using std::string;
-using std::istringstream;
-
class cconfig
{
protected:
- virtual bool load_config(const string& config_path) = 0;
+ virtual bool load_config(const std::string& config_path) = 0;
- string m_device_id;
+ std::string m_device_id;
public:
cconfig();
virtual ~cconfig();
#define _CINTERVAL_INFO_LIST_CLASS_H_
#include <list>
-using std::list;
class cinterval_info
{
unsigned int interval;
};
-typedef list<cinterval_info>::iterator cinterval_info_iterator;
+typedef std::list<cinterval_info>::iterator cinterval_info_iterator;
class cinterval_info_list
{
static bool comp_interval_info(cinterval_info a, cinterval_info b);
cinterval_info_iterator find_if(int client_id, bool is_processor);
- list<cinterval_info> m_list;
+ std::list<cinterval_info> m_list;
public:
bool add_interval(int client_id, unsigned int interval, bool is_processor);
va_end(ap);
}
+#if defined(_DEBUG)
bool get_proc_name(pid_t pid, char *process_name)
{
FILE *fp;
}
strncpy(process_name, buf, NAME_MAX-1);
+ process_name[NAME_MAX-1] = '\0';
fclose(fp);
return true;
}
+#else
+bool get_proc_name(pid_t pid, char *process_name)
+{
+ char buf[NAME_MAX];
+
+ if (sprintf(buf, "%d process", pid) < 1) {
+ return false;
+ }
+
+ strncpy(process_name, buf, NAME_MAX-1);
+ process_name[NAME_MAX-1] = '\0';
+
+ return true;
+}
+#endif
const char* get_client_name(void)
{
#include <sstream>
#include <iostream>
#include <fstream>
+#include <string>
using std::ifstream;
+using std::string;
+using std::istringstream;
#define ROOT_ELEMENT "SENSOR"
#define TEXT_ELEMENT "text"
#define SENSOR_CONFIG_FILE_PATH "/usr/etc/sensors.xml"
-typedef unordered_map<string,string> Element;
+typedef std::unordered_map<std::string,std::string> Element;
/*
* an Element is a group of attributes
* <Element value1 = "10.0", value2 = "20.0"/>
*
*/
-typedef unordered_map<string,Element> Model;
+typedef std::unordered_map<std::string,Element> Model;
/*
* a Model is a group of elements to consist of specific vendor's one sensor configuration
* <NAME value = "LSM330DLC" />
*
*/
-typedef unordered_map<string,Model> Model_list;
+typedef std::unordered_map<std::string,Model> Model_list;
/*
* a Model_list is a group of Model
* <MODEL id = "lsm330dlc_accel">
*
*/
-typedef unordered_map<string,Model_list> Sensor_config;
+typedef std::unordered_map<std::string,Model_list> Sensor_config;
/*
* a SensorConfig represents sensors.xml
* <ACCEL/>
csensor_config(csensor_config const&) {};
csensor_config& operator=(csensor_config const&);
- bool load_config(const string& config_path);
+ bool load_config(const std::string& config_path);
Sensor_config m_sensor_config;
public:
static csensor_config& get_instance(void);
- bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value);
- bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value);
- bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, std::string& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, double& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, long& value);
- bool get(const string& sensor_type, const string& model_id, const string& element, string& value);
- bool get(const string& sensor_type, const string& model_id, const string& element, double& value);
- bool get(const string& sensor_type, const string& model_id, const string& element, long& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, std::string& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, double& value);
+ bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, long& value);
- bool is_supported(const string &sensor_type, const string &model_id);
+ bool is_supported(const std::string &sensor_type, const std::string &model_id);
};
#endif
#include <common.h>
#include <sf_common.h>
#include <thread>
+#include <vector>
+
using std::thread;
+using std::vector;
#define MAX_PENDING_CONNECTION 32
#include <cclient_info_manager.h>
#include <csocket.h>
#include <virtual_sensor.h>
+#include <unordered_map>
+#include <list>
-typedef unordered_map<unsigned int, sensor_event_t> event_type_last_event_map;
-typedef list<virtual_sensor *> virtual_sensors;
+typedef std::unordered_map<unsigned int, sensor_event_t> event_type_last_event_map;
+typedef std::list<virtual_sensor *> virtual_sensors;
class csensor_event_dispatcher
{
#include <csensor_event_queue.h>
#include "common.h"
-csensor_event_queue::csensor_event_queue()
-{
-}
-
csensor_event_queue& csensor_event_queue::get_instance()
{
static csensor_event_queue inst;
return inst;
}
-
-void csensor_event_queue::push(sensor_event_t const &event)
+void csensor_event_queue::push(const sensor_event_t &event)
{
sensor_event_t *new_event = new(std::nothrow) sensor_event_t;
retm_if(!new_event, "Failed to allocate memory");
push_internal(new_event);
}
-void csensor_event_queue::push(sensorhub_event_t const &event)
+void csensor_event_queue::push(sensor_event_t *event)
+{
+ push_internal(event);
+}
+
+void csensor_event_queue::push(const sensorhub_event_t &event)
{
sensorhub_event_t *new_event = new(std::nothrow) sensorhub_event_t;
retm_if(!new_event, "Failed to allocate memory");
push_internal(new_event);
}
+void csensor_event_queue::push(sensorhub_event_t *event)
+{
+ push_internal(event);
+}
+
void csensor_event_queue::push_internal(void *event)
{
lock l(m_mutex);
delete (sensorhub_event_t *)event;
else
delete (sensor_event_t *)event;
-
} else
m_queue.push(event);
#include <condition_variable>
#include <set>
-using namespace std;
-using std::queue;
-using std::mutex;
-using std::lock_guard;
-using std::unique_lock;
-using std::condition_variable;
-using std::set;
-
-extern set<unsigned int> priority_list;
+extern std::set<unsigned int> priority_list;
class csensor_event_queue
{
if (priority_list.empty())
return (e2->data.timestamp < e1->data.timestamp);
- set<unsigned int>::iterator iter_e1 = priority_list.find(e1->event_type);
- set<unsigned int>::iterator iter_e2 = priority_list.find(e2->event_type);
+ std::set<unsigned int>::iterator iter_e1 = priority_list.find(e1->event_type);
+ std::set<unsigned int>::iterator iter_e2 = priority_list.find(e2->event_type);
if (iter_e1 == priority_list.end())
prioritize_e1 = false;
std::priority_queue<void*, std::vector<void*>, compare> m_queue;
- mutex m_mutex;
- condition_variable m_cond_var;
+ std::mutex m_mutex;
+ std::condition_variable m_cond_var;
- typedef lock_guard<mutex> lock;
- typedef unique_lock<mutex> ulock;
+ typedef std::lock_guard<std::mutex> lock;
+ typedef std::unique_lock<std::mutex> ulock;
- csensor_event_queue();
- csensor_event_queue(csensor_event_queue const&) {};
- csensor_event_queue& operator=(csensor_event_queue const&);
+ csensor_event_queue() {};
+ ~csensor_event_queue() {};
+ csensor_event_queue(const csensor_event_queue &) {};
+ csensor_event_queue& operator=(const csensor_event_queue &);
void push_internal(void *event);
-
public:
static csensor_event_queue& get_instance();
- void push(sensor_event_t const &event);
- void push(sensorhub_event_t const &event);
+ void push(const sensor_event_t &event);
+ void push(sensor_event_t *event);
+ void push(const sensorhub_event_t &event);
+ void push(sensorhub_event_t *event);
+
void* pop(void);
};
csensor_usage::csensor_usage()
: m_interval(POLL_MAX_HZ_MS)
+, m_latency(0)
, m_option(SENSOR_OPTION_DEFAULT)
, m_start(false)
{
#include <sf_common.h>
#include <algorithm>
#include <vector>
-using std::vector;
-typedef vector<unsigned int> reg_event_vector;
+typedef std::vector<unsigned int> reg_event_vector;
class csensor_usage {
public:
unsigned int m_interval;
+ unsigned int m_latency;
int m_option;
reg_event_vector m_reg_events;
bool m_start;
#include <csocket.h>
#include <attr/xattr.h>
#include <sys/stat.h>
-
+#include <stdint.h>
csocket::csocket()
: m_sock_fd(-1)
return true;
}
-ssize_t csocket::send_for_seqpacket(void const* buffer, size_t size) const
+ssize_t csocket::send_for_seqpacket(const void *buffer, size_t size) const
{
ssize_t err, len;
}
-ssize_t csocket::send_for_stream(void const* buffer, size_t size) const
+ssize_t csocket::send_for_stream(const void *buffer, size_t size) const
{
ssize_t len;
ssize_t err = 0;
size_t total_sent_size = 0;
do {
- len = ::send(m_sock_fd, (void const*)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags);
+ len = ::send(m_sock_fd, (const void *)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags);
if (len >= 0) {
total_sent_size += len;
}
-ssize_t csocket::send(void const* buffer, size_t size) const
+ssize_t csocket::send(const void *buffer, size_t size) const
{
if (m_sock_type == SOCK_STREAM)
return send_for_stream(buffer, size);
#include <errno.h>
#include <fcntl.h>
#include "common.h"
-#include <string>
-using std::string;
class csocket {
public:
bool connect(const char *sock_path);
//Data Transfer
- ssize_t send(void const* buffer, size_t size) const;
+ ssize_t send(const void *buffer, size_t size) const;
ssize_t recv(void* buffer, size_t size) const;
bool set_connection_mode(void);
bool set_blocking_mode(bool blocking);
bool set_sock_type(void);
- ssize_t send_for_seqpacket(void const* buffer, size_t size) const;
- ssize_t send_for_stream(void const* buffer, size_t size) const;
+ ssize_t send_for_seqpacket(const void *buffer, size_t size) const;
+ ssize_t send_for_stream(const void *buffer, size_t size) const;
ssize_t recv_for_seqpacket(void* buffer, size_t size) const;
ssize_t recv_for_stream(void* buffer, size_t size) const;
#define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml"
-typedef unordered_map<string,string> Element;
+typedef std::unordered_map<std::string,std::string> Element;
/*
* an Element is a group of attributes
* <Element value1 = "10.0", value2 = "20.0"/>
*
*/
-typedef unordered_map<string,Element> Virtual_sensor;
+typedef std::unordered_map<std::string,Element> Virtual_sensor;
/*
* a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration
* <ORIENTATION>
* ...
*/
-typedef unordered_map<string,Virtual_sensor> virtual_sensor_config;
+typedef std::unordered_map<std::string,Virtual_sensor> virtual_sensor_config;
/*
* a Virtual_sensor_config represents virtual_sensors.xml
* <ORIENTATION/>
*
*/
-typedef unordered_map<string,virtual_sensor_config> virtual_sensor_device_config;
+typedef std::unordered_map<std::string,virtual_sensor_config> virtual_sensor_device_config;
/*
* a virtual_sensor_device_config represents virtual_sensors.xml
* <emulator/>
cvirtual_sensor_config(cvirtual_sensor_config const&) {};
cvirtual_sensor_config& operator=(cvirtual_sensor_config const&);
- bool load_config(const string& config_path);
+ bool load_config(const std::string& config_path);
virtual_sensor_device_config m_virtual_sensor_config;
public:
static cvirtual_sensor_config& get_instance(void);
- bool get(const string& sensor_type, const string& element, const string& attr, string& value);
- bool get(const string& sensor_type, const string& element, const string& attr, float *value);
- bool get(const string& sensor_type, const string& element, const string& attr, int *value);
+ bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, std::string& value);
+ bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, float *value);
+ bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, int *value);
- bool get(const string& sensor_type, const string& element, string& value);
- bool get(const string& sensor_type, const string& element, float *value, int count =1);
- bool get(const string& sensor_type, const string& element, int *value, int count = 1);
+ bool get(const std::string& sensor_type, const std::string& element, std::string& value);
+ bool get(const std::string& sensor_type, const std::string& element, float *value, int count =1);
+ bool get(const std::string& sensor_type, const std::string& element, int *value, int count = 1);
- bool is_supported(const string &sensor_type);
+ bool is_supported(const std::string &sensor_type);
};
#endif
#include <string>
#include <common.h>
-using std::string;
-using std::ifstream;
-
-
#define NO_OF_ULL_BYTES 8
#define NO_OF_SHORT_VAL 4
#define CH0_INDEX 0
int convert_bytes_to_int(int input, struct channel_parameters *info);
template <typename value_t>
-bool read_node_value(string node_path, value_t &value)
+bool read_node_value(std::string node_path, value_t &value)
{
- ifstream handle;
+ std::ifstream handle;
handle.open(node_path.c_str());
if (!handle)
{
}
-bool physical_sensor::push(sensor_event_t const &event)
+bool physical_sensor::push(const sensor_event_t &event)
{
csensor_event_queue::get_instance().push(event);
return true;
}
-bool physical_sensor::push(sensorhub_event_t const &event)
+bool physical_sensor::push(sensor_event_t *event)
+{
+ csensor_event_queue::get_instance().push(event);
+ return true;
+}
+
+bool physical_sensor::push(const sensorhub_event_t &event)
+{
+ csensor_event_queue::get_instance().push(event);
+ return true;
+}
+
+bool physical_sensor::push(sensorhub_event_t *event)
{
csensor_event_queue::get_instance().push(event);
return true;
physical_sensor();
virtual ~physical_sensor();
- bool push(sensor_event_t const &event);
- bool push(sensorhub_event_t const &event);
+ bool push(const sensor_event_t &event);
+ bool push(sensor_event_t *event);
+ bool push(const sensorhub_event_t &event);
+ bool push(sensorhub_event_t *event);
void set_poller(working_func_t func, void *arg);
bool start_poll(void);
#include <sensor_base.h>
#include <algorithm>
+#include <utility>
+
+using std::make_pair;
+using std::vector;
#define UNKNOWN_NAME "UNKNOWN_SENSOR"
return false;
}
-void sensor_base::set_id(sensor_id_t id)
+void sensor_base::add_id(sensor_id_t id)
{
- m_id = id;
+ m_ids.insert(std::make_pair(static_cast<sensor_type_t> (id & SENSOR_TYPE_MASK), id));
}
sensor_id_t sensor_base::get_id(void)
{
- return m_id;
+ auto it = m_ids.begin();
+
+ if (it != m_ids.end())
+ return it->second;
+
+ return UNKNOWN_SENSOR;
+}
+
+sensor_id_t sensor_base::get_id(sensor_type_t sensor_type)
+{
+
+ auto it = m_ids.find(sensor_type);
+
+ if (it != m_ids.end())
+ return it->second;
+
+ return UNKNOWN_SENSOR;
}
sensor_privilege_t sensor_base::get_privilege(void)
m_permission = permission;
}
-
-sensor_type_t sensor_base::get_type()
-{
- return UNKNOWN_SENSOR;
-}
-
const char* sensor_base::get_name()
{
if (m_name.empty())
if (cur_min != prev_min) {
INFO("Min interval for sensor[0x%x] is changed from %dms to %dms"
" by%sclient[%d] adding interval",
- get_type(), prev_min, cur_min,
+ get_id(), prev_min, cur_min,
is_processor ? " processor " : " ", client_id);
set_interval(cur_min);
}
if (!cur_min) {
INFO("No interval for sensor[0x%x] by%sclient[%d] deleting interval, "
"so set to default %dms",
- get_type(), is_processor ? " processor " : " ",
+ get_id(), is_processor ? " processor " : " ",
client_id, POLL_1HZ_MS);
set_interval(POLL_1HZ_MS);
} else if (cur_min != prev_min) {
INFO("Min interval for sensor[0x%x] is changed from %dms to %dms"
" by%sclient[%d] deleting interval",
- get_type(), prev_min, cur_min,
+ get_id(), prev_min, cur_min,
is_processor ? " processor " : " ", client_id);
set_interval(cur_min);
return m_interval_info_list.get_interval(client_id, is_processor);
}
-void sensor_base::get_sensor_info(sensor_info &info)
+void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info)
{
sensor_properties_s properties;
- get_properties(properties);
+ get_properties(sensor_type, properties);
- info.set_type(get_type());
- info.set_id(get_id());
+ info.set_type(sensor_type);
+ info.set_id(get_id(sensor_type));
info.set_privilege(m_privilege);
info.set_name(properties.name.c_str());
info.set_vendor(properties.vendor.c_str());
info.set_min_interval(properties.min_interval);
info.set_fifo_count(properties.fifo_count);
info.set_max_batch_count(properties.max_batch_count);
- info.set_supported_events(m_supported_event_info);
+
+ vector<unsigned int> events;
+
+ for (unsigned int i = 0; i < m_supported_event_info.size(); ++ i) {
+ if (m_supported_event_info[i] & (sensor_type << 16))
+ events.push_back(m_supported_event_info[i]);
+ }
+
+ info.set_supported_events(events);
return;
}
-bool sensor_base::get_properties(sensor_properties_s &properties)
+bool sensor_base::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return false;
}
#define _SENSOR_BASE_H_
#include <list>
+#include <map>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <worker_thread.h>
#include <sensor_info.h>
-using std::string;
-using std::mutex;
-using std::recursive_mutex;
-using std::lock_guard;
-using std::list;
-using std::unordered_map;
-using std::vector;
-using std::unique_lock;
-using std::condition_variable;
-
class sensor_base
{
private:
- typedef unordered_map<unsigned int, unsigned int> client_info;
+ typedef std::unordered_map<unsigned int, unsigned int> client_info;
public:
sensor_base();
virtual ~sensor_base();
virtual bool init(void);
- void set_id(sensor_id_t id);
- sensor_id_t get_id(void);
- virtual sensor_type_t get_type(void);
+ void add_id(sensor_id_t id);
+ sensor_id_t get_id(sensor_type_t sensor_type);
+ virtual void get_types(std::vector<sensor_type_t> &types) {};
+
sensor_privilege_t get_privilege(void);
int get_permission(void);
virtual const char* get_name(void);
virtual bool delete_interval(int client_id, bool is_processor);
unsigned int get_interval(int client_id, bool is_processor);
+ void get_sensor_info(sensor_type_t sensor_type, sensor_info &info);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
- void get_sensor_info(sensor_info &info);
- virtual bool get_properties(sensor_properties_s &properties);
bool is_supported(unsigned int event_type);
virtual long set_command(unsigned int cmd, long value);
void register_supported_event(unsigned int event_type);
void unregister_supported_event(unsigned int event_type);
protected:
- typedef lock_guard<mutex> lock;
- typedef lock_guard<recursive_mutex> rlock;
- typedef unique_lock<mutex> ulock;
+ typedef std::lock_guard<std::mutex> lock;
+ typedef std::lock_guard<std::recursive_mutex> rlock;
+ typedef std::unique_lock<std::mutex> ulock;
- sensor_id_t m_id;
+ std::map<sensor_type_t, sensor_id_t> m_ids;
sensor_privilege_t m_privilege;
int m_permission;
client_info m_client_info;
cmutex m_client_info_mutex;
- vector<unsigned int> m_supported_event_info;
-
+ std::vector<unsigned int> m_supported_event_info;
bool m_started;
- string m_name;
+ std::string m_name;
+ sensor_id_t get_id(void);
void set_privilege(sensor_privilege_t privilege);
void set_permission(int permission);
unsigned int get_client_cnt(unsigned int event_type);
#include <csensor_config.h>
using std::ifstream;
+using std::ofstream;
using std::fstream;
+using std::string;
cmutex sensor_hal::m_shared_mutex;
bool sensor_hal::set_node_value(const string &node_path, int value)
{
- fstream node(node_path, fstream::out);
+ ofstream node(node_path, ofstream::binary);
if (!node)
return false;
bool sensor_hal::set_node_value(const string &node_path, unsigned long long value)
{
- fstream node(node_path, fstream::out);
+ ofstream node(node_path, ofstream::binary);
if (!node)
return false;
bool sensor_hal::get_node_value(const string &node_path, int &value)
{
- fstream node(node_path, fstream::in);
+ ifstream node(node_path, ifstream::binary);
if (!node)
return false;
#include <sensor_internal.h>
#include <string>
-using std::string;
-
/*
* As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock
* Current kernel-headers package doesn't have it so we should define it here.
#define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */
#endif
+typedef enum {
+ SENSOR_HAL_TYPE_ACCELEROMETER,
+ SENSOR_HAL_TYPE_GEOMAGNETIC,
+ SENSOR_HAL_TYPE_LIGHT,
+ SENSOR_HAL_TYPE_PROXIMITY,
+ SENSOR_HAL_TYPE_GYROSCOPE,
+ SENSOR_HAL_TYPE_PRESSURE,
+ SENSOR_HAL_TYPE_CONTEXT,
+ SENSOR_HAL_TYPE_BIO,
+ SENSOR_HAL_TYPE_BIO_HRM,
+ SENSOR_HAL_TYPE_PIR,
+ SENSOR_HAL_TYPE_PIR_LONG,
+ SENSOR_HAL_TYPE_TEMPERATURE,
+ SENSOR_HAL_TYPE_HUMIDITY,
+ SENSOR_HAL_TYPE_ULTRAVIOLET,
+ SENSOR_HAL_TYPE_DUST,
+ SENSOR_HAL_TYPE_BIO_LED_IR,
+ SENSOR_HAL_TYPE_BIO_LED_RED,
+ SENSOR_HAL_TYPE_BIO_LED_GREEN,
+ SENSOR_HAL_TYPE_RV_RAW,
+ SENSOR_HAL_TYPE_GYROSCOPE_UNCAL,
+ SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL,
+ SENSOR_HAL_TYPE_FUSION,
+} sensor_hal_type_t;
+
typedef struct {
int method;
- string data_node_path;
- string enable_node_path;
- string interval_node_path;
- string buffer_enable_node_path;
- string buffer_length_node_path;
- string trigger_node_path;
+ std::string data_node_path;
+ std::string enable_node_path;
+ std::string interval_node_path;
+ std::string buffer_enable_node_path;
+ std::string buffer_length_node_path;
+ std::string trigger_node_path;
} node_info;
typedef struct {
bool sensorhub_controlled;
- string sensor_type;
- string key;
- string iio_enable_node_name;
- string sensorhub_interval_node_name;
+ std::string sensor_type;
+ std::string key;
+ std::string iio_enable_node_name;
+ std::string sensorhub_interval_node_name;
} node_info_query;
enum input_method {
virtual ~sensor_hal();
virtual bool init(void *data = NULL);
- virtual string get_model_id(void) = 0;
- virtual sensor_type_t get_type(void) = 0;
+ virtual std::string get_model_id(void) = 0;
+ virtual sensor_hal_type_t get_type(void) = 0;
virtual bool enable(void) = 0;
virtual bool disable(void) = 0;
virtual bool set_interval(unsigned long val);
virtual bool is_data_ready(bool wait) = 0;
- virtual bool get_properties(sensor_properties_s &properties) = 0;
+ virtual bool get_properties(sensor_properties_s &properties) {return false;};
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) {return false;};
virtual int get_sensor_data(sensor_data_t &data);
virtual int get_sensor_data(sensorhub_data_t &data);
virtual long set_command(unsigned int cmd, long val);
cmutex m_mutex;
static cmutex m_shared_mutex;
- virtual bool set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
+ virtual bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
static unsigned long long get_timestamp(void);
static unsigned long long get_timestamp(timeval *t);
- static bool find_model_id(const string &sensor_type, string &model_id);
- static bool is_sensorhub_controlled(const string &key);
+ static bool find_model_id(const std::string &sensor_type, std::string &model_id);
+ static bool is_sensorhub_controlled(const std::string &key);
static bool get_node_info(const node_info_query &query, node_info &info);
static void show_node_info(node_info &info);
- static bool set_node_value(const string &node_path, int value);
- static bool set_node_value(const string &node_path, unsigned long long value);
- static bool get_node_value(const string &node_path, int &value);
+ static bool set_node_value(const std::string &node_path, int value);
+ static bool set_node_value(const std::string &node_path, unsigned long long value);
+ static bool get_node_value(const std::string &node_path, int &value);
private:
- static bool get_event_num(const string &node_path, string &event_num);
- static bool get_input_method(const string &key, int &method, string &device_num);
+ static bool get_event_num(const std::string &node_path, std::string &event_num);
+ static bool get_input_method(const std::string &key, int &method, std::string &device_num);
- static bool get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info);
- static bool get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info);
- static bool get_input_event_node_info(const string& device_num, node_info &info);
- static bool get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info);
+ static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info);
+ static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
+ static bool get_input_event_node_info(const std::string& device_num, node_info &info);
+ static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
};
#endif /*_SENSOR_HAL_CLASS_H_*/
#include <sensor_info.h>
#include <common.h>
#include <algorithm>
+#include <vector>
+#include <string>
+
+using std::vector;
+using std::string;
sensor_type_t sensor_info::get_type(void)
{
#include <string>
#include <vector>
-using std::string;
-using std::vector;
-
-typedef vector<char> raw_data_t;
+typedef std::vector<char> raw_data_t;
typedef raw_data_t::iterator raw_data_iterator;
class sensor_info
int get_min_interval(void);
int get_fifo_count(void);
int get_max_batch_count(void);
- void get_supported_events(vector<unsigned int> &events);
+ void get_supported_events(std::vector<unsigned int> &events);
bool is_supported_event(unsigned int event);
void set_type(sensor_type_t type);
void set_fifo_count(int fifo_count);
void set_max_batch_count(int max_batch_count);
void register_supported_event(unsigned int event);
- void set_supported_events(vector<unsigned int> &events);
+ void set_supported_events(std::vector<unsigned int> &events);
void clear(void);
sensor_type_t m_type;
sensor_id_t m_id;
sensor_privilege_t m_privilege;
- string m_name;
- string m_vendor;
+ std::string m_name;
+ std::string m_vendor;
float m_min_range;
float m_max_range;
float m_resolution;
int m_min_interval;
int m_fifo_count;
int m_max_batch_count;
- vector<unsigned int> m_supported_events;
+ std::vector<unsigned int> m_supported_events;
void put(raw_data_t &data, int value);
void put(raw_data_t &data, float value);
- void put(raw_data_t &data, string &value);
- void put(raw_data_t &data, vector<unsigned int> &value);
+ void put(raw_data_t &data, std::string &value);
+ void put(raw_data_t &data, std::vector<unsigned int> &value);
raw_data_iterator get(raw_data_iterator it, int &value);
raw_data_iterator get(raw_data_iterator it, float &value);
- raw_data_iterator get(raw_data_iterator it, string &value);
- raw_data_iterator get(raw_data_iterator it, vector<unsigned int> &value);
+ raw_data_iterator get(raw_data_iterator it, std::string &value);
+ raw_data_iterator get(raw_data_iterator it, std::vector<unsigned int> &value);
};
#endif /* _SENSOR_INFO_H_ */
using std::make_pair;
using std::equal;
using std::unordered_set;
+using std::pair;
+using std::vector;
+using std::string;
+using std::shared_ptr;
+using std::static_pointer_cast;
#define ROOT_ELEMENT "PLUGIN"
#define TEXT_ELEMENT "text"
if (!load_module(path, hals, handle))
return false;
- sensor_hal* hal;
+ shared_ptr<sensor_hal> hal;
for (unsigned int i = 0; i < hals.size(); ++i) {
- hal = static_cast<sensor_hal*> (hals[i]);
- sensor_type_t sensor_type = hal->get_type();
- m_sensor_hals.insert(make_pair(sensor_type, hal));
+ hal.reset(static_cast<sensor_hal*> (hals[i]));
+ sensor_hal_type_t sensor_hal_type = hal->get_type();
+ m_sensor_hals.insert(make_pair(sensor_hal_type, hal));
}
} else if (type == PLUGIN_TYPE_SENSOR) {
DBG("Insert Sensor plugin [%s]", path.c_str());
if (!load_module(path, sensors, handle))
return false;
- sensor_base* sensor;
+ shared_ptr<sensor_base> sensor;
for (unsigned int i = 0; i < sensors.size(); ++i) {
- sensor = static_cast<sensor_base*> (sensors[i]);
+ sensor.reset(static_cast<sensor_base*> (sensors[i]));
if (!sensor->init()) {
ERR("Failed to init [%s] module\n", sensor->get_name());
- delete sensor;
continue;
}
DBG("init [%s] module", sensor->get_name());
- sensor_type_t sensor_type = sensor->get_type();
+ vector<sensor_type_t> sensor_types;
- int idx;
- idx = m_sensors.count(sensor_type);
- sensor->set_id(idx << SENSOR_INDEX_SHIFT | sensor_type);
- m_sensors.insert(make_pair(sensor_type, sensor));
+ sensor->get_types(sensor_types);
+
+ for (unsigned int i = 0; i < sensor_types.size(); ++i) {
+ int idx;
+ idx = m_sensors.count(sensor_types[i]);
+ sensor->add_id(idx << SENSOR_INDEX_SHIFT | sensor_types[i]);
+ m_sensors.insert(make_pair(sensor_types[i], sensor));
+ }
}
}else {
ERR("Not supported type: %d", type);
auto it = m_sensors.begin();
while (it != m_sensors.end()) {
- sensor_base* sensor = it->second;
+ shared_ptr<sensor_base> sensor = it->second;
sensor_info info;
- sensor->get_sensor_info(info);
+ sensor->get_sensor_info(it->first, info);
INFO("No:%d [%s]\n", ++index, sensor->get_name());
info.show();
it++;
}
-sensor_hal* sensor_plugin_loader::get_sensor_hal(sensor_type_t type)
+sensor_hal* sensor_plugin_loader::get_sensor_hal(sensor_hal_type_t type)
{
auto it_plugins = m_sensor_hals.find(type);
if (it_plugins == m_sensor_hals.end())
return NULL;
- return it_plugins->second;
+ return it_plugins->second.get();
}
-vector<sensor_hal *> sensor_plugin_loader::get_sensor_hals(sensor_type_t type)
+vector<sensor_hal *> sensor_plugin_loader::get_sensor_hals(sensor_hal_type_t type)
{
vector<sensor_hal *> sensor_hal_list;
pair<sensor_hal_plugins::iterator, sensor_hal_plugins::iterator> ret;
ret = m_sensor_hals.equal_range(type);
for (auto it = ret.first; it != ret.second; ++it)
- sensor_hal_list.push_back(it->second);
+ sensor_hal_list.push_back(it->second.get());
return sensor_hal_list;
}
if (it_plugins == m_sensors.end())
return NULL;
- return it_plugins->second;
+ return it_plugins->second.get();
}
vector<sensor_base *> sensor_plugin_loader::get_sensors(sensor_type_t type)
ret = m_sensors.equal_range(type);
for (auto it = ret.first; it != ret.second; ++it)
- sensor_list.push_back(it->second);
+ sensor_list.push_back(it->second.get());
return sensor_list;
}
sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id)
{
- const int SENSOR_TYPE_MASK = 0x0000FFFF;
vector<sensor_base *> sensors;
sensor_type_t type = (sensor_type_t) (id & SENSOR_TYPE_MASK);
sensor_base* module;
for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) {
- module = sensor_it->second;
+ module = sensor_it->second.get();
if (module && module->is_virtual() == true) {
virtual_list.push_back(module);
return virtual_list;
}
-bool sensor_plugin_loader::destroy()
-{
- sensor_base* sensor;
-
- for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) {
- sensor = sensor_it->second;
-
- //need to dlclose
- //unregister_module(module);
-
- delete sensor;
- }
-
- sensor_hal* sensor_hal;
-
- for (auto sensor_hal_it = m_sensor_hals.begin(); sensor_hal_it != m_sensor_hals.end(); ++sensor_hal_it) {
- sensor_hal = sensor_hal_it->second;
-
- // need to dlclose
- //unregister_module(module);
-
- delete sensor_hal;
- }
-
- m_sensors.clear();
- m_sensor_hals.clear();
-
- return true;
-}
-
#define _SENSOR_PLUGIN_LOADER_CLASS_H_
#include <sensor_common.h>
+#include <sensor_hal.h>
#include <cmutex.h>
#include <sstream>
#include <vector>
#include <map>
#include <set>
-
+#include <memory>
class sensor_hal;
class sensor_base;
-using std::pair;
-using std::vector;
-using std::multimap;
-using std::set;
-using std::string;
-using std::istringstream;
-
-typedef multimap<sensor_type_t, sensor_hal*> sensor_hal_plugins;
+typedef std::multimap<sensor_hal_type_t, std::shared_ptr<sensor_hal> > sensor_hal_plugins;
/*
* a hal_plugins is a group of hal plugin
* <HAL>
*
*/
-typedef multimap<sensor_type_t, sensor_base*> sensor_plugins;
+typedef std::multimap<sensor_type_t, std::shared_ptr<sensor_base> > sensor_plugins;
/*
* a sensor_plugins is a group of sensor plugin
* <SENSOR>
sensor_plugin_loader();
- bool load_module(const string &path, vector<void*> &sensors, void* &handle);
- bool insert_module(plugin_type type, const string &path);
+ bool load_module(const std::string &path, std::vector<void*> &sensors, void* &handle);
+ bool insert_module(plugin_type type, const std::string &path);
void show_sensor_info(void);
- bool get_paths_from_dir(const string &dir_path, vector<string> &hal_paths, vector<string> &sensor_paths);
- bool get_paths_from_config(const string &config_path, vector<string> &hal_paths, vector<string> &sensor_paths);
+ bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &hal_paths, std::vector<std::string> &sensor_paths);
+ bool get_paths_from_config(const std::string &config_path, std::vector<std::string> &hal_paths, std::vector<std::string> &sensor_paths);
sensor_hal_plugins m_sensor_hals;
sensor_plugins m_sensors;
static sensor_plugin_loader& get_instance();
bool load_plugins(void);
- sensor_hal* get_sensor_hal(sensor_type_t type);
- vector<sensor_hal *> get_sensor_hals(sensor_type_t type);
+ sensor_hal* get_sensor_hal(sensor_hal_type_t type);
+ std::vector<sensor_hal *> get_sensor_hals(sensor_hal_type_t type);
sensor_base* get_sensor(sensor_type_t type);
- vector<sensor_base *> get_sensors(sensor_type_t type);
+ std::vector<sensor_base *> get_sensors(sensor_type_t type);
sensor_base* get_sensor(sensor_id_t id);
- vector<sensor_base*> get_virtual_sensors(void);
-
- bool destroy();
+ std::vector<sensor_base*> get_virtual_sensors(void);
};
#endif /* _SENSOR_PLUGIN_LOADER_CLASS_H_ */
*
*/
+#include <common.h>
+
#if !defined(_SF_COMMON_H_)
#define _SF_COMMON_H_
#include <unistd.h>
#include <string>
#include <vector>
-#define COMMAND_CHANNEL_PATH "/tmp/sf_command_socket"
-#define EVENT_CHANNEL_PATH "/tmp/sf_event_socket"
+#define COMMAND_CHANNEL_PATH "/tmp/sensord_command_socket"
+#define EVENT_CHANNEL_PATH "/tmp/sensord_event_socket"
-#define MAX_HANDLE 64
+#define MAX_HANDLE 256
#define MAX_HANDLE_REACHED -2
#define CLIENT_ID_INVALID -1
+#define SENSOR_TYPE_MASK 0xFFFF
+
enum packet_type_t {
CMD_NONE = 0,
CMD_GET_ID,
CMD_REG,
CMD_UNREG,
CMD_SET_OPTION,
- CMD_SET_INTERVAL,
- CMD_UNSET_INTERVAL,
+ CMD_SET_BATCH,
+ CMD_UNSET_BATCH,
CMD_SET_COMMAND,
CMD_GET_DATA,
CMD_SEND_SENSORHUB_DATA,
};
typedef struct {
- pid_t pid;
+ char name[NAME_MAX];
} cmd_get_id_t;
typedef struct {
typedef struct {
unsigned int interval;
-} cmd_set_interval_t;
+ unsigned int latency;
+} cmd_set_batch_t;
typedef struct {
-} cmd_unset_interval_t;
+} cmd_unset_batch_t;
typedef struct {
int option;
virtual_sensor();
virtual ~virtual_sensor();
- virtual void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs) = 0;
+ virtual void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs) = 0;
virtual int get_sensor_data(const unsigned int event_type, sensor_data_t &data) = 0;
bool is_virtual(void);
bool m_hardware_fusion;
#include <mutex>
#include <condition_variable>
-using std::mutex;
-using std::lock_guard;
-using std::unique_lock;
-using std::condition_variable;
-
class worker_thread
{
public:
TRANS_FUNC_CNT,
};
- typedef lock_guard<mutex> lock;
- typedef unique_lock<mutex> ulock;
+ typedef std::lock_guard<std::mutex> lock;
+ typedef std::unique_lock<std::mutex> ulock;
worker_state_t m_state;
void *m_context;
- mutex m_mutex;
- condition_variable m_cond_working;
+ std::mutex m_mutex;
+ std::condition_variable m_cond_working;
bool m_thread_created;
trans_func_t m_trans_func[TRANS_FUNC_CNT];
#include <temperature_sensor.h>
#include <sensor_plugin_loader.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "TEMPERATURE_SENSOR"
temperature_sensor::temperature_sensor()
bool temperature_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(TEMPERATURE_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_TEMPERATURE);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t temperature_sensor::get_type(void)
+void temperature_sensor::get_types(vector<sensor_type_t> &types)
{
- return TEMPERATURE_SENSOR;
+ types.push_back(TEMPERATURE_SENSOR);
}
bool temperature_sensor::working(void *inst)
return stop_poll();
}
-bool temperature_sensor::get_properties(sensor_properties_s &properties)
+bool temperature_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~temperature_sensor();
bool init();
- sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
int get_sensor_data(unsigned int type, sensor_data_t &data);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_hal *m_sensor_hal;
#include <temperature_sensor_hal.h>
#include <sys/ioctl.h>
+using std::string;
+
#define SENSOR_TYPE_TEMPERATURE "TEMPERATURE"
#define ELEMENT_NAME "NAME"
#define ELEMENT_VENDOR "VENDOR"
return m_model_id;
}
-sensor_type_t temperature_sensor_hal::get_type(void)
+sensor_hal_type_t temperature_sensor_hal::get_type(void)
{
- return TEMPERATURE_SENSOR;
+ return SENSOR_HAL_TYPE_TEMPERATURE;
}
bool temperature_sensor_hal::enable(void)
#define _TEMPERATURE_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class temperature_sensor_hal : public sensor_hal
{
public:
temperature_sensor_hal();
virtual ~temperature_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
unsigned long m_polling_interval;
unsigned long long m_fired_time;
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
float m_raw_data_unit;
- string m_data_node;
- string m_enable_node;
- string m_interval_node;
+ std::string m_data_node;
+ std::string m_enable_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::string;
+using std::vector;
+
#define SENSOR_NAME "TILT_SENSOR"
#define SENSOR_TYPE_TILT "TILT"
return true;
}
-sensor_type_t tilt_sensor::get_type(void)
+void tilt_sensor::get_types(vector<sensor_type_t> &types)
{
- return TILT_SENSOR;
+ types.push_back(TILT_SENSOR);
}
bool tilt_sensor::on_start(void)
return 0;
}
-bool tilt_sensor::get_properties(sensor_properties_s &properties)
+bool tilt_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
if(m_raw_data_unit == "DEGREES") {
properties.min_range = -180;
virtual ~tilt_sensor();
bool init(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
- void synthesize(const sensor_event_t &event, vector<sensor_event_t> &outs);
+ void synthesize(const sensor_event_t &event, std::vector<sensor_event_t> &outs);
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
-
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
private:
sensor_base *m_accel_sensor;
sensor_base *m_fusion_sensor;
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
int m_pitch_rotation_compensation;
int m_roll_rotation_compensation;
using std::bind1st;
using std::mem_fun;
+using std::string;
+using std::vector;
#define SENSOR_NAME "ULTRAVIOLET_SENSOR"
bool ultraviolet_sensor::init()
{
- m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(ULTRAVIOLET_SENSOR);
+ m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ULTRAVIOLET);
if (!m_sensor_hal) {
ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
return true;
}
-sensor_type_t ultraviolet_sensor::get_type(void)
+void ultraviolet_sensor::get_types(vector<sensor_type_t> &types)
{
- return ULTRAVIOLET_SENSOR;
+ types.push_back(ULTRAVIOLET_SENSOR);
}
bool ultraviolet_sensor::working(void *inst)
return stop_poll();
}
-bool ultraviolet_sensor::get_properties(sensor_properties_s &properties)
+bool ultraviolet_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
return m_sensor_hal->get_properties(properties);
}
virtual ~ultraviolet_sensor();
bool init();
- virtual sensor_type_t get_type(void);
+ virtual void get_types(std::vector<sensor_type_t> &types);
static bool working(void *inst);
virtual bool set_interval(unsigned long interval);
- virtual bool get_properties(sensor_properties_s &properties);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
private:
sensor_hal *m_sensor_hal;
#include <fstream>
using std::ifstream;
+using std::string;
#define SENSOR_TYPE_ULTRAVIOLET "ULTRAVIOLET"
#define ELEMENT_NAME "NAME"
}
-sensor_type_t ultraviolet_sensor_hal::get_type(void)
+sensor_hal_type_t ultraviolet_sensor_hal::get_type(void)
{
- return ULTRAVIOLET_SENSOR;
+ return SENSOR_HAL_TYPE_ULTRAVIOLET;
}
bool ultraviolet_sensor_hal::enable(void)
#define _ULTRAVIOLET_SENSOR_HAL_H_
#include <sensor_hal.h>
-#include <string>
-
-using std::string;
class ultraviolet_sensor_hal : public sensor_hal
{
public:
ultraviolet_sensor_hal();
virtual ~ultraviolet_sensor_hal();
- string get_model_id(void);
- sensor_type_t get_type(void);
+ std::string get_model_id(void);
+ sensor_hal_type_t get_type(void);
bool enable(void);
bool disable(void);
bool set_interval(unsigned long val);
bool get_properties(sensor_properties_s &properties);
private:
- string m_model_id;
- string m_vendor;
- string m_chip_name;
+ std::string m_model_id;
+ std::string m_vendor;
+ std::string m_chip_name;
float m_min_range;
float m_max_range;
unsigned long long m_fired_time;
int m_node_handle;
- string m_enable_node;
- string m_data_node;
- string m_interval_node;
+ std::string m_enable_node;
+ std::string m_data_node;
+ std::string m_interval_node;
bool m_sensorhub_controlled;
#include <orientation_filter.h>
#include <cvirtual_sensor_config.h>
+using std::vector;
+using std::string;
+
#define SENSOR_NAME "UNCAL_GYROSCOPE_SENSOR"
#define SENSOR_TYPE_UNCAL_GYRO "UNCAL_GYROSCOPE"
{
cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
- sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);
+ sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);
if (!fusion_sensor_hal)
m_hardware_fusion = false;
else
return true;
}
-sensor_type_t uncal_gyro_sensor::get_type(void)
+void uncal_gyro_sensor::get_types(vector<sensor_type_t> &types)
{
- return UNCAL_GYROSCOPE_SENSOR;
+ types.push_back(UNCAL_GYROSCOPE_SENSOR);
}
bool uncal_gyro_sensor::on_start(void)
return 0;
}
-bool uncal_gyro_sensor::get_properties(sensor_properties_s &properties)
+bool uncal_gyro_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
{
properties.resolution = 0.000001;
properties.vendor = m_vendor;
bool add_interval(int client_id, unsigned int interval);
bool delete_interval(int client_id);
- bool get_properties(sensor_properties_s &properties);
- sensor_type_t get_type(void);
+ virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
+ virtual void get_types(std::vector<sensor_type_t> &types);
int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
unsigned long long m_time;
unsigned int m_interval;
- string m_vendor;
- string m_raw_data_unit;
+ std::string m_vendor;
+ std::string m_raw_data_unit;
int m_default_sampling_time;
float m_gyro_static_bias[3];
int m_gyro_rotation_direction_compensation[3];
Description=Sensor daemon socket
[Socket]
-ListenStream=/tmp/sf_command_socket
+ListenStream=/tmp/sensord_command_socket
SocketMode=0777
PassCredentials=yes
Accept=false
sensor_t *output_list;
result_boolean = sensord_get_sensor_list(sensor_type, &output_list, &output);
if (!result_boolean) {
+ free(output2);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_sensor_list\n", sensor_type, event_type);
return false;
}
result = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL);
if (result < 0) {
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type);
return false;
}
if (!result_boolean) {
sensord_unregister_event(handle, event_type);
sensord_disconnect(handle);
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_start\n", sensor_type, event_type);
return false;
}
if (!result_boolean) {
sensord_unregister_event(handle, event_type);
sensord_disconnect(handle);
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_data\n", sensor_type, event_type);
return false;
}
result_boolean = sensord_change_event_interval(handle, event_type, 101);
if (!result_boolean) {
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_event_interval\n", sensor_type, event_type);
return false;
}
result_boolean = sensord_set_option(handle, SENSOR_OPTION_ON_IN_SCREEN_OFF);
if (!result_boolean){
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_sensor_option\n", sensor_type, event_type);
return false;
}
result_boolean = sensord_unregister_event(handle, event_type);
if (!result_boolean) {
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_unregister_event\n", sensor_type, event_type);
return false;
}
result_boolean = sensord_stop(handle);
if (!result_boolean) {
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_stop\n", sensor_type, event_type);
return false;
}
result_boolean = sensord_disconnect(handle);
if (!result_boolean) {
+ free(output2);
+ free(output_list);
fprintf(fp, "Sensor - %d, event - %d, failed at sensord_disconnect\n", sensor_type, event_type);
return false;
}
+ free(output2);
+ free(output_list);
+
return true;
}
return UNCAL_GYRO_RAW_DATA_EVENT;
break;
+ default:
+ return -1;
}
return -1;
}
int i;
int handle[MAXSIZE];
- int result[MAXSIZE], start_handle[MAXSIZE], stop_handle[MAXSIZE];
+ int result[MAXSIZE], start_handle[MAXSIZE];
unsigned int event[MAXSIZE];
int sensors[MAXSIZE];
for (j = 0; j < MAX; j++) {
char command[100];
sprintf(command, "kill %d", pids[j]);
- system(command);
+ if (system(command) == -1)
+ return -1;
}
}
}
else {
usage();
+ return -1;
}
interval = DEFAULT_EVENT_INTERVAL;