retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count,
false, "Invalid param: sensor (%p), event_types(%p), count(%)", sensor, event_types, count);
- vector<unsigned int> event_vec;
-
- info->get_supported_events(event_vec);
- *event_types = (unsigned int *) malloc(sizeof(unsigned int) * event_vec.size());
+ unsigned int event_type;
+ event_type = info->get_supported_event();
+ *event_types = (unsigned int *) malloc(sizeof(unsigned int));
retvm_if(!*event_types, false, "Failed to allocate memory");
- copy(event_vec.begin(), event_vec.end(), *event_types);
- *count = event_vec.size();
+ (*event_types)[0] = event_type;
+ *count = 1;
return true;
}
auto it_sensor = sensors.begin();
while (it_sensor != last) {
+ (*it_sensor)->get_sensor_info(info);
+ permission = (*it_sensor)->get_permission();
- 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;
}
}
bool command_worker::stopped(void *ctx)
{
string info;
- event_type_vector event_vec;
command_worker *inst = (command_worker *)ctx;
inst->get_info(info);
if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
- get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_sensor_id, event_vec);
-
- auto it_event = event_vec.begin();
-
- while (it_event != event_vec.end()) {
- WARN("Does not unregister event[0x%x] before connection broken for [%s]!!", *it_event, inst->m_module->get_name());
- if (!inst->m_module->delete_client(*it_event))
- ERR("Unregistering event[0x%x] failed", *it_event);
-
- ++it_event;
- }
-
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);
}
insert_priority_list(cmd->event_type);
- m_module->add_client(cmd->event_type);
ret_value = OP_SUCCESS;
DBG("Registering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id);
goto out;
}
- if (!m_module->delete_client(cmd->event_type)) {
- ERR("Failed to unregister event [0x%x] for client [%d]",
- cmd->event_type, m_client_id);
- ret_value = OP_ERROR;
- goto out;
- }
-
ret_value = OP_SUCCESS;
DBG("Unregistering Event [0x%x] is done for client [%d]",
cmd->event_type, m_client_id);
bool command_worker::cmd_get_data(void *payload)
{
const unsigned int GET_DATA_MIN_INTERVAL = 10;
- cmd_get_data_t *cmd;
int state = OP_ERROR;
bool adjusted = false;
DBG("CMD_GET_VALUE Handler invoked\n");
- cmd = (cmd_get_data_t*)payload;
-
if (!is_permission_allowed()) {
ERR("Permission denied to get data for client [%d], for sensor [0x%x]",
m_client_id, m_sensor_id);
goto out;
}
- state = m_module->get_sensor_data(cmd->type, data);
+ state = m_module->get_sensor_data(data);
// In case of not getting sensor data, wait short time and retry again
// 1. changing interval to be less than 10ms
while (!state && !data.timestamp && (retry++ < RETRY_CNT)) {
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);
+ state = m_module->get_sensor_data(data);
}
if (adjusted)
return event.first;
}
+void csensor_event_queue::push(sensor_event_t *event, int event_length)
+{
+ push_internal(event, event_length);
+}
void push_internal(void *event, int length);
public:
static csensor_event_queue& get_instance();
- template<typename T> void push(const T &event);
- template<typename T> void push(T *event);
+
+ void push(sensor_event_t *event, int event_length);
void* pop(int *length);
};
-template<typename T>
-void csensor_event_queue::push(const T &event)
-{
- void *new_event = malloc(sizeof(event));
- if (!new_event)
- return;
- memcpy(new_event, &event, sizeof(event));
- push_internal(new_event, sizeof(event));
-}
-
-template<typename T>
-void csensor_event_queue::push(T *event)
-{
- push_internal(event, sizeof(event));
-}
#endif
#include <physical_sensor.h>
#include <csensor_event_queue.h>
+#define UNKNOWN_NAME "UNKNOWN_SENSOR"
physical_sensor::physical_sensor()
+: m_sensor_hal(NULL)
{
}
}
-bool physical_sensor::push(const sensor_event_t &event)
+sensor_type_t physical_sensor::get_type(void)
{
- csensor_event_queue::get_instance().push(event);
- return true;
+ return static_cast<sensor_type_t>(m_handle.type);
}
-bool physical_sensor::push(sensor_event_t *event)
+unsigned int physical_sensor::get_event_type(void)
{
- csensor_event_queue::get_instance().push(event);
- return true;
+ return m_handle.event_type;
}
-bool physical_sensor::push(const sensorhub_event_t &event)
+const char* physical_sensor::get_name()
{
- csensor_event_queue::get_instance().push(event);
- return true;
+ if (m_handle.name.empty())
+ return UNKNOWN_NAME;
+
+ return m_handle.name.c_str();
+}
+
+void physical_sensor::set_sensor_handle(sensor_handle_t handle)
+{
+ m_handle.id = handle.id;
+ m_handle.name = handle.name;
+ m_handle.type = handle.type;
+ m_handle.event_type = handle.event_type;
+}
+
+void physical_sensor::set_sensor_hal(sensor_hal *hal)
+{
+ m_sensor_hal = hal;
+}
+
+int physical_sensor::get_poll_fd()
+{
+ AUTOLOCK(m_mutex);
+
+ if (!m_sensor_hal)
+ return -1;
+
+ return m_sensor_hal->get_poll_fd();
+}
+
+bool physical_sensor::on_start()
+{
+ AUTOLOCK(m_mutex);
+
+ return m_sensor_hal->enable(m_handle.id);
+}
+
+bool physical_sensor::on_stop()
+{
+ AUTOLOCK(m_mutex);
+
+ return m_sensor_hal->disable(m_handle.id);
+}
+
+long physical_sensor::set_command(unsigned int cmd, long value)
+{
+ AUTOLOCK(m_mutex);
+
+ return m_sensor_hal->set_command(m_handle.id, std::to_string(cmd), std::to_string(value));
}
-bool physical_sensor::push(sensorhub_event_t *event)
+bool physical_sensor::set_interval(unsigned long interval)
{
- csensor_event_queue::get_instance().push(event);
- return true;
+ AUTOLOCK(m_mutex);
+
+ INFO("Polling interval is set to %dms", interval);
+
+ return m_sensor_hal->set_interval(m_handle.id, interval);
}
-void physical_sensor::set_poller(working_func_t func, void *arg)
+bool physical_sensor::set_batch(unsigned long latency)
{
- m_sensor_data_poller.set_context(arg);
- m_sensor_data_poller.set_working(func);
+ AUTOLOCK(m_mutex);
+
+ INFO("Polling interval is set to %dms", latency);
+
+ return m_sensor_hal->set_batch_latency(m_handle.id, latency);
}
+bool physical_sensor::set_wakeup(int wakeup)
+{
+ return false;
+}
-bool physical_sensor::start_poll(void)
+bool physical_sensor::is_data_ready(void)
{
- return m_sensor_data_poller.start();
+ AUTOLOCK(m_mutex);
+ return m_sensor_hal->is_data_ready();
}
-bool physical_sensor::stop_poll(void)
+int physical_sensor::get_sensor_data(sensor_data_t &data)
{
- return m_sensor_data_poller.pause();
+ AUTOLOCK(m_mutex);
+
+ if (!m_sensor_hal->get_sensor_data(m_handle.id, data)) {
+ ERR("Failed to get sensor data");
+ return -1;
+ }
+
+ return 0;
}
+
+int physical_sensor::get_sensor_event(sensor_event_t **event)
+{
+ AUTOLOCK(m_mutex);
+
+ int event_length = -1;
+ event_length = m_sensor_hal->get_sensor_event(m_handle.id, event);
+
+ if (event_length < 0) {
+ ERR("Failed to get sensor event");
+ return -1;
+ }
+
+ return event_length;
+}
+
+bool physical_sensor::get_properties(sensor_properties_s &properties)
+{
+ return m_sensor_hal->get_properties(m_handle.id, properties);
+}
+
class physical_sensor : public sensor_base
{
public:
- typedef worker_thread::trans_func_t working_func_t;
-
-private:
- worker_thread m_sensor_data_poller;
-
-protected:
physical_sensor();
virtual ~physical_sensor();
- 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);
+ /* setting module */
+ void set_sensor_handle(sensor_handle_t handle);
+ void set_sensor_hal(sensor_hal *hal);
+
+ /* module info */
+ virtual sensor_type_t get_type();
+ virtual unsigned int get_event_type(void);
+ virtual const char* get_name(void);
- void set_poller(working_func_t func, void *arg);
- bool start_poll(void);
- bool stop_poll(void);
+ int get_poll_fd();
+
+ /* get data */
+ bool is_data_ready(void);
+ virtual int get_sensor_data(sensor_data_t &data);
+ virtual int get_sensor_event(sensor_event_t **event);
+
+private:
+ sensor_handle_t m_handle;
+ sensor_hal *m_sensor_hal;
+
+ virtual bool set_interval(unsigned long interval);
+ virtual bool set_wakeup(int wakeup);
+ virtual bool set_batch(unsigned long latency);
+ virtual bool on_start();
+ virtual bool on_stop();
+ virtual long set_command(unsigned int cmd, long value);
+ virtual bool get_properties(sensor_properties_s &properties);
};
#endif
*
*/
+#include <sensor_hal.h>
#include <sensor_base.h>
#include <algorithm>
#include <utility>
+#include <functional>
+#include <csensor_event_queue.h>
+
using std::make_pair;
using std::vector;
-#define UNKNOWN_NAME "UNKNOWN_SENSOR"
-
sensor_base::sensor_base()
-: m_privilege(SENSOR_PRIVILEGE_PUBLIC)
+: m_unique_id(-1)
+, m_privilege(SENSOR_PRIVILEGE_PUBLIC)
, m_permission(SENSOR_PERMISSION_STANDARD)
, m_client(0)
, m_started(false)
{
-
}
sensor_base::~sensor_base()
{
-
+ INFO("%s is destroyed!\n", m_handle.name.c_str());
}
-bool sensor_base::init()
-{
- return true;
-}
-
-bool sensor_base::is_virtual()
-{
- return false;
-}
-
-void sensor_base::add_id(sensor_id_t 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)
+sensor_type_t sensor_base::get_type(void)
{
- 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)
-{
- return m_privilege;
-}
-
-int sensor_base::get_permission(void)
-{
- return m_permission;
-}
-
-
-void sensor_base::set_privilege(sensor_privilege_t privilege)
-{
- m_privilege = privilege;
-}
-
-void sensor_base::set_permission(int permission)
-{
- m_permission = permission;
-}
-
-const char* sensor_base::get_name()
-{
- if (m_name.empty())
- return UNKNOWN_NAME;
-
- return m_name.c_str();
-}
-
-bool sensor_base::on_start()
-{
- return true;
-}
-
-bool sensor_base::on_stop()
-{
- return true;
-}
-
bool sensor_base::start()
{
AUTOLOCK(m_mutex);
return true;
}
-
-bool sensor_base::is_started(void)
+bool sensor_base::on_start()
{
- AUTOLOCK(m_mutex);
- AUTOLOCK(m_client_mutex);
-
- return m_started;
+ return false;
}
-bool sensor_base::add_client(unsigned int event_type)
+bool sensor_base::on_stop()
{
- if (!is_supported(event_type)) {
- ERR("Invaild event type: 0x%x", event_type);
- return false;
- }
-
- AUTOLOCK(m_client_info_mutex);
-
- ++(m_client_info[event_type]);
- return true;
+ return false;
}
-bool sensor_base::delete_client(unsigned int event_type)
+long sensor_base::set_command(unsigned int cmd, long value)
{
- if (!is_supported(event_type)) {
- ERR("Invaild event type: 0x%x", event_type);
- return false;
- }
-
- AUTOLOCK(m_client_info_mutex);
-
- auto iter = m_client_info.find(event_type);
-
- if (iter == m_client_info.end())
- return false;
-
- if (iter->second == 0)
- return false;
-
- --(iter->second);
-
- return true;
+ return -1;
}
bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_processor)
" by%sclient[%d] adding interval",
get_id(), prev_min, cur_min,
is_processor ? " processor " : " ", client_id);
+
set_interval(cur_min);
}
return m_plugin_info_list.get_interval(client_id, is_processor);
}
+bool sensor_base::add_batch(int client_id, unsigned int latency)
+{
+ unsigned int prev_max, cur_max;
+
+ AUTOLOCK(m_plugin_info_list_mutex);
+
+ prev_max = m_plugin_info_list.get_max_batch();
+
+ if (!m_plugin_info_list.add_batch(client_id, latency))
+ return false;
+
+ cur_max = m_plugin_info_list.get_max_batch();
+
+ if (cur_max != prev_max) {
+ INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency",
+ get_id(), prev_max, cur_max, client_id);
+ set_batch(cur_max);
+ }
+
+ return true;
+}
+
+bool sensor_base::delete_batch(int client_id)
+{
+ unsigned int prev_max, cur_max;
+ AUTOLOCK(m_plugin_info_list_mutex);
+
+ prev_max = m_plugin_info_list.get_max_batch();
+
+ if (!m_plugin_info_list.delete_batch(client_id))
+ return false;
+
+ cur_max = m_plugin_info_list.get_max_batch();
+
+ if (!cur_max) {
+ INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms",
+ get_id(), client_id);
+
+ set_batch(0);
+ } else if (cur_max != prev_max) {
+ INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency",
+ get_id(), prev_max, cur_max, client_id);
+
+ set_batch(cur_max);
+ }
+
+ return true;
+}
+
+unsigned int sensor_base::get_batch(int client_id)
+{
+ AUTOLOCK(m_plugin_info_list_mutex);
+
+ return m_plugin_info_list.get_batch(client_id);
+}
+
bool sensor_base::add_wakeup(int client_id, int wakeup)
{
int prev_wakeup, cur_wakeup;
if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) {
INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] adding wakeup",
get_id(), prev_wakeup, cur_wakeup, client_id);
- set_wakeup(client_id, SENSOR_WAKEUP_ON);
+ set_wakeup(SENSOR_WAKEUP_ON);
}
return true;
if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) {
INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] deleting wakeup",
get_id(), prev_wakeup, cur_wakeup, client_id);
- set_wakeup(client_id, SENSOR_WAKEUP_OFF);
+ set_wakeup(SENSOR_WAKEUP_OFF);
}
return true;
return m_plugin_info_list.is_wakeup_on();
}
-bool sensor_base::add_batch(int client_id, unsigned int latency)
+int sensor_base::get_sensor_data(sensor_data_t &data)
{
- unsigned int prev_max, cur_max;
-
- AUTOLOCK(m_plugin_info_list_mutex);
-
- prev_max = m_plugin_info_list.get_max_batch();
-
- if (!m_plugin_info_list.add_batch(client_id, latency))
- return false;
+ return -1;
+}
- cur_max = m_plugin_info_list.get_max_batch();
+int sensor_base::get_sensor_event(sensor_event_t **event)
+{
+ return -1;
+}
- if (cur_max != prev_max) {
- INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency",
- get_id(), prev_max, cur_max, client_id);
- set_batch(client_id, cur_max);
- }
+bool sensor_base::get_properties(sensor_properties_s &properties)
+{
+ return false;
+}
- return true;
+const char* sensor_base::get_name()
+{
+ return NULL;
}
-bool sensor_base::delete_batch(int client_id)
+void sensor_base::set_id(sensor_id_t id)
{
- unsigned int prev_max, cur_max;
- AUTOLOCK(m_plugin_info_list_mutex);
+ m_unique_id = id;
+}
- prev_max = m_plugin_info_list.get_max_batch();
+sensor_id_t sensor_base::get_id(void)
+{
+ if (m_unique_id == -1)
+ return UNKNOWN_SENSOR;
- if (!m_plugin_info_list.delete_batch(client_id))
- return false;
+ return m_unique_id;
+}
- cur_max = m_plugin_info_list.get_max_batch();
+unsigned int sensor_base::get_event_type(void)
+{
+ return -1;
+}
- if (!cur_max) {
- INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms",
- get_id(), client_id);
+sensor_privilege_t sensor_base::get_privilege(void)
+{
+ return m_privilege;
+}
- set_batch(client_id, 0);
- } else if (cur_max != prev_max) {
- INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency",
- get_id(), prev_max, cur_max, client_id);
+int sensor_base::get_permission(void)
+{
+ return m_permission;
+}
- set_batch(client_id, cur_max);
- }
+bool sensor_base::is_started(void)
+{
+ AUTOLOCK(m_mutex);
+ AUTOLOCK(m_client_mutex);
- return true;
+ return m_started;
}
-unsigned int sensor_base::get_batch(int client_id)
+bool sensor_base::is_virtual()
{
- AUTOLOCK(m_plugin_info_list_mutex);
-
- return m_plugin_info_list.get_batch(client_id);
+ return false;
}
-void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info)
+void sensor_base::get_sensor_info(sensor_info &info)
{
sensor_properties_s properties;
properties.wakeup_supported = false;
- get_properties(sensor_type, properties);
+ get_properties(properties);
- info.set_type(sensor_type);
- info.set_id(get_id(sensor_type));
+ info.set_type(get_type());
+ info.set_id(get_id());
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);
-
- 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);
+ info.set_supported_event(get_event_type());
info.set_wakeup_supported(properties.wakeup_supported);
return;
}
-bool sensor_base::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties)
+bool sensor_base::is_wakeup_supported(void)
{
return false;
}
-bool sensor_base::is_supported(unsigned int event_type)
+bool sensor_base::set_interval(unsigned long interval)
{
- auto iter = find(m_supported_event_info.begin(), m_supported_event_info.end(), event_type);
-
- if (iter == m_supported_event_info.end())
- return false;
-
- return true;
+ return false;
}
-bool sensor_base::is_wakeup_supported(void)
+bool sensor_base::set_wakeup(int wakeup)
{
return false;
}
-long sensor_base::set_command(unsigned int cmd, long value)
+bool sensor_base::set_batch(unsigned long latency)
{
- return -1;
+ return false;
}
-bool sensor_base::set_wakeup(int client_id, int wakeup)
+void sensor_base::set_privilege(sensor_privilege_t privilege)
{
- return false;
+ m_privilege = privilege;
}
-bool sensor_base::set_batch(int client_id, unsigned int latency)
+void sensor_base::set_permission(int permission)
{
- return false;
+ m_permission = permission;
}
int sensor_base::send_sensorhub_data(const char* data, int data_len)
return -1;
}
-int sensor_base::get_sensor_data(unsigned int type, sensor_data_t &data)
+bool sensor_base::push(sensor_event_t *event, int event_length)
{
- return -1;
+ AUTOLOCK(m_client_mutex);
+
+ if (m_client <= 0)
+ return false;
+
+ csensor_event_queue::get_instance().push(event, event_length);
+ return true;
}
-void sensor_base::register_supported_event(unsigned int event_type)
+/*
+bool sensor_base::push(const sensor_event_t &event)
{
- m_supported_event_info.push_back(event_type);
+ AUTOLOCK(m_client_mutex);
+
+ if (m_client <= 0)
+ return false;
+
+ csensor_event_queue::get_instance().push(event);
+ return true;
}
-void sensor_base::unregister_supported_event(unsigned int event_type)
+bool sensor_base::push(sensor_event_t *event)
{
- m_supported_event_info.erase(std::remove(m_supported_event_info.begin(),
- m_supported_event_info.end(), event_type), m_supported_event_info.end());
+ AUTOLOCK(m_client_mutex);
+
+ if (m_client <= 0)
+ return false;
+
+ csensor_event_queue::get_instance().push(event);
+ return true;
}
-unsigned int sensor_base::get_client_cnt(unsigned int event_type)
-{
- AUTOLOCK(m_client_info_mutex);
- auto iter = m_client_info.find(event_type);
+bool sensor_base::push(const sensorhub_event_t &event)
+{
+ AUTOLOCK(m_client_mutex);
- if (iter == m_client_info.end())
- return 0;
+ if (m_client <= 0)
+ return false;
- return iter->second;
+ csensor_event_queue::get_instance().push(event);
+ return true;
}
-bool sensor_base::set_interval(unsigned long val)
+bool sensor_base::push(sensorhub_event_t *event)
{
+ AUTOLOCK(m_client_mutex);
+
+ if (m_client <= 0)
+ return false;
+
+ csensor_event_queue::get_instance().push(event);
return true;
}
+*/
unsigned long long sensor_base::get_timestamp(void)
{
return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
}
+
#include <sensor_common.h>
#include <worker_thread.h>
#include <sensor_info.h>
+#include <sensor_hal.h>
class sensor_base
{
-private:
- typedef std::unordered_map<unsigned int, unsigned int> client_info;
-
public:
sensor_base();
virtual ~sensor_base();
- virtual bool init(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);
+ /* module info */
+ virtual sensor_type_t get_type();
+ virtual unsigned int get_event_type(void);
virtual const char* get_name(void);
- virtual bool is_virtual(void);
+ /* start/stop */
bool start(void);
bool stop(void);
- bool is_started(void);
-
- virtual bool add_client(unsigned int event_type);
- virtual bool delete_client(unsigned int event_type);
- virtual bool add_interval(int client_id, unsigned int interval, bool is_processor);
- virtual bool delete_interval(int client_id, bool is_processor);
+ /* interval / batch / wakeup */
+ bool add_interval(int client_id, unsigned int interval, bool is_processor);
+ bool delete_interval(int client_id, bool is_processor);
unsigned int get_interval(int client_id, bool is_processor);
- virtual bool add_wakeup(int client_id, int wakeup);
- virtual bool delete_wakeup(int client_id);
+ bool add_batch(int client_id, unsigned int latency);
+ bool delete_batch(int client_id);
+ unsigned int get_batch(int client_id);
+
+ bool add_wakeup(int client_id, int wakeup);
+ bool delete_wakeup(int client_id);
int get_wakeup(int client_id);
+ bool is_wakeup_supported(void);
- virtual bool add_batch(int client_id, unsigned int latency);
- virtual bool delete_batch(int client_id);
- unsigned int get_batch(int client_id);
+ /* get data */
+ virtual int get_sensor_data(sensor_data_t &data);
+ virtual int get_sensor_event(sensor_event_t **event);
- 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);
+ /* id */
+ void set_id(sensor_id_t id);
+ sensor_id_t get_id(void);
- bool is_supported(unsigned int event_type);
- bool is_wakeup_supported(void);
+ /* privilege */
+ sensor_privilege_t get_privilege(void);
+ int get_permission(void);
- virtual long set_command(unsigned int cmd, long value);
- virtual bool set_wakeup(int client_id, int wakeup);
- virtual bool set_batch(int client_id, unsigned int latency);
- virtual int send_sensorhub_data(const char* data, int data_len);
+ bool is_started(void);
+ virtual bool is_virtual(void);
+
+ /* sensor info */
+ virtual void get_sensor_info(sensor_info &info);
- virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
+ /* push event to queue */
+ bool push(sensor_event_t *event, int event_length);
+ /*
+ 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 register_supported_event(unsigned int event_type);
- void unregister_supported_event(unsigned int event_type);
+ /* for sensorhub */
+ virtual long set_command(unsigned int cmd, long value);
+ virtual int send_sensorhub_data(const char* data, int data_len);
protected:
- typedef std::lock_guard<std::mutex> lock;
- typedef std::lock_guard<std::recursive_mutex> rlock;
- typedef std::unique_lock<std::mutex> ulock;
+ cmutex m_mutex;
+
+ void set_privilege(sensor_privilege_t privilege);
+ void set_permission(int permission);
- std::map<sensor_type_t, sensor_id_t> m_ids;
+private:
+ sensor_id_t m_unique_id;
+ sensor_handle_t m_handle;
sensor_privilege_t m_privilege;
+
int m_permission;
cplugin_info_list m_plugin_info_list;
cmutex m_plugin_info_list_mutex;
- cmutex m_mutex;
-
unsigned int m_client;
cmutex m_client_mutex;
- client_info m_client_info;
- cmutex m_client_info_mutex;
-
- std::vector<unsigned int> m_supported_event_info;
bool m_started;
- std::string m_name;
+ virtual bool set_interval(unsigned long interval);
+ virtual bool set_batch(unsigned long latency);
+ virtual bool set_wakeup(int wakeup);
- 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);
- virtual bool set_interval(unsigned long val);
+ /* get properties */
+ virtual bool get_properties(sensor_properties_s &properties);
- static unsigned long long get_timestamp(void);
- static unsigned long long get_timestamp(timeval *t);
-private:
virtual bool on_start(void);
virtual bool on_stop(void);
+
+ static unsigned long long get_timestamp(void);
+ static unsigned long long get_timestamp(timeval *t);
};
#endif
+++ /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 _SENSOR_HAL_H_
-#define _SENSOR_HAL_H_
-
-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;
-
-
-
-class sensor_hal
-{
-public:
- sensor_hal(){};
- virtual ~sensor_hal(){};
-
- 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 is_data_ready(void) = 0;
- virtual bool set_interval(unsigned long val) = 0;
- virtual int get_sensor_data(sensor_data_t &data) = 0;
- virtual bool get_properties(sensor_properties_s &properties) = 0;
-};
-#endif /*_SENSOR_HAL_H_*/
#include <libxml/parser.h>
#include <sensor_hal.h>
#include <sensor_base.h>
+#include <physical_sensor.h>
#include <dlfcn.h>
#include <dirent.h>
#include <sensor_logs.h>
#include <unordered_set>
#include <algorithm>
-/*
#ifdef ENABLE_AUTO_ROTATION
#include <auto_rotation_sensor.h>
#endif
+/*
#ifdef ENABLE_TILT
#include <tilt_sensor.h>
#endif
#endif
*/
-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"
#define HAL_ELEMENT "HAL"
#define SENSOR_ELEMENT "SENSOR"
-#define ACCELEROMETER_ENABLED 0x01
-#define GYROSCOPE_ENABLED 0x02
-#define GEOMAGNETIC_ENABLED 0x04
-#define TILT_ENABLED 1
-#define FUSION_ENABLED 1
-#define AUTO_ROTATION_ENABLED 1
-#define GAMING_RV_ENABLED 3
-#define GEOMAGNETIC_RV_ENABLED 5
-#define ORIENTATION_ENABLED 7
-#define GRAVITY_ENABLED 7
-#define LINEAR_ACCEL_ENABLED 7
-#define ORIENTATION_ENABLED 7
-
#define HAL_PLUGINS_DIR_PATH "/usr/lib/sensor"
#define SENSOR_INDEX_SHIFT 16
return inst;
}
-bool sensor_plugin_loader::load_module(const string &path, vector<void*> &sensors, void* &handle)
+bool sensor_plugin_loader::load_plugin(const string &path, vector<void*> &sensors, void* &handle)
{
+ INFO("load HAL plugin [%s]", path.c_str());
+
void *_handle = dlopen(path.c_str(), RTLD_NOW);
if (!_handle) {
dlerror();
- create_t create_module = (create_t) dlsym(_handle, "create");
+ create_t create_plugin = (create_t) dlsym(_handle, "create");
- if (!create_module) {
+ if (!create_plugin) {
ERR("Failed to find symbols in %s", path.c_str());
dlclose(_handle);
return false;
}
- sensor_module *module = create_module();
+ sensor_module *plugin = create_plugin();
- if (!module) {
- ERR("Failed to create module, path is %s\n", path.c_str());
+ if (!plugin) {
+ ERR("Failed to create plugin, path is %s\n", path.c_str());
dlclose(_handle);
return false;
}
sensors.clear();
- sensors.swap(module->sensors);
+ sensors.swap(plugin->sensors);
- delete module;
+ delete plugin;
handle = _handle;
return true;
}
-bool sensor_plugin_loader::insert_module(plugin_type type, const string &path)
+bool sensor_plugin_loader::insert_plugins(std::vector<void *> hals)
{
- if (type == PLUGIN_TYPE_HAL) {
- DBG("Insert HAL plugin [%s]", path.c_str());
-
- std::vector<void *>hals;
- void *handle;
-
- if (!load_module(path, hals, handle))
- return false;
+ unsigned int i;
+ sensor_hal *hal;
- shared_ptr<sensor_hal> hal;
+ for (i = 0; i < hals.size(); ++i) {
+ hal = static_cast<sensor_hal *>(hals[i]);
- for (unsigned int i = 0; i < hals.size(); ++i) {
- 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());
-
- std::vector<void *> sensors;
- void *handle;
-
- if (!load_module(path, sensors, handle))
- return false;
+ insert_sensors(hal);
+ }
- shared_ptr<sensor_base> sensor;
+ return true;
+}
- for (unsigned int i = 0; i < sensors.size(); ++i) {
- sensor.reset(static_cast<sensor_base*> (sensors[i]));
+bool sensor_plugin_loader::insert_sensors(sensor_hal *hal)
+{
+ unsigned int i;
+ vector<sensor_handle_t> sensors;
+ physical_sensor *phy_sensor;
- if (!sensor->init()) {
- ERR("Failed to init [%s] module\n", sensor->get_name());
- continue;
- }
+ hal->get_sensors(sensors);
- DBG("init [%s] module", sensor->get_name());
+ for (i = 0; i < sensors.size(); ++i) {
+ int idx;
+ idx = m_sensors.count(sensors[i].type);
- vector<sensor_type_t> sensor_types;
+ phy_sensor = new physical_sensor();
+ phy_sensor->set_id(idx << SENSOR_INDEX_SHIFT | sensors[i].type);
+ phy_sensor->set_sensor_handle(sensors[i]);
+ phy_sensor->set_sensor_hal(hal);
- sensor->get_types(sensor_types);
+ std::shared_ptr<sensor_base> sensor(phy_sensor);
+ m_sensors.insert(std::make_pair(sensors[i].type, sensor));
- 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);
- return false;
+ INFO("created [%s] sensor", sensor->get_name());
}
return true;
vector<string> hal_paths;
vector<string> unique_hal_paths;
- int enable_virtual_sensor = 0;
- vector<void*> sensors;
-
get_paths_from_dir(string(HAL_PLUGINS_DIR_PATH), hal_paths);
unordered_set<string> s;
for_each(unique_hal_paths.begin(), unique_hal_paths.end(),
[&](const string &path) {
- insert_module(PLUGIN_TYPE_HAL, path);
+ void *handle;
+ std::vector<void *> hals;
+
+ load_plugin(path, hals, handle);
+ insert_plugins(hals);
}
);
-
-#ifdef ENABLE_SENSOR_FUSION
- fusion_sensor* fusion_sensor_ptr = NULL;
+#ifdef ENABLE_AUTO_ROTATION
+ auto_rotation_sensor* auto_rot_sensor_ptr = NULL;
try {
- fusion_sensor_ptr = new(std::nothrow) fusion_sensor;
+ auto_rot_sensor_ptr = new(std::nothrow) auto_rotation_sensor;
} catch (int err) {
- ERR("Failed to create fusion_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (fusion_sensor_ptr != NULL)
- sensors.push_back(fusion_sensor_ptr);
-#endif
-#ifdef ENABLE_TILT
- if (enable_virtual_sensor & TILT_ENABLED == TILT_ENABLED) {
- tilt_sensor* tilt_sensor_ptr = NULL;
- try {
- tilt_sensor_ptr = new(std::nothrow) tilt_sensor;
- } catch (int err) {
- ERR("Failed to create tilt_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (tilt_sensor_ptr != NULL)
- sensors.push_back(tilt_sensor_ptr);
+ ERR("Failed to create auto_rotation_sensor module, err: %d, cause: %s", err, strerror(err));
}
-#endif
-#ifdef ENABLE_AUTO_ROTATION
- if (enable_virtual_sensor & AUTO_ROTATION_ENABLED == AUTO_ROTATION_ENABLED) {
- auto_rotation_sensor* auto_rot_sensor_ptr = NULL;
- try {
- auto_rot_sensor_ptr = new(std::nothrow) auto_rotation_sensor;
- } catch (int err) {
- ERR("Failed to create auto_rotation_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (auto_rot_sensor_ptr != NULL)
- sensors.push_back(auto_rot_sensor_ptr);
- }
-#endif
-#ifdef ENABLE_GRAVITY
- if (enable_virtual_sensor & GRAVITY_ENABLED == GRAVITY_ENABLED) {
- gravity_sensor* gravity_sensor_ptr = NULL;
- try {
- gravity_sensor_ptr = new(std::nothrow) gravity_sensor;
- } catch (int err) {
- ERR("Failed to create tilt_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (gravity_sensor_ptr != NULL)
- sensors.push_back(gravity_sensor_ptr);
- }
-#endif
-#ifdef ENABLE_LINEAR_ACCEL
- if (enable_virtual_sensor & LINEAR_ACCEL_ENABLED == LINEAR_ACCEL_ENABLED) {
- linear_accel_sensor* linear_accel_sensor_ptr = NULL;
- try {
- linear_accel_sensor_ptr = new(std::nothrow) linear_accel_sensor;
- } catch (int err) {
- ERR("Failed to create linear_accel_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (linear_accel_sensor_ptr != NULL)
- sensors.push_back(linear_accel_sensor_ptr);
- }
-#endif
+ if (auto_rot_sensor_ptr != NULL) {
+ std::shared_ptr<sensor_base> sensor(auto_rot_sensor_ptr);
+ sensor_hal_type type;
- if (enable_virtual_sensor & ORIENTATION_ENABLED == ORIENTATION_ENABLED) {
-#ifdef ENABLE_ORIENTATION
- orientation_sensor* orientation_sensor_ptr = NULL;
- try {
- orientation_sensor_ptr = new(std::nothrow) orientation_sensor;
- } catch (int err) {
- ERR("Failed to create orientation_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (orientation_sensor_ptr != NULL)
- sensors.push_back(orientation_sensor_ptr);
-#endif
-#ifdef ENABLE_RV
- rv_sensor* rv_sensor_ptr = NULL;
- try {
- rv_sensor_ptr = new(std::nothrow) rv_sensor;
- } catch (int err) {
- ERR("Failed to create rv_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (rv_sensor_ptr != NULL)
- sensors.push_back(rv_sensor_ptr);
-#endif
-#ifdef ENABLE_GYROSCOPE_UNCAL
- gyroscope_uncal_sensor* gyroscope_uncal_sensor_ptr = NULL;
- try {
- gyroscope_uncal_sensor_ptr = new(std::nothrow) gyroscope_uncal_sensor;
- } catch (int err) {
- ERR("Failed to create gyroscope_uncal_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (gyroscope_uncal_sensor_ptr != NULL)
- sensors.push_back(gyroscope_uncal_sensor_ptr);
-#endif
- }
+ type = static_cast<sensor_hal_type>(sensor->get_type());
+ sensor->set_id(type);
-#ifdef ENABLE_GAMING_RV
- if (enable_virtual_sensor & GAMING_RV_ENABLED == GAMING_RV_ENABLED) {
- gaming_rv_sensor* gaming_rv_sensor_ptr = NULL;
- try {
- gaming_rv_sensor_ptr = new(std::nothrow) gaming_rv_sensor;
- } catch (int err) {
- ERR("Failed to create gaming_rv_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (gaming_rv_sensor_ptr != NULL)
- sensors.push_back(gaming_rv_sensor_ptr);
- }
-#endif
-#ifdef ENABLE_GEOMAGNETIC_RV
- if (enable_virtual_sensor & GEOMAGNETIC_RV_ENABLED == GEOMAGNETIC_RV_ENABLED) {
- geomagnetic_rv_sensor* geomagnetic_rv_sensor_ptr = NULL;
- try {
- geomagnetic_rv_sensor_ptr = new(std::nothrow) geomagnetic_rv_sensor;
- } catch (int err) {
- ERR("Failed to create geomagnetic_rv_sensor module, err: %d, cause: %s", err, strerror(err));
- }
- if (geomagnetic_rv_sensor_ptr != NULL)
- sensors.push_back(geomagnetic_rv_sensor_ptr);
+ m_sensors.insert(std::make_pair(type, sensor));
}
#endif
- shared_ptr<sensor_base> sensor;
-
- for (unsigned int i = 0; i < sensors.size(); ++i) {
- sensor.reset(static_cast<sensor_base*> (sensors[i]));
-
- if (!sensor->init()) {
- ERR("Failed to init [%s] module\n", sensor->get_name());
- continue;
- }
-
- DBG("init [%s] module", sensor->get_name());
-
- vector<sensor_type_t> sensor_types;
-
- 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));
- }
- }
show_sensor_info();
return true;
auto it = m_sensors.begin();
while (it != m_sensors.end()) {
- shared_ptr<sensor_base> sensor = it->second;
+ sensor_base *sensor = it->second.get();
sensor_info info;
- sensor->get_sensor_info(it->first, info);
+ sensor->get_sensor_info(info);
INFO("No:%d [%s]\n", ++index, sensor->get_name());
info.show();
it++;
return true;
}
-sensor_hal* sensor_plugin_loader::get_sensor_hal(sensor_hal_type_t type)
+sensor_base* sensor_plugin_loader::get_sensor(sensor_type_t type)
{
- auto it_plugins = m_sensor_hals.find(type);
+ auto it_plugins = m_sensors.find(static_cast<sensor_hal_type>(type));
- if (it_plugins == m_sensor_hals.end())
+ if (it_plugins == m_sensors.end())
return NULL;
return it_plugins->second.get();
}
-vector<sensor_hal *> sensor_plugin_loader::get_sensor_hals(sensor_hal_type_t type)
+sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id)
{
- 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.get());
+ vector<sensor_base *> sensors;
- return sensor_hal_list;
-}
+ sensor_type_t type = static_cast<sensor_type_t> (id & SENSOR_TYPE_MASK);
+ unsigned int index = id >> SENSOR_INDEX_SHIFT;
-sensor_base* sensor_plugin_loader::get_sensor(sensor_type_t type)
-{
- auto it_plugins = m_sensors.find(type);
+ sensors = get_sensors(type);
- if (it_plugins == m_sensors.end())
+ if (sensors.size() <= index)
return NULL;
- return it_plugins->second.get();
+ return sensors[index];
}
vector<sensor_base *> sensor_plugin_loader::get_sensors(sensor_type_t type)
{
vector<sensor_base *> sensor_list;
- pair<sensor_plugins::iterator, sensor_plugins::iterator> ret;
+ std::pair<sensor_plugins::iterator, sensor_plugins::iterator> ret;
- if (type == ALL_SENSOR)
+ if ((int)(type) == (int)SENSOR_HAL_TYPE_ALL)
ret = std::make_pair(m_sensors.begin(), m_sensors.end());
else
- ret = m_sensors.equal_range(type);
+ ret = m_sensors.equal_range(static_cast<sensor_hal_type>(type));
for (auto it = ret.first; it != ret.second; ++it)
sensor_list.push_back(it->second.get());
return sensor_list;
}
-
-sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id)
-{
- vector<sensor_base *> sensors;
-
- sensor_type_t type = (sensor_type_t) (id & SENSOR_TYPE_MASK);
- unsigned int index = id >> SENSOR_INDEX_SHIFT;
-
- sensors = get_sensors(type);
-
- if (sensors.size() <= index)
- return NULL;
-
- return sensors[index];
-}
-
-
vector<sensor_base *> sensor_plugin_loader::get_virtual_sensors(void)
{
vector<sensor_base *> virtual_list;
- sensor_base* module;
+ sensor_base* sensor;
for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) {
- module = sensor_it->second.get();
+ sensor = sensor_it->second.get();
- if (module && module->is_virtual() == true) {
- virtual_list.push_back(module);
+ if (sensor && sensor->is_virtual() == true) {
+ virtual_list.push_back(sensor);
}
}
class sensor_hal;
class sensor_base;
-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>
-* ...
-* </HAL>
-*
-*/
-
-typedef std::multimap<sensor_type_t, std::shared_ptr<sensor_base> > sensor_plugins;
-/*
-* a sensor_plugins is a group of sensor plugin
-* <SENSOR>
-* ...
-* </SENSOR>
-*
-*/
+typedef std::multimap<sensor_hal_type, std::shared_ptr<sensor_base>> sensor_plugins;
class sensor_plugin_loader
{
private:
- typedef enum plugin_type {
- PLUGIN_TYPE_HAL,
- PLUGIN_TYPE_SENSOR,
- } plugin_type;
-
sensor_plugin_loader();
- bool load_module(const std::string &path, std::vector<void*> &sensors, void* &handle);
- bool insert_module(plugin_type type, const std::string &path);
+ bool load_plugin(const std::string &path, std::vector<void *> &sensors, void* &handle);
+ bool insert_plugins(std::vector<void *> hals);
+ bool insert_sensors(sensor_hal *hal);
void show_sensor_info(void);
bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &hal_paths);
- sensor_hal_plugins m_sensor_hals;
sensor_plugins m_sensors;
-
public:
static sensor_plugin_loader& get_instance();
bool load_plugins(void);
- 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);
- std::vector<sensor_base *> get_sensors(sensor_type_t type);
sensor_base* get_sensor(sensor_id_t id);
+ std::vector<sensor_base *> get_sensors(sensor_type_t type);
std::vector<sensor_base*> get_virtual_sensors(void);
};
#endif /* _SENSOR_PLUGIN_LOADER_CLASS_H_ */
{
return csensor_event_dispatcher::get_instance().delete_active_virtual_sensor(this);
}
-
-bool virtual_sensor::push(sensor_event_t const &event)
-{
- csensor_event_queue::get_instance().push(event);
- return true;
-}
-
virtual_sensor();
virtual ~virtual_sensor();
- 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;
+ /* module info */
+ virtual sensor_type_t get_type() = 0;
+ virtual unsigned int get_event_type(void) = 0;
+ virtual const char* get_name(void) = 0;
+ virtual void synthesize(const sensor_event_t& event, std::vector<sensor_event_t> &outs) = 0;
+ virtual int get_sensor_data(sensor_data_t &data) = 0;
+ virtual bool is_virtual(void);
protected:
-
bool activate(void);
bool deactivate(void);
-
- bool push(sensor_event_t const &event);
+private:
+ bool m_hardware_fusion;
};
#endif
#ifndef _SENSOR_HAL_H_
#define _SENSOR_HAL_H_
+
+#include <stdint.h>
#include <string>
+#include <vector>
+#include <sensor_common.h>
#include <sf_common.h>
+#define SENSOR_HAL_VERSION(maj,min) \
+ ((((maj) & 0xffff) << 24) | ((min) & 0xffff))
+
+/*
+ * Sensor Types
+ * These types are used to controll the sensors
+ *
+ * - base unit
+ * acceleration values : meter per second^2 (m/s^2)
+ * magnetic values : micro-Tesla (uT)
+ * orientation values : degrees
+ * gyroscope values : degree/s
+ * temperature values : degrees centigrade
+ * proximity valeus : distance
+ * light values : lux
+ * pressure values : hectopascal (hPa)
+ * humidity : relative humidity (%)
+ */
typedef enum {
+ SENSOR_HAL_TYPE_UNKNOWN = -2,
+ SENSOR_HAL_TYPE_ALL = -1,
SENSOR_HAL_TYPE_ACCELEROMETER,
+ SENSOR_HAL_TYPE_GRAVITY,
+ SENSOR_HAL_TYPE_LINEAR_ACCELERATION,
SENSOR_HAL_TYPE_GEOMAGNETIC,
+ SENSOR_HAL_TYPE_ROTATION_VECTOR,
+ SENSOR_HAL_TYPE_ORIENTATION,
+ SENSOR_HAL_TYPE_GYROSCOPE,
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_ULTRAVIOLET,
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_HRM,
+ SENSOR_HAL_TYPE_HRM_LED_GREEN,
+ SENSOR_HAL_TYPE_HRM_LED_IR,
+ SENSOR_HAL_TYPE_HRM_LED_RED,
SENSOR_HAL_TYPE_GYROSCOPE_UNCAL,
SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL,
- SENSOR_HAL_TYPE_FUSION,
-} sensor_hal_type_t;
+ SENSOR_HAL_TYPE_GYROSCOPE_RV,
+ SENSOR_HAL_TYPE_GEOMAGNETIC_RV,
+ SENSOR_HAL_TYPE_ACTIVITY_STATIONARY = 0x100,
+ SENSOR_HAL_TYPE_ACTIVITY_WALK,
+ SENSOR_HAL_TYPE_ACTIVITY_RUN,
+ SENSOR_HAL_TYPE_ACTIVITY_IN_VEHICLE,
+ SENSOR_HAL_TYPE_ACTIVITY_ON_BICYCLE,
+ SENSOR_HAL_TYPE_GESTURE_MOVEMENT = 0x200,
+ SENSOR_HAL_TYPE_GESTURE_WRIST_UP,
+ SENSOR_HAL_TYPE_GESTURE_WRIST_DOWN,
+ SENSOR_HAL_TYPE_HUMAN_PEDOMETER = 0x300,
+ SENSOR_HAL_TYPE_HUMAN_SLEEP_MONITOR,
+
+ SENSOR_HAL_TYPE_FUSION = 0x900,
+ SENSOR_HAL_TYPE_AUTO_ROTATION,
+
+ SENSOR_HAL_TYPE_CONTEXT = 0x1000,
+ SENSOR_HAL_TYPE_MOTION,
+ SENSOR_HAL_TYPE_PIR,
+ SENSOR_HAL_TYPE_PIR_LONG,
+ SENSOR_HAL_TYPE_DUST,
+ SENSOR_HAL_TYPE_THERMOMETER,
+ SENSOR_HAL_TYPE_PEDOMETER,
+ SENSOR_HAL_TYPE_FLAT,
+ SENSOR_HAL_TYPE_HRM_RAW,
+ SENSOR_HAL_TYPE_TILT,
+ SENSOR_HAL_TYPE_ROTATION_VECTOR_RAW,
+} sensor_hal_type;
+
+/*
+ * A platform sensor handler is generated based on this handle
+ * ID can be assigned from HAL developer. so it has to be unique in HAL.
+ */
+typedef struct sensor_handle_t {
+ uint32_t id;
+ std::string name;
+ sensor_hal_type type;
+ unsigned int event_type; // for Internal API
+} sensor_handle_t;
+
+/*
+ * Sensor HAL interface
+ * 1 HAL must be abstracted from 1 device event node
+ */
class sensor_hal
{
public:
- sensor_hal();
- virtual ~sensor_hal();
-
- 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 is_data_ready(void) = 0;
- virtual bool set_interval(unsigned long val) = 0;
- virtual int get_sensor_data(sensor_data_t &data) = 0;
- virtual bool get_properties(sensor_properties_s &properties) = 0;
+ uint32_t get_hal_version(void) {
+ return SENSOR_HAL_VERSION(1, 0);
+ }
+
+ virtual int get_poll_fd(void) = 0;
+ virtual bool get_sensors(std::vector<sensor_handle_t> &sensors) = 0;
+
+ /* enable/disable sensor device */
+ virtual bool enable(uint32_t id) = 0;
+ virtual bool disable(uint32_t id) = 0;
+
+ /* set_command or set_option? */
+ virtual bool set_command(uint32_t id, std::string command, std::string value) = 0;
+
+ /* the belows can be merged to one */
+ virtual bool set_interval(uint32_t id, unsigned long val) = 0;
+ virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
+
+ /* sensor fw read the data when is_data_ready() is true */
+ virtual bool is_data_ready() = 0;
+ virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0;
+ virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0;
+
+ /* TODO: use get_sensors() instead of get_properties() */
+ virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0;
};
#endif /*_SENSOR_HAL_H_*/
return m_max_batch_count;
}
-void sensor_info::get_supported_events(vector<unsigned int> &events)
+unsigned int sensor_info::get_supported_event()
{
- events = m_supported_events;
+ return m_supported_event;
}
bool sensor_info::is_supported_event(unsigned int event)
{
- auto iter = find(m_supported_events.begin(), m_supported_events.end(), event);
-
- if (iter == m_supported_events.end())
+ if (event != m_supported_event)
return false;
return true;
m_max_batch_count = max_batch_count;
}
-void sensor_info::register_supported_event(unsigned int event)
+void sensor_info::set_supported_event(unsigned int event)
{
- m_supported_events.push_back(event);
-}
-
-void sensor_info::set_supported_events(vector<unsigned int> &events)
-{
- copy(events.begin(), events.end(), back_inserter(m_supported_events));
+ m_supported_event = event;
}
void sensor_info::set_wakeup_supported(bool supported)
put(data, m_min_interval);
put(data, m_fifo_count);
put(data, m_max_batch_count);
- put(data, m_supported_events);
+ put(data, m_supported_event);
put(data, m_wakeup_supported);
}
it_r_data = get(it_r_data, m_min_interval);
it_r_data = get(it_r_data, m_fifo_count);
it_r_data = get(it_r_data, m_max_batch_count);
- it_r_data = get(it_r_data, m_supported_events);
+ it_r_data = get(it_r_data, m_supported_event);
it_r_data = get(it_r_data, m_wakeup_supported);
}
INFO("Min_interval = %d", m_min_interval);
INFO("Fifo_count = %d", m_fifo_count);
INFO("Max_batch_count = %d", m_max_batch_count);
-
- for (unsigned int i = 0; i < m_supported_events.size(); ++i)
- INFO("supported_events[%u] = 0x%x", i, m_supported_events[i]);
+ INFO("supported_event = 0x%x", m_supported_event);
INFO("Wakeup_supported = %d", m_wakeup_supported);
}
m_min_interval = 0;
m_fifo_count = 0;
m_max_batch_count = 0;
- m_supported_events.clear();
+ m_supported_event = 0;
m_wakeup_supported = false;
}
copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
}
-void sensor_info::put(raw_data_t &data, float value)
+void sensor_info::put(raw_data_t &data, unsigned int value)
{
char buffer[sizeof(value)];
- float *temp = (float *) buffer;
+ unsigned int *temp = (unsigned int *) buffer;
*temp = value;
copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
}
-void sensor_info::put(raw_data_t &data, string &value)
+void sensor_info::put(raw_data_t &data, float value)
{
- put(data, (int) value.size());
+ char buffer[sizeof(value)];
- copy(value.begin(), value.end(), back_inserter(data));
+ float *temp = (float *) buffer;
+ *temp = value;
+
+ copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
}
-void sensor_info::put(raw_data_t &data, vector<unsigned int> &value)
+void sensor_info::put(raw_data_t &data, string &value)
{
put(data, (int) value.size());
- auto it = value.begin();
-
- while (it != value.end()) {
- put(data, (int) *it);
- ++it;
- }
+ copy(value.begin(), value.end(), back_inserter(data));
}
void sensor_info::put(raw_data_t &data, bool value)
return it + sizeof(value);
}
-raw_data_iterator sensor_info::get(raw_data_iterator it, float &value)
+raw_data_iterator sensor_info::get(raw_data_iterator it, unsigned int &value)
{
copy(it, it + sizeof(value), (char*) &value);
return it + sizeof(value);
}
-raw_data_iterator sensor_info::get(raw_data_iterator it, string &value)
+raw_data_iterator sensor_info::get(raw_data_iterator it, float &value)
{
- int len;
-
- it = get(it, len);
-
- copy(it, it + len, back_inserter(value));
+ copy(it, it + sizeof(value), (char*) &value);
- return it + len;
+ return it + sizeof(value);
}
-raw_data_iterator sensor_info::get(raw_data_iterator it, vector<unsigned int> &value)
+raw_data_iterator sensor_info::get(raw_data_iterator it, string &value)
{
int len;
it = get(it, len);
- int ele;
- for (int i = 0; i < len; ++i) {
- it = get(it, ele);
- value.push_back(ele);
- }
+ copy(it, it + len, back_inserter(value));
- return it;
+ return it + len;
}
raw_data_iterator sensor_info::get(raw_data_iterator it, bool &value)
int get_min_interval(void);
int get_fifo_count(void);
int get_max_batch_count(void);
- void get_supported_events(std::vector<unsigned int> &events);
+ unsigned int get_supported_event();
bool is_supported_event(unsigned int event);
bool is_wakeup_supported(void);
void set_min_interval(int min_interval);
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(std::vector<unsigned int> &events);
+ void set_supported_event(unsigned int event);
void set_wakeup_supported(bool supported);
void clear(void);
int m_min_interval;
int m_fifo_count;
int m_max_batch_count;
- std::vector<unsigned int> m_supported_events;
+ unsigned int m_supported_event;
bool m_wakeup_supported;
void put(raw_data_t &data, int value);
+ void put(raw_data_t &data, unsigned int value);
void put(raw_data_t &data, float value);
void put(raw_data_t &data, std::string &value);
- void put(raw_data_t &data, std::vector<unsigned int> &value);
void put(raw_data_t &data, bool value);
raw_data_iterator get(raw_data_iterator it, int &value);
+ raw_data_iterator get(raw_data_iterator it, unsigned int &value);
raw_data_iterator get(raw_data_iterator it, float &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);
raw_data_iterator get(raw_data_iterator it, bool &value);
};