*
*/
+#include <sensor_common.h>
#include <sensor_internal_deprecated.h>
#include <sensor_internal.h>
#include <sensor_event_listener.h>
+#include <sensor_client_info.h>
#include <client_common.h>
#include <vconf.h>
#include <cmutex.h>
#define DEFAULT_INTERVAL POLL_10HZ_MS
-static const int OP_SUCCESS = 0;
-static const int OP_ERROR = -1;
-
static cmutex lock;
static int g_power_save_state = 0;
{
AUTOLOCK(lock);
- _I("Trying to restore session for %s", get_client_name());
+ _I("Trying to restore sensor client session for %s", get_client_name());
command_channel *cmd_channel;
int client_id;
++it_sensor;
}
- _I("Succeeded to restore session for %s", get_client_name());
+ _I("Succeeded to restore sensor client session for %s", get_client_name());
return;
sensor_info* info = sensor_to_sensor_info(sensor);
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);
+ false, "Invalid param: sensor (%p), event_types(%p), count(%p)", sensor, event_types, count);
unsigned int event_type;
event_type = info->get_supported_event();
- *event_types = (unsigned int *) malloc(sizeof(unsigned int));
+ *event_types = (unsigned int *)malloc(sizeof(unsigned int));
+
retvm_if(!*event_types, false, "Failed to allocate memory");
(*event_types)[0] = event_type;
sensor_info* info = sensor_to_sensor_info(sensor);
retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_type || !supported,
- false, "Invalid param: sensor (%p), event_type(%p), supported(%)", sensor, event_type, supported);
+ false, "Invalid param: sensor (%p), event_type(%p), supported(%p)", sensor, event_type, supported);
*supported = info->is_supported_event(event_type);
if (!sensor_registered) {
cmd_channel = new(std::nothrow) command_channel();
- retvm_if (!cmd_channel, OP_ERROR, "Failed to allocate memory");
+ if (!cmd_channel) {
+ _E("Failed to allocated memory");
+ sensor_client_info::get_instance().delete_handle(handle);
+ return OP_ERROR;
+ }
if (!cmd_channel->create_channel()) {
_E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(sensor_id));
return false;
}
+ if (interval == 0)
+ interval = DEFAULT_INTERVAL;
+
_I("%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);
sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data);
- if (interval == 0)
- interval = DEFAULT_INTERVAL;
-
if (!sensor_client_info::get_instance().set_event_batch(handle, event_type, interval, latency))
return false;
AUTOLOCK(lock);
if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
- _E("client %s failed to get handle information", get_client_name());
+ _E("Client %s failed to get handle information", get_client_name());
return false;
}
if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
- _E("client %s failed to get command channel for %s",
+ _E("Client %s failed to get command channel for %s",
get_client_name(), get_sensor_name(sensor_id));
return false;
}
return sensord_set_attribute_str(handle, 0, data, data_len);
}
+API bool sensord_send_command(int handle, const char *command, int command_len)
+{
+ return sensord_set_attribute_str(handle, 0, command, command_len);
+}
+
API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
{
sensor_id_t sensor_id;
* limitations under the License.
*
*/
+#include <time.h>
#include <client_common.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
-#include <unordered_map>
-using std::unordered_map;
-
-#define FILL_LOG_ELEMENT(ID, TYPE, CNT, PRINT_PER_CNT) {ID, TYPE, {#TYPE, CNT, PRINT_PER_CNT} }
-
-log_element g_log_elements[] = {
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, UNKNOWN_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ACCELEROMETER_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GEOMAGNETIC_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, LIGHT_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, PROXIMITY_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GYROSCOPE_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, PRESSURE_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, CONTEXT_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, AUTO_ROTATION_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GRAVITY_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, LINEAR_ACCEL_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ORIENTATION_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, TEMPERATURE_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ROTATION_VECTOR_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GEOMAGNETIC_RV_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GAMING_RV_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, FUSION_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, TILT_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GYROSCOPE_UNCAL_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ULTRAVIOLET_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, BIO_LED_RED_SENSOR, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GESTURE_WRIST_UP_SENSOR, 0, 1),
-
- FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_CHANGE_STATE_EVENT, 0,1),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_CHANGE_LEVEL_EVENT, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_STATE_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_DISTANCE_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, AUTO_ROTATION_CHANGE_STATE_EVENT, 0, 1),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, ACCELEROMETER_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GYROSCOPE_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GEOMAGNETIC_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, PRESSURE_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_LEVEL_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_LUX_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GRAVITY_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, LINEAR_ACCEL_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, ORIENTATION_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, PRESSURE_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, TEMPERATURE_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, ROTATION_VECTOR_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GEOMAGNETIC_RV_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GAMING_RV_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, FUSION_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, TILT_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, GYROSCOPE_UNCAL_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, ULTRAVIOLET_RAW_DATA_EVENT, 0, 10),
- FILL_LOG_ELEMENT(LOG_ID_EVENT, BIO_LED_RED_RAW_DATA_EVENT, 0, 10),
+#include <map>
+
+typedef std::map<sensor_type_t, log_attr> sensor_type_map;
+static sensor_type_map g_log_maps = {
+ {UNKNOWN_SENSOR, {"UNKNOWN", "UNKNOWN_EVENT"}},
+ {ACCELEROMETER_SENSOR, {"ACCELEROMETER", "ACCELEROMETER_RAW_DATA_EVENT"}},
+ {GRAVITY_SENSOR, {"GRAVITY", "GRAVITY_RAW_DATA_EVENT"}},
+ {LINEAR_ACCEL_SENSOR, {"LINEAR_ACCEL", "LINEAR_ACCEL_RAW_DATA_EVENT"}},
+ {GEOMAGNETIC_SENSOR, {"GEOMAGNETIC SENSOR", "GEOMAGNETIC SENSOR_RAW_DATA_EVENT"}},
+ {ROTATION_VECTOR_SENSOR, {"ROTATION VECTOR", "ROTATION VECTOR_RAW_DATA_EVENT"}},
+ {ORIENTATION_SENSOR, {"ORIENTATION", "ORIENTATION_RAW_DATA_EVENT"}},
+ {GYROSCOPE_SENSOR, {"GYROSCOPE", "GYROSCOPE_RAW_DATA_EVENT"}},
+ {LIGHT_SENSOR, {"LIGHT", "LIGHT_RAW_DATA_EVENT"}},
+ {PROXIMITY_SENSOR, {"PROXIMITY", "PROXIMITY_RAW_DATA_EVENT"}},
+ {PRESSURE_SENSOR, {"PRESSURE", "PRESSURE_RAW_DATA_EVENT"}},
+ {ULTRAVIOLET_SENSOR, {"ULTRAVIOLET", "ULTRAVIOLET_RAW_DATA_EVENT"}},
+ {TEMPERATURE_SENSOR, {"TEMPERATURE", "TEMPERATURE_RAW_DATA_EVENT"}},
+ {HUMIDITY_SENSOR, {"HUMIDITY", "HUMIDITY_RAW_DATA_EVENT"}},
+ {BIO_HRM_SENSOR, {"BIO_HRM", "BIO_HRM_RAW_DATA_EVENT"}},
+ {BIO_LED_GREEN_SENSOR, {"BIO_LED_GREEN", "BIO_LED_GREEN_RAW_DATA_EVENT"}},
+ {BIO_LED_IR_SENSOR, {"BIO_LED_IR", "BIO_LED_IR_RAW_DATA_EVENT"}},
+ {BIO_LED_RED_SENSOR, {"BIO_LED_RED", "BIO_LED_RED_RAW_DATA_EVENT"}},
+ {GYROSCOPE_UNCAL_SENSOR, {"GYROSCOPE_UNCAL", "GYROSCOPE_UNCAL_RAW_DATA_EVENT"}},
+ {GEOMAGNETIC_UNCAL_SENSOR, {"GEOMAGNETIC_UNCAL", "GEOMAGNETIC_UNCAL_RAW_DATA_EVENT"}},
+ {GYROSCOPE_RV_SENSOR, {"GYROSCOPE_RV", "GYROSCOPE_RV_RAW_DATA_EVENT"}},
+ {GEOMAGNETIC_RV_SENSOR, {"GEOMAGNETIC_RV", "GEOMAGNETIC_RV_RAW_DATA_EVENT"}},
+ {CONTEXT_SENSOR, {"CONTEXT", "CONTEXT_RAW_DATA_EVENT"}},
};
-typedef unordered_map<unsigned int, log_attr* > log_map;
-static log_map g_log_maps[LOG_ID_END];
-
-static void init_log_maps(void);
-
-class initiator {
-public:
- initiator()
- {
- init_log_maps();
- }
-};
-
-static initiator g_initiator;
-
-void init_log_maps(void)
+const char* get_sensor_name(sensor_id_t sensor_id)
{
- int cnt;
+ const char* p_unknown = "UNKNOWN";
+ sensor_type_t sensor_type = (sensor_type_t) (sensor_id >> SENSOR_TYPE_SHIFT);
- cnt = sizeof(g_log_elements) / sizeof(g_log_elements[0]);
+ auto iter = g_log_maps.find(sensor_type);
- for (int i = 0; i < cnt; ++i) {
- g_log_maps[g_log_elements[i].id][g_log_elements[i].type] = &g_log_elements[i].log_attr;
+ if (iter == g_log_maps.end()) {
+ _I("Unknown type value: 0x%x", sensor_type);
+ return p_unknown;
}
+ return iter->second.sensor_name;
}
-const char* get_log_element_name(log_id id, unsigned int type)
+const char* get_event_name(unsigned int event_type)
{
const char* p_unknown = "UNKNOWN";
+ sensor_type_t sensor_type = (sensor_type_t) (event_type >> EVENT_TYPE_SHIFT);
- auto iter = g_log_maps[id].find(type);
+ auto iter = g_log_maps.find(sensor_type);
- if (iter == g_log_maps[id].end()) {
- _I("Unknown type value: 0x%x", type);
+ if (iter == g_log_maps.end()) {
+ _I("Unknown type value: 0x%x", sensor_type);
return p_unknown;
}
- return iter->second->name;
-}
-
-const char* get_sensor_name(sensor_id_t sensor_id)
-{
- sensor_type_t sensor_type = (sensor_type_t) (sensor_id >> SENSOR_TYPE_SHIFT);
-
- return get_log_element_name(LOG_ID_SENSOR_TYPE, sensor_type);
-}
-
-const char* get_event_name(unsigned int event_type)
-{
- return get_log_element_name(LOG_ID_EVENT, event_type);
-}
-
-
-const char* get_data_name(unsigned int data_id)
-{
- return get_log_element_name(LOG_ID_DATA, data_id);
+ return iter->second.event_name;
}
bool is_one_shot_event(unsigned int event_type)
void print_event_occurrence_log(sensor_handle_info &sensor_handle_info, const reg_event_info *event_info)
{
- log_attr *log_attr;
-
- auto iter = g_log_maps[LOG_ID_EVENT].find(event_info->type);
-
- if (iter == g_log_maps[LOG_ID_EVENT].end())
- return;
-
- log_attr = iter->second;
-
- log_attr->cnt++;
-
- if ((log_attr->cnt != 1) && ((log_attr->cnt % log_attr->print_per_cnt) != 0)) {
- return;
- }
-
- _I("%s receives %s with %s[%d][state: %d, option: %d count: %d]", get_client_name(), log_attr->name,
- get_sensor_name(sensor_handle_info.m_sensor_id), sensor_handle_info.m_handle, sensor_handle_info.m_sensor_state,
- sensor_handle_info.m_sensor_option, log_attr->cnt);
-
- _I("0x%x(cb_event_type = %s, &user_data, client_data = 0x%x)\n", event_info->m_cb,
- log_attr->name, event_info->m_user_data);
+ _D("%s receives %s[%d]", get_client_name(),
+ get_sensor_name(sensor_handle_info.m_sensor_id), sensor_handle_info.m_handle);
}
/*
#define CLIENT_NAME_SIZE NAME_MAX+10
-enum log_id {
- LOG_ID_START = 0,
- LOG_ID_SENSOR_TYPE = 0,
- LOG_ID_EVENT,
- LOG_ID_DATA,
- LOG_ID_PROPERTY,
- LOG_ID_END,
-};
-
struct log_attr {
- const char *name;
- unsigned long cnt;
- const unsigned int print_per_cnt;
-};
-
-struct log_element {
- log_id id;
- int type;
- struct log_attr log_attr;
+ char *sensor_name;
+ char *event_name;
};
-
-typedef struct {
- int handle;
- unsigned int event_type;
- sensor_event_data_t ev_data;
- int sensor_state;
- int sensor_option;
- sensor_type_t sensor;
- reg_event_info event_info;
-} log_info;
-
bool is_one_shot_event(unsigned int event_type);
bool is_ontime_event(unsigned int event_type);
bool is_panning_event(unsigned int event_type);
unsigned int get_calibration_event_type(unsigned int event_type);
unsigned long long get_timestamp(void);
-const char* get_log_element_name(log_id id, unsigned int type);
const char* get_sensor_name(sensor_id_t sensor_id);
const char* get_event_name(unsigned int event_type);
-const char* get_data_name(unsigned int data_id);
void print_event_occurrence_log(sensor_handle_info &sensor_handle_info, const reg_event_info *event_info);
class sensor_info;
if (m_command_socket.recv(&header, sizeof(header)) <= 0) {
m_command_socket.close();
- _E("Failed to receive header for reply packet in client %s", get_client_name());
+ _E("Failed to receive header for command reply packet in client %s", get_client_name());
return false;
}
if (m_command_socket.recv(buffer, header.size) <= 0) {
m_command_socket.close();
- _E("Failed to receive reply packet in client %s", get_client_name());
+ _E("Failed to receive command reply packet in client %s", get_client_name());
delete[] buffer;
return false;
}
cmd_get_data->type = type;
if (!command_handler(packet, (void **)&cmd_get_data_done)) {
- _E("Client %s failed to send/receive command with client_id [%d], data_id[%s]",
- get_client_name(), m_client_id, get_data_name(type));
+ _E("Client %s failed to send/receive command with client_id [%d]",
+ get_client_name(), m_client_id);
delete packet;
return false;
}
if (cmd_get_data_done->state < 0 ) {
- _E("Client %s got error[%d] from server with client_id [%d], data_id[%s]",
- get_client_name(), cmd_get_data_done->state, m_client_id, get_data_name(type));
+ _E("Client %s got error[%d] from server with client_id [%d]",
+ get_client_name(), cmd_get_data_done->state, m_client_id);
sensor_data->accuracy = SENSOR_ACCURACY_UNDEFINED;
sensor_data->timestamp = 0;
sensor_data->value_count = 0;
get_client_name(), m_client_id, get_sensor_name(m_sensor_id), attribute, value);
if (!command_handler(packet, (void **)&cmd_done)) {
- _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], property[0x%x], value[%d]",
+ _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], attribute[0x%x], value[%d]",
get_client_name(), get_sensor_name(m_sensor_id), m_client_id, attribute, value);
delete packet;
return false;
}
if (cmd_done->value < 0) {
- _E("Client %s got error[%d] from server for sensor[%s] with property[0x%x], value[%d]",
+ _E("Client %s got error[%d] from server for sensor[%s] with attribute[0x%x], value[%d]",
get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), attribute, value);
delete[] (char *)cmd_done;
cmd_set_attribute_str->value_len = value_len;
memcpy(cmd_set_attribute_str->value, value, value_len);
- _I("%s send cmd_set_attribute_str(client_id=%d, value_len = %d, buffer = 0x%x)",
- get_client_name(), m_client_id, value_len, value);
+ _I("%s send cmd_set_attribute_str(client_id=%d, attribute = 0x%x, value_len = %d, value = 0x%x)",
+ get_client_name(), m_client_id, attribute, value_len, value);
if (!command_handler(packet, (void **)&cmd_done)) {
_E("%s failed to send/receive command with client_id [%d]",
delete[] (char *)cmd_done;
delete packet;
-
return true;
-
-
}
class command_channel {
public:
-
command_channel();
~command_channel();
bool cmd_unregister_events(event_type_vector &event_vec);
bool cmd_set_batch(unsigned int interval, unsigned int latency);
bool cmd_unset_batch(void);
- bool cmd_get_data(unsigned int type, sensor_data_t* values);
+ bool cmd_get_data(unsigned int type, sensor_data_t *values);
bool cmd_set_attribute_int(int attribute, int value);
- bool cmd_set_attribute_str(int attribute, const char* buffer, int data_len);
+ bool cmd_set_attribute_str(int attribute, const char *value, int value_len);
private:
csocket m_command_socket;
int m_client_id;
bool command_handler(cpacket *packet, void **return_payload);
};
-#endif /* COMMAND_CHANNEL_H_ */
+#endif /* _COMMAND_CHANNEL_H_ */
void *m_cb;
void *m_user_data;
unsigned long long m_previous_event_time;
- bool m_fired;
+ bool m_fired;
GMainContext *m_maincontext;
- reg_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), m_maincontext(NULL){}
+ reg_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), m_maincontext(NULL) {}
- ~reg_event_info(){}
+ ~reg_event_info() {}
};
-
#endif /* _REG_EVENT_INFO_H_ */
#include <thread>
#include <chrono>
-#define MS_TO_US 1000
-#define MIN_DELIVERY_DIFF_FACTOR 0.75f
-
using std::thread;
using std::pair;
return true;
}
-
bool sensor_client_info::has_client_id(void)
{
return (m_client_id != CLIENT_ID_INVALID);
return false;
}
-
bool sensor_client_info::is_sensor_active(sensor_id_t sensor)
{
AUTOLOCK(m_handle_info_lock);
#include <chrono>
#include <vector>
-#define MS_TO_US 1000
-#define MIN_DELIVERY_DIFF_FACTOR 0.75f
+#include <sensor_types.h>
-/* TODO: this macro should be adjusted */
+/* TODO: this macro should be adjusted(4224 = 4096(data) + 128(header)) */
#define EVENT_BUFFER_SIZE 4224
using std::thread;
return len;
}
-
-
void sensor_event_listener::listen_events(void)
{
struct epoll_event event;
hup_observer_t m_hup_observer;
+ sensor_client_info &m_client_info;
+
sensor_event_listener();
~sensor_event_listener();
bool create_event_channel(void);
void close_event_channel(void);
- ssize_t sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event);
+ ssize_t sensor_event_poll(void *buffer, int buffer_len, struct epoll_event &event);
void listen_events(void);
client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy);
static gboolean callback_dispatcher(gpointer data);
void set_thread_state(thread_state state);
-
- sensor_client_info &m_client_info;
};
#endif /* _SENSOR_EVENT_LISTENER_H_ */
#ifndef _SENSOR_HANDLE_INFO_H_
#define _SENSOR_HANDLE_INFO_H_
+#include <sensor_internal.h>
#include <reg_event_info.h>
#include <sensor_log.h>
#include <string.h>
#include <unordered_map>
#include <glib.h>
-#include <sensor_internal.h>
typedef std::unordered_map<unsigned int,reg_event_info> event_info_map;
/*header for common sensor type*/
#include <sensor_common.h>
-
-/*header for each sensor type*/
#include <sensor_types.h>
-
+#include <sensor_deprecated.h>
#include <sensor_internal_deprecated.h>
#ifdef __cplusplus
* @return true on success, otherwise false.
*/
bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
+bool sensord_send_command(int handle, const char *command, int command_len);
/**
* @brief get sensor data from a connected sensor
/*header for common sensor type*/
#include <sensor_common.h>
-
-/*header for each sensor type*/
#include <sensor_types.h>
-
#include <sensor_deprecated.h>
-
#ifdef __cplusplus
extern "C"
{
SENSOR_DEVICE_GYROSCOPE_RV,
SENSOR_DEVICE_GEOMAGNETIC_RV,
- SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x100,
- SENSOR_DEVICE_ACTIVITY_WALK,
- SENSOR_DEVICE_ACTIVITY_RUN,
- SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
- SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
-
- SENSOR_DEVICE_GESTURE_MOVEMENT = 0x200,
- SENSOR_DEVICE_GESTURE_WRIST_UP,
- SENSOR_DEVICE_GESTURE_WRIST_DOWN,
-
SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
SENSOR_DEVICE_HRM_RAW,
SENSOR_DEVICE_TILT,
SENSOR_DEVICE_ROTATION_VECTOR_RAW,
+
+ SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x1100,
+ SENSOR_DEVICE_ACTIVITY_WALK,
+ SENSOR_DEVICE_ACTIVITY_RUN,
+ SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
+ SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
+
+ SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200,
+ SENSOR_DEVICE_GESTURE_WRIST_UP,
+ SENSOR_DEVICE_GESTURE_WRIST_DOWN,
} sensor_device_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.
+ * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device.
*/
typedef struct sensor_info_t {
uint32_t id;
virtual bool enable(uint32_t id) = 0;
virtual bool disable(uint32_t id) = 0;
- virtual bool set_interval(uint32_t id, unsigned long val) = 0;
- virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
- virtual bool set_attribute_int(uint32_t id, int32_t attribute, int32_t value) = 0;
- virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len) = 0;
-
virtual int read_fd(uint32_t **ids) = 0;
virtual int get_data(uint32_t id, sensor_data_t **data, int *length) = 0;
- virtual bool flush(uint32_t id) = 0;
+ virtual bool set_interval(uint32_t id, unsigned long val)
+ {
+ return false;
+ }
+ virtual bool set_batch_latency(uint32_t id, unsigned long val)
+ {
+ return false;
+ }
+ virtual bool set_attribute_int(uint32_t id, int32_t attribute, int32_t value)
+ {
+ return false;
+ }
+ virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len)
+ {
+ return false;
+ }
+ virtual bool flush(uint32_t id)
+ {
+ return false;
+ }
};
#endif /* __cplusplus */
int remains;
rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+ if (!rotation_event) {
+ _E("Failed to allocate memory");
+ return;
+ }
+
remains = get_data(&rotation_data, &data_length);
if (remains < 0)
#define _AUTO_ROTATION_SENSOR_H_
#include <virtual_sensor.h>
-#include <sensor_internal.h>
+#include <sensor_types.h>
#include <auto_rotation_alg.h>
class auto_rotation_sensor : public virtual_sensor {
auto_rotation_alg *get_alg();
};
-#endif
+#endif /* _AUTO_ROTATION_SENSOR_H_ */
using std::string;
using std::vector;
-#define SENSOR_NAME "GAMING_RV_SENSOR"
+#define SENSOR_NAME "GYROSCOPE_RV_SENSOR"
#define SENSOR_TYPE_GAMING_RV "GAMING_ROTATION_VECTOR"
#define ACCELEROMETER_ENABLED 0x01
void gaming_rv_sensor::get_types(vector<sensor_type_t> &types)
{
- types.push_back(GAMING_RV_SENSOR);
+ types.push_back(GYROSCOPE_RV_SENSOR);
}
bool gaming_rv_sensor::on_start(void)
*
*/
-#ifndef _GAMING_RV_SENSOR_H_
-#define _GAMING_RV_SENSOR_H_
+#ifndef _GYROSCOPE_RV_SENSOR_H_
+#define _GYROSCOPE_RV_SENSOR_H_
#include <sensor_internal.h>
#include <virtual_sensor.h>
bool on_stop(void);
};
-#endif /*_GAMING_RV_SENSOR_H_*/
+#endif /*_GYROSCOPE_RV_SENSOR_H_*/
#ifndef _CLIENT_SENSOR_RECORD_H_
#define _CLIENT_SENSOR_RECORD_H_
-#include <sensor_internal.h>
+#include <sensor_common.h>
+#include <sensor_types.h>
#include <sensor_usage.h>
#include <csocket.h>
#include <unordered_map>
*
*/
+#include <sensor_common.h>
#include <command_common.h>
#include <sensor_loader.h>
#include <sensor_info.h>
-#include <sensor_types.h>
#include <thread>
#include <string>
#include <vector>
_I("%s is stopped", info.c_str());
if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
-
if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) {
_W("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);
#ifndef _COMMAND_WORKER_H_
#define _COMMAND_WORKER_H_
+#include <sensor_common.h>
#include <command_common.h>
#include <worker_thread.h>
#include <client_info_manager.h>
#include <sensor_event_dispatcher.h>
#include <sensor_base.h>
#include <map>
-#include <cpacket.h>
typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
void insert_priority_list(unsigned int);
private:
typedef bool (command_worker::*cmd_handler_t)(void *payload);
- static const int OP_ERROR = -1;
- static const int OP_SUCCESS = 0;
-
int m_client_id;
int m_permission;
csocket m_socket;
#include <sensor_log.h>
class device_config {
-protected:
- virtual bool load_config(const std::string& config_path) = 0;
-
- std::string m_device_id;
public:
device_config();
virtual ~device_config();
bool get_device_id(void);
+protected:
+ virtual bool load_config(const std::string& config_path) = 0;
+
+ std::string m_device_id;
};
#endif /* _DEVICE_CONFIG_H_ */
*
*/
+#include <sensor_common.h>
#include <physical_sensor.h>
#include <sensor_event_queue.h>
#define UNKNOWN_NAME "UNKNOWN_SENSOR"
-#define OP_SUCCESS 0
-#define OP_ERROR -1
-
cmutex physical_sensor::m_mutex;
physical_sensor::physical_sensor()
AUTOLOCK(m_mutex);
if (!m_sensor_device)
- return -1;
+ return OP_ERROR;
return m_sensor_device->get_poll_fd();
}
AUTOLOCK(m_mutex);
if (!m_sensor_device)
- return -1;
+ return OP_ERROR;
int remains = 0;
remains = m_sensor_device->get_data(m_info->id, data, length);
if (*length < 0) {
_E("Failed to get sensor event");
- return -1;
+ return OP_ERROR;
}
return remains;
AUTOLOCK(m_mutex);
if (!m_sensor_device)
- return false;
+ return OP_ERROR;
if (!m_sensor_device->set_attribute_int(m_info->id, attribute, value))
return OP_ERROR;
AUTOLOCK(m_mutex);
if (!m_sensor_device)
- return false;
+ return OP_ERROR;
if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, value_len))
return OP_ERROR;
info.set_max_range(m_info->max_range);
info.set_resolution(m_info->resolution);
info.set_min_interval(m_info->min_interval);
- info.set_fifo_count(0); // FIXME
+ info.set_fifo_count(0);
info.set_max_batch_count(m_info->max_batch_count);
info.set_supported_event(get_event_type());
info.set_wakeup_supported(m_info->wakeup_supported);
*/
#include <stdint.h>
-#include <algorithm>
-#include <utility>
-#include <functional>
#include <sensor_hal.h>
#include <sensor_event_queue.h>
#include <sensor_base.h>
+#include <sensor_common.h>
+
+#include <algorithm>
+#include <utility>
+#include <functional>
using std::make_pair;
using std::vector;
sensor_base::sensor_base()
-: m_unique_id(-1)
+: m_id(SENSOR_ID_INVALID)
, m_permission(SENSOR_PERMISSION_STANDARD)
, m_started(false)
, m_client(0)
void sensor_base::set_id(sensor_id_t id)
{
- m_unique_id = id;
+ m_id = id;
}
sensor_id_t sensor_base::get_id(void)
{
- if (m_unique_id == -1)
+ if (m_id == SENSOR_ID_INVALID)
return UNKNOWN_SENSOR;
- return m_unique_id;
+ return m_id;
}
sensor_type_t sensor_base::get_type(void)
int sensor_base::get_data(sensor_data_t **data, int *length)
{
- return -1;
+ return OP_ERROR;
}
bool sensor_base::flush(void)
int sensor_base::set_attribute(int32_t cmd, int32_t value)
{
- return -1;
+ return OP_ERROR;
}
int sensor_base::set_attribute(int32_t attribute, char *value, int value_size)
{
- return -1;
+ return OP_ERROR;
}
bool sensor_base::start()
{
unsigned int prev_min, cur_min;
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_min = m_plugin_info_list.get_min_interval();
+ prev_min = m_sensor_info_list.get_min_interval();
- if (!m_plugin_info_list.add_interval(client_id, interval, is_processor))
+ if (!m_sensor_info_list.add_interval(client_id, interval, is_processor))
return false;
- cur_min = m_plugin_info_list.get_min_interval();
+ cur_min = m_sensor_info_list.get_min_interval();
if (cur_min != prev_min) {
_I("Min interval for sensor[0x%llx] is changed from %dms to %dms"
bool sensor_base::delete_interval(int client_id, bool is_processor)
{
unsigned int prev_min, cur_min;
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_min = m_plugin_info_list.get_min_interval();
+ prev_min = m_sensor_info_list.get_min_interval();
- if (!m_plugin_info_list.delete_interval(client_id, is_processor))
+ if (!m_sensor_info_list.delete_interval(client_id, is_processor))
return false;
- cur_min = m_plugin_info_list.get_min_interval();
+ cur_min = m_sensor_info_list.get_min_interval();
if (!cur_min) {
_I("No interval for sensor[0x%llx] by%sclient[%d] deleting interval, "
unsigned int sensor_base::get_interval(int client_id, bool is_processor)
{
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- return m_plugin_info_list.get_interval(client_id, is_processor);
+ return m_sensor_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);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_max = m_plugin_info_list.get_max_batch();
+ prev_max = m_sensor_info_list.get_max_batch();
- if (!m_plugin_info_list.add_batch(client_id, latency))
+ if (!m_sensor_info_list.add_batch(client_id, latency))
return false;
- cur_max = m_plugin_info_list.get_max_batch();
+ cur_max = m_sensor_info_list.get_max_batch();
if (cur_max != prev_max) {
_I("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] adding latency",
bool sensor_base::delete_batch(int client_id)
{
unsigned int prev_max, cur_max;
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_max = m_plugin_info_list.get_max_batch();
+ prev_max = m_sensor_info_list.get_max_batch();
- if (!m_plugin_info_list.delete_batch(client_id))
+ if (!m_sensor_info_list.delete_batch(client_id))
return false;
- cur_max = m_plugin_info_list.get_max_batch();
+ cur_max = m_sensor_info_list.get_max_batch();
if (!cur_max) {
_I("No latency for sensor[0x%llx] by client[%d] deleting latency, so set to default 0 ms",
unsigned int sensor_base::get_batch(int client_id)
{
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- return m_plugin_info_list.get_batch(client_id);
+ return m_sensor_info_list.get_batch(client_id);
}
bool sensor_base::add_wakeup(int client_id, int wakeup)
{
int prev_wakeup, cur_wakeup;
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_wakeup = m_plugin_info_list.is_wakeup_on();
+ prev_wakeup = m_sensor_info_list.is_wakeup_on();
- if (!m_plugin_info_list.add_wakeup(client_id, wakeup))
+ if (!m_sensor_info_list.add_wakeup(client_id, wakeup))
return false;
- cur_wakeup = m_plugin_info_list.is_wakeup_on();
+ cur_wakeup = m_sensor_info_list.is_wakeup_on();
if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) {
_I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] adding wakeup",
bool sensor_base::delete_wakeup(int client_id)
{
int prev_wakeup, cur_wakeup;
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- prev_wakeup = m_plugin_info_list.is_wakeup_on();
+ prev_wakeup = m_sensor_info_list.is_wakeup_on();
- if (!m_plugin_info_list.delete_wakeup(client_id))
+ if (!m_sensor_info_list.delete_wakeup(client_id))
return false;
- cur_wakeup = m_plugin_info_list.is_wakeup_on();
+ cur_wakeup = m_sensor_info_list.is_wakeup_on();
if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) {
_I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] deleting wakeup",
int sensor_base::get_wakeup(int client_id)
{
- AUTOLOCK(m_plugin_info_list_mutex);
+ AUTOLOCK(m_sensor_info_list_mutex);
- return m_plugin_info_list.is_wakeup_on();
+ return m_sensor_info_list.is_wakeup_on();
}
bool sensor_base::is_wakeup_supported(void)
return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
}
-
#ifndef _SENSOR_BASE_H_
#define _SENSOR_BASE_H_
-#include <vector>
#include <sensor_types.h>
-#include <plugin_info_list.h>
+#include <sensor_info_list.h>
#include <cmutex.h>
#include <sensor_log.h>
#include <worker_thread.h>
#include <sensor_info.h>
#include <sensor_hal.h>
+#include <vector>
class sensor_base {
public:
virtual sensor_type_t get_type();
virtual unsigned int get_event_type(void);
virtual const char* get_name(void);
+ virtual bool is_virtual(void);
virtual bool get_sensor_info(sensor_info &info);
- virtual bool is_virtual(void);
/* set/get data */
virtual int get_data(sensor_data_t **data, int *length);
bool is_started(void);
/* interval / batch / wakeup */
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
+ virtual bool add_interval(int client_id, unsigned int interval, bool is_processor);
+ virtual bool delete_interval(int client_id, bool is_processor);
unsigned int get_interval(int client_id, bool is_processor);
- bool add_batch(int client_id, unsigned int latency);
- bool delete_batch(int client_id);
+ virtual bool add_batch(int client_id, unsigned int latency);
+ virtual 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);
+ virtual bool add_wakeup(int client_id, int wakeup);
+ virtual bool delete_wakeup(int client_id);
int get_wakeup(int client_id);
bool is_wakeup_supported(void);
void set_permission(int permission);
private:
- sensor_id_t m_unique_id;
+ sensor_id_t m_id;
int m_permission;
- plugin_info_list m_plugin_info_list;
- cmutex m_plugin_info_list_mutex;
+ sensor_info_list m_sensor_info_list;
+ cmutex m_sensor_info_list_mutex;
bool m_started;
unsigned int m_client;
*
*/
+#include <sensor_common.h>
#include <command_common.h>
#include <sensor_event_dispatcher.h>
#include <sensor_log.h>
#define MAX_PENDING_CONNECTION 32
sensor_event_dispatcher::sensor_event_dispatcher()
-: m_lcd_on(false)
{
}
}
}
-
-bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor * sensor)
+bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor *sensor)
{
AUTOLOCK(m_active_virtual_sensors_mutex);
return true;
}
-bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor * sensor)
+bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor *sensor)
{
AUTOLOCK(m_active_virtual_sensors_mutex);
#ifndef _SENSOR_EVENT_DISPATCHER_H_
#define _SENSOR_EVENT_DISPATCHER_H_
+#include <sensor_common.h>
#include <sensor_event_queue.h>
#include <client_info_manager.h>
#include <csocket.h>
#include <list>
#include <vector>
-
typedef std::unordered_map<unsigned int, sensor_event_t> event_type_last_event_map;
typedef std::list<virtual_sensor *> virtual_sensors;
class sensor_event_dispatcher {
private:
- bool m_lcd_on;
csocket m_accept_socket;
cmutex m_mutex;
cmutex m_last_events_mutex;
#include <sensor_loader.h>
#include <algorithm>
-#define EPOLL_MAX_FD 32
-
sensor_event_poller::sensor_event_poller()
{
init_sensor_map();
*/
#include <sensor_event_queue.h>
-#include "sensor_log.h"
+#include <sensor_log.h>
sensor_event_queue& sensor_event_queue::get_instance()
{
typedef std::lock_guard<std::mutex> lock;
typedef std::unique_lock<std::mutex> ulock;
- sensor_event_queue() {};
- ~sensor_event_queue() {};
- sensor_event_queue(const sensor_event_queue &) {};
+ sensor_event_queue() {}
+ ~sensor_event_queue() {}
+ sensor_event_queue(const sensor_event_queue &) {}
sensor_event_queue& operator=(const sensor_event_queue &);
void push_internal(void *event);
public:
*
*/
-#include <plugin_info_list.h>
+#include <sensor_info_list.h>
#include <algorithm>
-
-cinterval_info::cinterval_info(int client_id, bool is_processor, unsigned int interval)
+interval_info::interval_info(int client_id, bool is_processor, unsigned int interval)
{
this->client_id = client_id;
this->is_processor = is_processor;
this->interval = interval;
}
-cbatch_info::cbatch_info(int client_id, unsigned int latency)
+batch_info::batch_info(int client_id, unsigned int latency)
{
this->client_id = client_id;
this->latency = latency;
}
-cwakeup_info::cwakeup_info(int client_id, int wakeup)
+wakeup_info::wakeup_info(int client_id, int wakeup)
{
this->client_id = client_id;
this->wakeup = wakeup;
}
-bool plugin_info_list::comp_interval_info(cinterval_info a, cinterval_info b)
+bool sensor_info_list::comp_interval_info(interval_info a, interval_info b)
{
return a.interval < b.interval;
}
-bool plugin_info_list::comp_batch_info(cbatch_info a, cbatch_info b)
+bool sensor_info_list::comp_batch_info(batch_info a, batch_info b)
{
return a.latency < b.latency;
}
-cinterval_info_iterator plugin_info_list::find_if_interval_info(int client_id, bool is_processor)
+interval_info_iterator sensor_info_list::find_if_interval_info(int client_id, bool is_processor)
{
auto iter = m_interval_info_list.begin();
return iter;
}
-cbatch_info_iterator plugin_info_list::find_if_batch_info(int client_id)
+batch_info_iterator sensor_info_list::find_if_batch_info(int client_id)
{
auto iter = m_batch_info_list.begin();
return iter;
}
-cwakeup_info_iterator plugin_info_list::find_if_wakeup_info(int client_id)
+wakeup_info_iterator sensor_info_list::find_if_wakeup_info(int client_id)
{
auto iter = m_wakeup_info_list.begin();
return iter;
}
-bool plugin_info_list::add_interval(int client_id, unsigned int interval, bool is_processor)
+bool sensor_info_list::add_interval(int client_id, unsigned int interval, bool is_processor)
{
auto iter = find_if_interval_info(client_id, is_processor);
if (iter != m_interval_info_list.end())
- *iter = cinterval_info(client_id, is_processor, interval);
+ *iter = interval_info(client_id, is_processor, interval);
else
- m_interval_info_list.push_back(cinterval_info(client_id, is_processor, interval));
+ m_interval_info_list.push_back(interval_info(client_id, is_processor, interval));
return true;
}
-bool plugin_info_list::delete_interval(int client_id, bool is_processor)
+bool sensor_info_list::delete_interval(int client_id, bool is_processor)
{
auto iter = find_if_interval_info(client_id, is_processor);
return true;
}
-unsigned int plugin_info_list::get_interval(int client_id, bool is_processor)
+unsigned int sensor_info_list::get_interval(int client_id, bool is_processor)
{
auto iter = find_if_interval_info(client_id, is_processor);
return iter->interval;
}
-unsigned int plugin_info_list::get_min_interval(void)
+unsigned int sensor_info_list::get_min_interval(void)
{
if (m_interval_info_list.empty())
return 0;
return iter->interval;
}
-bool plugin_info_list::add_batch(int client_id, unsigned int latency)
+bool sensor_info_list::add_batch(int client_id, unsigned int latency)
{
auto iter = find_if_batch_info(client_id);
if (iter != m_batch_info_list.end())
- *iter = cbatch_info(client_id, latency);
+ *iter = batch_info(client_id, latency);
else
- m_batch_info_list.push_back(cbatch_info(client_id, latency));
+ m_batch_info_list.push_back(batch_info(client_id, latency));
return true;
}
-bool plugin_info_list::delete_batch(int client_id)
+bool sensor_info_list::delete_batch(int client_id)
{
auto iter = find_if_batch_info(client_id);
return true;
}
-unsigned int plugin_info_list::get_batch(int client_id)
+unsigned int sensor_info_list::get_batch(int client_id)
{
auto iter = find_if_batch_info(client_id);
return iter->latency;
}
-unsigned int plugin_info_list::get_max_batch(void)
+unsigned int sensor_info_list::get_max_batch(void)
{
if (m_batch_info_list.empty())
return 0;
return iter->latency;
}
-bool plugin_info_list::add_wakeup(int client_id, int wakeup)
+bool sensor_info_list::add_wakeup(int client_id, int wakeup)
{
auto iter = find_if_wakeup_info(client_id);
if (iter != m_wakeup_info_list.end())
- *iter = cwakeup_info(client_id, wakeup);
+ *iter = wakeup_info(client_id, wakeup);
else
- m_wakeup_info_list.push_back(cwakeup_info(client_id, wakeup));
+ m_wakeup_info_list.push_back(wakeup_info(client_id, wakeup));
return true;
}
-bool plugin_info_list::delete_wakeup(int client_id)
+bool sensor_info_list::delete_wakeup(int client_id)
{
auto iter = find_if_wakeup_info(client_id);
return true;
}
-int plugin_info_list::get_wakeup(int client_id)
+int sensor_info_list::get_wakeup(int client_id)
{
auto iter = find_if_wakeup_info(client_id);
return iter->wakeup;
}
-int plugin_info_list::is_wakeup_on(void)
+int sensor_info_list::is_wakeup_on(void)
{
if (m_wakeup_info_list.empty())
return -1;
*
*/
-#ifndef _PLUGIN_INFO_LIST_H_
-#define _PLUGIN_INFO_LIST_H_
+#ifndef _SENSOR_INFO_LIST_H_
+#define _SENSOR_INFO_LIST_H_
#include <list>
-class cinterval_info {
+class interval_info {
public:
- cinterval_info(int client_id, bool is_processor, unsigned int interval);
+ interval_info(int client_id, bool is_processor, unsigned int interval);
int client_id;
bool is_processor;
unsigned int interval;
};
-typedef std::list<cinterval_info>::iterator cinterval_info_iterator;
+typedef std::list<interval_info>::iterator interval_info_iterator;
-class cbatch_info {
+class batch_info {
public:
- cbatch_info(int client_id, unsigned int latency);
+ batch_info(int client_id, unsigned int latency);
int client_id;
unsigned int latency;
};
-typedef std::list<cbatch_info>::iterator cbatch_info_iterator;
+typedef std::list<batch_info>::iterator batch_info_iterator;
-class cwakeup_info {
+class wakeup_info {
public:
- cwakeup_info(int client_id, int wakeup);
+ wakeup_info(int client_id, int wakeup);
int client_id;
int wakeup;
};
-typedef std::list<cwakeup_info>::iterator cwakeup_info_iterator;
-
-class plugin_info_list {
-private:
- static bool comp_interval_info(cinterval_info a, cinterval_info b);
- cinterval_info_iterator find_if_interval_info(int client_id, bool is_processor);
-
- static bool comp_batch_info(cbatch_info a, cbatch_info b);
- cbatch_info_iterator find_if_batch_info(int client_id);
-
- cwakeup_info_iterator find_if_wakeup_info(int client_id);
-
- std::list<cinterval_info> m_interval_info_list;
- std::list<cbatch_info> m_batch_info_list;
- std::list<cwakeup_info> m_wakeup_info_list;
+typedef std::list<wakeup_info>::iterator wakeup_info_iterator;
+class sensor_info_list {
public:
bool add_interval(int client_id, unsigned int interval, bool is_processor);
bool delete_interval(int client_id, bool is_processor);
bool delete_wakeup(int client_id);
int get_wakeup(int client_id);
int is_wakeup_on(void);
+
+private:
+ static bool comp_interval_info(interval_info a, interval_info b);
+ interval_info_iterator find_if_interval_info(int client_id, bool is_processor);
+
+ static bool comp_batch_info(batch_info a, batch_info b);
+ batch_info_iterator find_if_batch_info(int client_id);
+
+ wakeup_info_iterator find_if_wakeup_info(int client_id);
+
+ std::list<interval_info> m_interval_info_list;
+ std::list<batch_info> m_batch_info_list;
+ std::list<wakeup_info> m_wakeup_info_list;
};
-#endif /* _PLUGIN_INFO_LIST_H_ */
+#endif /* _SENSOR_INFO_LIST_H_ */
*
*/
+#include <dlfcn.h>
+#include <dirent.h>
+#include <sensor_common.h>
#include <sensor_loader.h>
-#include <libxml/xmlmemory.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_log.h>
+#include <physical_sensor.h>
+#include <virtual_sensor.h>
#include <unordered_set>
#include <algorithm>
using std::vector;
using std::string;
-#define DEVICE_PLUGINS_DIR_PATH "/usr/lib/sensor"
-#define SENSOR_TYPE_SHIFT 32
-#define SENSOR_INDEX_MASK 0xFFFFFFFF
+#define DEVICE_HAL_DIR_PATH "/usr/lib/sensor"
sensor_loader::sensor_loader()
{
bool sensor_loader::load(void)
{
- std::vector<string> device_plugin_paths;
- std::vector<string> unique_device_plugin_paths;
+ std::vector<string> device_hal_paths;
+ std::vector<string> unique_device_hal_paths;
- get_paths_from_dir(string(DEVICE_PLUGINS_DIR_PATH), device_plugin_paths);
+ get_paths_from_dir(string(DEVICE_HAL_DIR_PATH), device_hal_paths);
std::unordered_set<string> s;
auto unique = [&s](vector<string> &paths, const string &path) {
paths.push_back(path);
};
- for_each(device_plugin_paths.begin(), device_plugin_paths.end(),
+ for_each(device_hal_paths.begin(), device_hal_paths.end(),
[&](const string &path) {
- unique(unique_device_plugin_paths, path);
+ unique(unique_device_hal_paths, path);
}
);
- for_each(unique_device_plugin_paths.begin(), unique_device_plugin_paths.end(),
+ for_each(unique_device_hal_paths.begin(), unique_device_hal_paths.end(),
[&](const string &path) {
void *handle;
load_sensor_devices(path, handle);
bool sensor_loader::load_sensor_devices(const string &path, void* &handle)
{
sensor_device_t *_devices = NULL;
- sensor_device *device;
+ sensor_device *device = NULL;
const sensor_info_t *infos;
_I("load device: [%s]", path.c_str());
continue;
}
- sensor = reinterpret_cast<physical_sensor *>(create_sensor<_sensor>());
+ sensor = dynamic_cast<physical_sensor *>(create_sensor<_sensor>());
if (!sensor) {
_E("Memory allocation failed[%s]", info->name);
m_devices[info] = NULL;
}
- return;
}
template <typename _sensor>
sensor_type_t type;
virtual_sensor *instance;
- instance = reinterpret_cast<virtual_sensor *>(create_sensor<_sensor>());
+ instance = dynamic_cast<virtual_sensor *>(create_sensor<_sensor>());
if (!instance) {
_E("Memory allocation failed[%s]", name);
return;
_I("===============================================\n");
}
-bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &plugin_paths)
+bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &hal_paths)
{
DIR *dir = NULL;
struct dirent *dir_entry = NULL;
string name;
- while ((dir_entry = readdir(dir))) {
+ while (dir_entry = readdir(dir)) {
name = string(dir_entry->d_name);
if (name == "." || name == "..")
continue;
- plugin_paths.push_back(dir_path + "/" + name);
+ hal_paths.push_back(dir_path + "/" + name);
}
closedir(dir);
sensor_base* sensor_loader::get_sensor(sensor_type_t type)
{
- auto it_plugins = m_sensors.find(type);
+ auto it = m_sensors.find(type);
- if (it_plugins == m_sensors.end())
+ if (it == m_sensors.end())
return NULL;
- return it_plugins->second.get();
+ return it->second.get();
}
sensor_base* sensor_loader::get_sensor(sensor_id_t id)
vector<sensor_base *> virtual_list;
sensor_base* sensor;
- for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) {
- sensor = sensor_it->second.get();
+ for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
+ sensor = it->second.get();
- if (sensor && sensor->is_virtual() == true) {
- virtual_list.push_back(sensor);
- }
+ if (!sensor || !sensor->is_virtual())
+ continue;
+
+ virtual_list.push_back(sensor);
}
return virtual_list;
*
*/
-#ifndef _SENSOR_PLUGIN_LOADER_H_
-#define _SENSOR_PLUGIN_LOADER_H_
+#ifndef _SENSOR_LOADER_H_
+#define _SENSOR_LOADER_H_
#include <sensor_common.h>
#include <sensor_types.h>
#include <map>
#include <set>
#include <memory>
-#include <physical_sensor.h>
-#include <virtual_sensor.h>
class sensor_base;
template <typename _sensor> sensor_base* create_sensor(void);
void show_sensor_info(void);
- bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &plugin_paths);
+ bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &hal_paths);
sensor_map_t m_sensors;
sensor_device_map_t m_devices;
std::vector<sensor_base *> get_sensors(sensor_type_t type);
std::vector<sensor_base *> get_virtual_sensors(void);
};
-#endif /* _SENSOR_PLUGIN_LOADER_H_ */
+#endif /* _SENSOR_LOADER_H_ */
*
*/
-#include <sensor_internal.h>
+#include <sensor_common.h>
+#include <sensor_types.h>
#include <sensor_usage.h>
#include <sensor_log.h>
}
if (sd_listen_fds(fd_env) < 0) {
- ERR("Failed to listen fds from systemd");
+ _E("Failed to listen fds from systemd");
return -1;
}
#include <csocket.h>
class server {
+public:
+ void run(void);
+ void stop(void);
+ static server& get_instance();
+
private:
GMainLoop *m_mainloop;
csocket m_command_channel_accept_socket;
void accept_event_channel(void);
int get_systemd_socket(const char *name);
-public:
- void run(void);
- void stop(void);
- static server& get_instance();
};
#endif /* _SERVER_H_ */
virtual_sensor::virtual_sensor()
-: m_hardware_fusion(false)
{
}
bool deactivate(void);
private:
- bool m_hardware_fusion;
-
virtual bool set_interval(unsigned long interval) = 0;
virtual bool set_batch_latency(unsigned long latency) = 0;
virtual bool set_wakeup(int wakeup) = 0;
#ifndef _COMMAND_COMMON_H_
#define _COMMAND_COMMON_H_
+#include <cpacket.h>
#include <sensor_common.h>
-#define COMMAND_CHANNEL_PATH "/tmp/sensord_command_socket"
-#define EVENT_CHANNEL_PATH "/tmp/sensord_event_socket"
+#define COMMAND_CHANNEL_PATH "/tmp/sensord_command_socket"
+#define EVENT_CHANNEL_PATH "/tmp/sensord_event_socket"
#define MAX_HANDLE 256
#define MAX_HANDLE_REACHED -2
enum packet_type_t {
+ CMD_DONE = -1,
CMD_NONE = 0,
CMD_GET_ID,
CMD_GET_SENSOR_LIST,
CMD_HELLO,
CMD_BYEBYE,
- CMD_DONE,
CMD_START,
CMD_STOP,
CMD_REG,
#ifndef _CPACKET_H_
#define _CPACKET_H_
+#include <stddef.h>
+
typedef struct packet_header {
int cmd;
size_t size;
*
*/
+#include <sensor_log.h>
#include <csocket.h>
#include <attr/xattr.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-#include "sensor_log.h"
+#include <sensor_log.h>
class csocket {
public:
#define EPOLL_MAX 32
poller::poller()
+: m_epfd(-1)
{
init_poll_fd();
}
poller::poller(int fd)
+: m_epfd(-1)
{
init_poll_fd();
add_fd(fd);
m_event_queue.pop();
if (event.events & EPOLLERR) {
- _D("Poll error!");
+ _E("Poll error!");
return false;
}
#ifndef __SENSOR_COMMON_H__
#define __SENSOR_COMMON_H__
+#include <stddef.h>
+#include <stdint.h>
#include <sensor_hal.h>
#include <sensor_types.h>
-#include <stdint.h>
-#define CLIENT_ID_INVALID -1
+#define OP_ERROR -1
+#define OP_SUCCESS 0
+
+#define CLIENT_ID_INVALID -1
+#define SENSOR_ID_INVALID -1
+
+#define SENSOR_TYPE_SHIFT 32
+#define SENSOR_INDEX_MASK 0xFFFFFFFF
#ifndef NAME_MAX
#define NAME_MAX 256
#include <vector>
typedef std::vector<unsigned int> event_type_vector;
-#endif
+#endif /* __cplusplus */
#endif /* __SENSOR_COMMON_H__ */
return m_max_batch_count;
}
-unsigned int sensor_info::get_supported_event()
+unsigned int sensor_info::get_supported_event(void)
{
return m_supported_event;
}
_I("Min_interval = %d", m_min_interval);
_I("Fifo_count = %d", m_fifo_count);
_I("Max_batch_count = %d", m_max_batch_count);
- _I("supported_event = 0x%x", m_supported_event);
-
+ _I("Supported_event = 0x%x", m_supported_event);
_I("Wakeup_supported = %d", m_wakeup_supported);
}
{
char buffer[sizeof(value)];
- int *temp = (int *) buffer;
+ int *temp = (int *)buffer;
*temp = value;
copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
{
char buffer[sizeof(value)];
- unsigned int *temp = (unsigned int *) buffer;
+ unsigned int *temp = (unsigned int *)buffer;
*temp = value;
copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
int get_min_interval(void);
int get_fifo_count(void);
int get_max_batch_count(void);
- unsigned int get_supported_event();
+ unsigned int get_supported_event(void);
bool is_supported_event(unsigned int event);
bool is_wakeup_supported(void);
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
+#include <sensor_log.h>
#include <dlog.h>
+#include <stddef.h>
#include <sensor_common.h>
-#include "sensor_log.h"
+#include <sensor_types.h>
#define PATH_MAX 256
*
*/
-#ifndef _SENSOR_LOGS_H_
-#define _SENSOR_LOGS_H_
+#ifndef _SENSOR_LOG_H_
+#define _SENSOR_LOG_H_
-#include <dlog.h>
+#include <dlog/dlog.h>
#include <sys/types.h>
#define EVENT_TYPE_SHIFT 16
#endif
#define LOG_TAG "SENSOR"
+#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while(0)
+
#ifdef _DEBUG
#define DBG SLOGD
#else
}
#endif
-#endif /* _SENSOR_LOGS_H_ */
+#endif /* _SENSOR_LOG_H_ */
ULTRAVIOLET_SENSOR,
TEMPERATURE_SENSOR,
HUMIDITY_SENSOR,
- BIO_HRM_SENSOR,
- BIO_LED_GREEN_SENSOR,
- BIO_LED_IR_SENSOR,
- BIO_LED_RED_SENSOR,
+ HRM_SENSOR,
+ BIO_HRM_SENSOR = HRM_SENSOR,
+ HRM_LED_GREEN_SENSOR,
+ BIO_LED_GREEN_SENSOR = HRM_LED_GREEN_SENSOR,
+ HRM_LED_IR_SENSOR,
+ BIO_LED_IR_SENSOR = HRM_LED_IR_SENSOR,
+ HRM_LED_RED_SENSOR,
+ BIO_LED_RED_SENSOR = HRM_LED_RED_SENSOR,
GYROSCOPE_UNCAL_SENSOR,
- UNCAL_GEOMAGNETIC_SENSOR,
- GAMING_RV_SENSOR,
+ GEOMAGNETIC_UNCAL_SENSOR,
+ GYROSCOPE_RV_SENSOR,
GEOMAGNETIC_RV_SENSOR,
- ACTIVITY_STATIONARY_SENSOR = 0x1100,
- ACTIVITY_WALK_SENSOR,
- ACTIVITY_RUN_SENSOR,
- ACTIVITY_IN_VEHICLE_SENSOR,
- ACTIVITY_ON_BICYCLE_SENSOR,
-
- GESTURE_MOVEMENT_SENSOR = 0x1200,
- GESTURE_WRIST_UP_SENSOR,
- GESTURE_WRIST_DOWN_SENSOR,
-
HUMAN_PEDOMETER_SENSOR = 0x300,
HUMAN_SLEEP_MONITOR_SENSOR,
THERMOMETER_SENSOR,
PEDOMETER_SENSOR,
FLAT_SENSOR,
- BIO_SENSOR,
+ HRM_RAW_SENSOR,
+ BIO_SENSOR = HRM_RAW_SENSOR,
TILT_SENSOR,
RV_RAW_SENSOR,
+
+ ACTIVITY_STATIONARY_SENSOR = 0x1100,
+ ACTIVITY_WALK_SENSOR,
+ ACTIVITY_RUN_SENSOR,
+ ACTIVITY_IN_VEHICLE_SENSOR,
+ ACTIVITY_ON_BICYCLE_SENSOR,
+
+ GESTURE_MOVEMENT_SENSOR = 0x1200,
+ GESTURE_WRIST_UP_SENSOR,
+ GESTURE_WRIST_DOWN_SENSOR,
} sensor_type_t;
// Sensor Event Types
BIO_LED_RED_RAW_DATA_EVENT = (BIO_LED_RED_SENSOR << 16) | 0x0001,
- GAMING_RV_RAW_DATA_EVENT = (GAMING_RV_SENSOR << 16) | 0x0001,
+ GAMING_RV_RAW_DATA_EVENT = (GYROSCOPE_RV_SENSOR << 16) | 0x0001,
GEOMAGNETIC_RV_RAW_DATA_EVENT = (GEOMAGNETIC_RV_SENSOR << 16) | 0x0001,
}
#endif
+#include <sensor_deprecated.h>
+
#endif /* _SENSOR_TYPES_H_ */
case(GEOMAGNETIC_RV_SENSOR):
printf("Geomagnetic Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]);
break;
- case(GAMING_RV_SENSOR):
+ case(GYROSCOPE_RV_SENSOR):
printf("Gaming Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]);
break;
case(GYROSCOPE_UNCAL_SENSOR):
if (strcmp(str, "RAW_DATA_EVENT") == 0)
return GEOMAGNETIC_RV_RAW_DATA_EVENT;
break;
- case GAMING_RV_SENSOR:
+ case GYROSCOPE_RV_SENSOR:
if (strcmp(str, "RAW_DATA_EVENT") == 0)
return GAMING_RV_RAW_DATA_EVENT;
break;
case GEOMAGNETIC_RV_SENSOR:
printf("Geomagnetic RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]);
break;
- case GAMING_RV_SENSOR:
+ case GYROSCOPE_RV_SENSOR:
printf("Gaming RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]);
break;
case GYROSCOPE_UNCAL_SENSOR:
event = GEOMAGNETIC_RV_RAW_DATA_EVENT;
}
else if (strcmp(argv[1], "gaming_rv") == 0) {
- sensor_type = GAMING_RV_SENSOR;
+ sensor_type = GYROSCOPE_RV_SENSOR;
event = GAMING_RV_RAW_DATA_EVENT;
}
else if (strcmp(argv[1], "light") == 0) {