SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
-SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,--gc-sections -Wl,--print-gc-sections")
SET(CMAKE_VERBOSE_MAKEFILE OFF)
MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
ADD_SUBDIRECTORY(src/client)
ADD_SUBDIRECTORY(src/client-dummy)
ADD_SUBDIRECTORY(src/sensorctl)
-ADD_SUBDIRECTORY(src/sensor)
+ADD_SUBDIRECTORY(src/physical-sensor)
+ADD_SUBDIRECTORY(src/fusion-sensor)
INSTALL(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor
FILES_MATCHING PATTERN "*.h"
)
-INSTALL(
- FILES sensor.conf DESTINATION /etc/dbus-1/system.d
-)
#include <string>
#include <sensor_types.h>
+#include "sensor_hal.h"
+
#ifndef SENSOR_VERSION
#define PHYSICAL_SENSOR_VERSION(maj, min) \
((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
#endif
#ifndef OP_SUCCESS
-#define OP_SUCCESS 1
+#define OP_SUCCESS 0
#endif
#ifndef OP_ERROR
#define OP_ERROR -1
inline uint32_t get_version(void) { return PHYSICAL_SENSOR_VERSION(1, 0); }
- /* TODO */
+ virtual std::string get_uri(void) { return ""; }
virtual std::string get_privilege(void) { return ""; }
- virtual int start(observer_h ob) = 0;
- virtual int stop(observer_h ob) = 0;
+ virtual physical_sensor *clone(void) const = 0;
+ virtual void set_device(sensor_device *device) { return; }
+
+ virtual int start(observer_h ob)
+ {
+ return OP_DEFAULT;
+ }
+
+ virtual int stop(observer_h ob)
+ {
+ return OP_DEFAULT;
+ }
+
virtual int set_interval(observer_h ob, uint32_t interval)
{
return OP_DEFAULT;
#include <stdint.h>
#include <stdbool.h>
+#include <time.h>
#define SENSOR_HAL_VERSION(maj, min) \
((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
SENSOR_DEVICE_GYROSCOPE_RV,
SENSOR_DEVICE_GEOMAGNETIC_RV,
+ SENSOR_DEVICE_SIGNIFICANT_MOTION = 0x100,
+
SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR,
SENSOR_DEVICE_EXERCISE_ROWING,
SENSOR_DEVICE_EXERCISE_STEPPER,
+ SENSOR_DEVICE_DATA_JOURNAL = 0x500,
+
SENSOR_DEVICE_FUSION = 0x900,
SENSOR_DEVICE_AUTO_ROTATION,
SENSOR_DEVICE_AUTO_BRIGHTNESS,
+ SENSOR_DEVICE_MYOTEST,
SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200,
SENSOR_DEVICE_GESTURE_WRIST_UP,
SENSOR_DEVICE_GESTURE_WRIST_DOWN,
SENSOR_DEVICE_GESTURE_MOVEMENT_STATE,
+ SENSOR_DEVICE_GESTURE_PICK_UP,
+ SENSOR_DEVICE_GESTURE_FACE_DOWN,
SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00,
SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR,
SENSOR_DEVICE_GPS_BATCH,
+ SENSOR_DEVICE_PPG_BATCH,
+ SENSOR_DEVICE_GPS_TIMESYNC,
SENSOR_DEVICE_HRM_CTRL = 0x1A80,
+ SENSOR_DEVICE_REG_CTRL,
+ SENSOR_DEVICE_GPS_CTRL,
SENSOR_DEVICE_WEAR_STATUS = 0x2000,
SENSOR_DEVICE_WEAR_ON_MONITOR,
SENSOR_DEVICE_PRESSURE_INDICATOR,
SENSOR_DEVICE_PRESSURE_ALERT,
SENSOR_DEVICE_HR_CALORIE,
+ SENSOR_DEVICE_SWIMMING_TRACKER,
+ SENSOR_DEVICE_STRESS_TRACKER,
+ SENSOR_DEVICE_FAKE_MOTION,
+ SENSOR_DEVICE_GEOFENCE,
+ SENSOR_DEVICE_SWIMMING_OUTDOOR,
+ SENSOR_DEVICE_AUTO_SWIMMING,
+ SENSOR_DEVICE_INACTIVITY_DETECTOR,
+ SENSOR_DEVICE_HRM_BP,
+ SENSOR_DEVICE_ECG,
+ SENSOR_DEVICE_FALL_DETECTION,
SENSOR_DEVICE_CONTEXT = 0x7000,
SENSOR_DEVICE_MOTION,
SENSOR_DEVICE_GSR,
SENSOR_DEVICE_SIMSENSE,
SENSOR_DEVICE_PPG,
+
} sensor_device_type;
/*
SENSOR_ATTR_PEDOMETER_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1),
SENSOR_ATTR_PEDOMETER_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2),
SENSOR_ATTR_PEDOMETER_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3),
+ SENSOR_ATTR_PEDOMETER_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x4),
+ SENSOR_ATTR_PEDOMETER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2F),
SENSOR_ATTR_STRESS_MONITOR_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1),
SENSOR_ATTR_CYCLE_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1),
SENSOR_ATTR_CYCLE_HOLDING_POSITION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2),
SENSOR_ATTR_CYCLE_VELOCITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3),
+ SENSOR_ATTR_CYCLE_GET_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x4),
+ SENSOR_ATTR_CYCLE_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x5),
+ SENSOR_ATTR_CYCLE_GPS_AGREEMENT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x6),
SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1),
SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2),
SENSOR_ATTR_RESTING_HR_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20),
SENSOR_ATTR_RESTING_HR_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21),
+ SENSOR_ATTR_STEP_LEVEL_MONITOR_DW_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STEP_LEVEL_MONITOR, 0x1),
+
SENSOR_ATTR_EXERCISE_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1),
SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2),
SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3),
SENSOR_ATTR_EXERCISE_HR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4),
+ SENSOR_ATTR_EXERCISE_HR_ELEVATED_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x5),
+ SENSOR_ATTR_EXERCISE_HR_ELEVATED_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x6),
+ SENSOR_ATTR_EXERCISE_HR_BPM_RAW = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x7),
+ SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x8),
+ SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x9),
SENSOR_ATTR_PRESSURE_INDICATOR_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1),
SENSOR_ATTR_PRESSURE_INDICATOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2),
SENSOR_ATTR_HR_CALORIE_TARGET_CAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12),
SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13),
SENSOR_ATTR_HR_CALORIE_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20),
+
+ SENSOR_ATTR_SWIMMING_TRACKER_PLACE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x1),
+ SENSOR_ATTR_SWIMMING_TRACKER_DISTANCE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x2),
+ SENSOR_ATTR_SWIMMING_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x3),
+ SENSOR_ATTR_SWIMMING_TRACKER_BATCH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x4),
+ SENSOR_ATTR_SWIMMING_TRACKER_GOAL_CALORIES = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x5),
+ SENSOR_ATTR_SWIMMING_TRACKER_GOAL_LAPS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x6),
+ SENSOR_ATTR_SWIMMING_TRACKER_TIME_REST = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x7),
+ SENSOR_ATTR_SWIMMING_TRACKER_TIME_TURN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x8),
+
+ SENSOR_ATTR_SWIMMING_OUTDOOR_SET_BATCH_LAP_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x1),
+ SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_LENGTH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x2),
+ SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x3),
+ SENSOR_ATTR_SWIMMING_OUTDOOR_SET_GPS_PERMISSION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x4),
+ SENSOR_ATTR_SWIMMING_OUTDOOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x6),
+
+ SENSOR_ATTR_AUTO_SWIMMING_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_AUTO_SWIMMING, 0x1),
+
+ SENSOR_ATTR_INACTIVITY_DETECTOR_LEVEL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x1),
+ SENSOR_ATTR_INACTIVITY_DETECTOR_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x2),
+
+ SENSOR_ATTR_STRESS_TRACKER_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x1),
+ SENSOR_ATTR_STRESS_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x2),
+
+ SENSOR_ATTR_STRESS_MONITOR_BASE_HR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1),
+ SENSOR_ATTR_STRESS_MONITOR_HISTO_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x2),
+ SENSOR_ATTR_STRESS_MONITOR_HISTO_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x3),
+ SENSOR_ATTR_STRESS_MONITOR_TUNE_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x4),
+ SENSOR_ATTR_STRESS_MONITOR_TUNE_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x5),
+ SENSOR_ATTR_STRESS_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x6),
+ SENSOR_ATTR_STRESS_MONITOR_OPERATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x7),
+
+ SENSOR_ATTR_SLEEP_MONITOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x1),
+ SENSOR_ATTR_SLEEP_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x2),
+
+ SENSOR_ATTR_SLEEP_DETECTOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x1),
+ SENSOR_ATTR_SLEEP_DETECTOR_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x2),
+
+ SENSOR_ATTR_DATA_JOURNAL_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x1),
+ SENSOR_ATTR_DATA_JOURNAL_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x2),
+
+ SENSOR_ATTR_GPS_BATCH_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_BATCH, 0x1),
+
+ SENSOR_ATTR_PPG_BATCH_POLLING_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x1),
+ SENSOR_ATTR_PPG_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x2),
+
+ SENSOR_ATTR_REG_CTRL_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x1),
+ SENSOR_ATTR_REG_CTRL_ADDRESS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x2),
+ SENSOR_ATTR_REG_CTRL_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x3),
+ SENSOR_ATTR_REG_CTRL_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x4),
+
+ SENSOR_ATTR_GPS_CTRL_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_CTRL, 0x1),
+
+ SENSOR_ATTR_FAKE_MOTION_EVENT_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x1),
+ SENSOR_ATTR_FAKE_MOTION_EVENT_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x2),
+ SENSOR_ATTR_FAKE_MOTION_PAUSE_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x3),
+
+ SENSOR_ATTR_GEOFENCE_ID = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x1),
+ SENSOR_ATTR_GEOFENCE_LAT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x2),
+ SENSOR_ATTR_GEOFENCE_LON = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x3),
+ SENSOR_ATTR_GEOFENCE_RADIUS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x4),
+ SENSOR_ATTR_GEOFENCE_PROVIDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x5),
+ SENSOR_ATTR_GEOFENCE_ACCURACY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x6),
+ SENSOR_ATTR_GEOFENCE_TIMESTAMP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x7),
+ SENSOR_ATTR_GEOFENCE_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x8),
+ SENSOR_ATTR_GEOFENCE_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x10),
+ SENSOR_ATTR_GEOFENCE_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x11),
+ SENSOR_ATTR_GEOFENCE_SET_LOCATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x12),
+ SENSOR_ATTR_GEOFENCE_BT_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x13),
+
+ SENSOR_ATTR_FALL_DETECTION_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FALL_DETECTION, 0x1),
};
enum sensor_activity {
typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data);
int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data);
+typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
+int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
+
int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
/* Deprecated */
GYROSCOPE_RV_SENSOR,
GEOMAGNETIC_RV_SENSOR,
+ SIGNIFICANT_MOTION_SENSOR = 0x100,
+
HUMAN_PEDOMETER_SENSOR = 0x300,
HUMAN_SLEEP_MONITOR_SENSOR,
HUMAN_SLEEP_DETECTOR_SENSOR,
EXERCISE_ROWING_SENSOR,
EXERCISE_STEPPER_SENSOR,
+ DATA_JOURNAL_SENSOR = 0x500,
+
EXTERNAL_EXERCISE_SENSOR = 0x800,
EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR,
FUSION_SENSOR = 0x900,
AUTO_ROTATION_SENSOR,
AUTO_BRIGHTNESS_SENSOR,
+ MYOTEST_SENSOR,
GESTURE_MOVEMENT_SENSOR = 0x1200,
GESTURE_WRIST_UP_SENSOR,
GESTURE_WRIST_DOWN_SENSOR,
GESTURE_MOVEMENT_STATE_SENSOR,
+ GESTURE_PICK_UP_SENSOR,
GESTURE_FACE_DOWN_SENSOR,
ACTIVITY_TRACKER_SENSOR = 0x1A00,
ACTIVITY_LEVEL_MONITOR_SENSOR,
GPS_BATCH_SENSOR,
+ PPG_BATCH_SENSOR,
+ GPS_TIMESYNC_SENSOR,
HRM_CTRL_SENSOR = 0x1A80,
+ REG_CTRL_SENSOR,
+ GPS_CTRL_SENSOR,
WEAR_STATUS_SENSOR = 0x2000,
WEAR_ON_MONITOR_SENSOR,
PRESSURE_INDICATOR_SENSOR,
PRESSURE_ALERT_SENSOR,
HR_CALORIE_SENSOR,
+ SWIMMING_TRACKER_SENSOR,
+ STRESS_TRACKER_SENSOR,
+ FAKE_MOTION_SENSOR,
+ GEOFENCE_SENSOR,
+ SWIMMING_OUTDOOR_SENSOR,
+ AUTO_SWIMMING_SENSOR,
+ INACTIVITY_DETECTOR_SENSOR,
+ HRM_BP_SENSOR,
+ ECG_SENSOR,
+ FALL_DETECTION_SENSOR,
CONTEXT_SENSOR = 0x7000,
MOTION_SENSOR,
SmackProcessLabel=System
ExecStart=/usr/bin/sensord
MemoryLimit=20M
+Sockets=sensord.socket
+Nice=-5
[Install]
WantedBy=multi-user.target
ListenStream=/run/.sensord.socket
SocketMode=0777
PassCredentials=yes
+Accept=false
SmackLabelIPIn=*
SmackLabelIPOut=@
+Service=sensord.service
Name: sensord
Summary: Sensor daemon
-Version: 4.0.3
+Version: 4.0.54
Release: 1
Group: System/Sensor Framework
License: Apache-2.0
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(libsystemd-daemon)
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(cynara-creds-socket)
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(cynara-session)
%description -n sensor-test
Sensor functional testing
-
%prep
%setup -q
%{_libdir}/libsensor-genuine.so.*
%{_libdir}/libsensord-shared.so
%{_libdir}/sensor/fusion/libsensor-fusion.so
+%{_libdir}/sensor/physical/libsensor-physical.so
%{_bindir}/sensord
%{_unitdir}/sensord.service
%{_unitdir}/sensord.socket
%{_unitdir}/multi-user.target.wants/sensord.service
-%{_sysconfdir}/dbus-1/system.d/sensor.conf
%{_unitdir}/sockets.target.wants/sensord.socket
%license LICENSE.APLv2
+++ /dev/null
-<?xml version="1.0"?>
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-
-<policy user="root">
-<allow own="org.tizen.system.sensord"/>
-<allow send_destination="org.tizen.system.sensord"/>
-</policy>
-
-<policy group="sensor">
-<allow own="org.tizen.system.sensord"/>
-<allow send_destination="org.tizen.system.sensord"/>
-</policy>
-
-<policy context="default">
-<deny own="org.tizen.system.sensord"/>
-<deny send_destination="org.tizen.system.sensord"/>
-</policy>
-
-</busconfig>
-
#include <sensor_log.h>
#include <unordered_map>
#include <regex>
+#include <thread>
+#include <cmutex.h>
+
+#include "sensor_reader.h"
#define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
#define MAX_LISTENER 100
using namespace sensor;
+typedef struct {
+ int listener_id;
+ sensor_cb_t cb;
+ sensor_accuracy_changed_cb_t acc_cb;
+ sensor_info *sensor;
+ sensor_data_t *data;
+ void *user_data;
+} callback_info_s;
+
+static sensor::sensor_manager manager;
+static std::unordered_map<int, sensor::sensor_listener *> listeners;
+static cmutex lock;
+
+static gboolean callback_dispatcher(gpointer data)
+{
+ int event_type = 0;
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->sensor)
+ event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
+
+ if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end())
+ info->cb(info->sensor, event_type, info->data, info->user_data);
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
+static gboolean accuracy_callback_dispatcher(gpointer data)
+{
+ callback_info_s *info = (callback_info_s *)data;
+
+ AUTOLOCK(lock);
+
+ if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end())
+ info->acc_cb(info->sensor, info->data->timestamp, info->data->accuracy, info->user_data);
+
+ delete [] info->data;
+ delete info;
+ return FALSE;
+}
+
class sensor_event_handler : public ipc::channel_handler
{
public:
- sensor_event_handler(sensor_t sensor, sensor_cb_t cb, void *user_data)
- : m_sensor(reinterpret_cast<sensor_info *>(sensor))
+ sensor_event_handler(int id, sensor_t sensor, sensor_cb_t cb, void *user_data)
+ : m_listener_id(id)
+ , m_sensor(reinterpret_cast<sensor_info *>(sensor))
, m_cb(cb)
, m_user_data(user_data)
{}
void disconnected(ipc::channel *ch) {}
void read(ipc::channel *ch, ipc::message &msg)
{
- int event_type;
- sensor_data_t *data;
+ callback_info_s *info;
+ sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()];
+
+ memcpy(data, msg.body(), msg.size());
- data = reinterpret_cast<sensor_data_t *>(msg.body());
- event_type = CONVERT_TYPE_EVENT(m_sensor->get_type());
+ info = new(std::nothrow) callback_info_s();
+ info->listener_id = m_listener_id;
+ info->cb = m_cb;
+ info->sensor = m_sensor;
+ info->data = data;
+ info->user_data = m_user_data;
- m_cb(m_sensor, event_type, data, m_user_data);
+ g_idle_add(callback_dispatcher, info);
}
void read_complete(ipc::channel *ch) {}
void error_caught(ipc::channel *ch, int error) {}
private:
+ int m_listener_id;
sensor_info *m_sensor;
sensor_cb_t m_cb;
void *m_user_data;
class sensor_accuracy_handler : public ipc::channel_handler
{
public:
- sensor_accuracy_handler(sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data)
- : m_sensor(reinterpret_cast<sensor_info *>(sensor))
+ sensor_accuracy_handler(int id, sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data)
+ : m_listener_id(id)
+ , m_sensor(reinterpret_cast<sensor_info *>(sensor))
, m_cb(cb)
, m_user_data(user_data)
{}
void disconnected(ipc::channel *ch) {}
void read(ipc::channel *ch, ipc::message &msg)
{
- sensor_data_t *data;
- data = reinterpret_cast<sensor_data_t *>(msg.body());
+ callback_info_s *info;
+ sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()];
+
+ memcpy(data, msg.body(), msg.size());
+
+ info = new(std::nothrow) callback_info_s();
+ info->listener_id = m_listener_id;
+ info->acc_cb = m_cb;
+ info->sensor = m_sensor;
+ info->data = data;
+ info->user_data = m_user_data;
- m_cb(m_sensor, data->timestamp, data->accuracy, m_user_data);
+ g_idle_add(accuracy_callback_dispatcher, info);
}
void read_complete(ipc::channel *ch) {}
void error_caught(ipc::channel *ch, int error) {}
private:
+ int m_listener_id;
sensor_info *m_sensor;
sensor_accuracy_changed_cb_t m_cb;
void *m_user_data;
};
-static sensor::sensor_manager manager;
-static std::unordered_map<int, sensor::sensor_listener *> listeners;
-
/*
* TO-DO-LIST:
* 1. power save option / lcd vconf : move to server
API int sensord_connect(sensor_t sensor)
{
+ AUTOLOCK(lock);
+
retvm_if(!manager.connect(), -EIO, "Failed to connect");
retvm_if(!manager.is_supported(sensor), -EINVAL,
"Invalid sensor[%p]", sensor);
retvm_if(listeners.size() > MAX_LISTENER, -EPERM, "Exceeded the maximum listener");
sensor::sensor_listener *listener;
+ static sensor_reader reader;
- listener = new(std::nothrow) sensor::sensor_listener(sensor);
+ listener = new(std::nothrow) sensor::sensor_listener(sensor, reader.get_event_loop());
retvm_if(!listener, -ENOMEM, "Failed to allocate memory");
listeners[listener->get_id()] = listener;
+ _D("Connect[%d]", listener->get_id());
+
return listener->get_id();
}
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
listener = it->second;
retvm_if(!listener, false, "Invalid handle[%d]", handle);
+ _D("Disconnect[%d]", listener->get_id());
+
delete listener;
listeners.erase(handle);
int prev_max_batch_latency;
sensor_event_handler *handler;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return false;
}
- handler = new(std::nothrow) sensor_event_handler(listener->get_sensor(), cb, user_data);
+ handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, user_data);
if (!handler) {
listener->set_max_batch_latency(prev_max_batch_latency);
listener->set_interval(prev_interval);
listener->set_event_handler(handler);
+ _D("Register event[%d]", listener->get_id());
+
return true;
}
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
listener->unset_event_handler();
+ _D("Unregister event[%d]", listener->get_id());
+
return true;
}
sensor::sensor_listener *listener;
sensor_accuracy_handler *handler;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
listener = it->second;
- handler = new(std::nothrow) sensor_accuracy_handler(listener->get_sensor(), cb, user_data);
+ handler = new(std::nothrow) sensor_accuracy_handler(handle, listener->get_sensor(), cb, user_data);
retvm_if(!handler, false, "Failed to allocate memory");
listener->set_accuracy_handler(handler);
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
sensor::sensor_listener *listener;
int prev_pause;
int pause;
+ int interval, batch_latency;
+
+ AUTOLOCK(lock);
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return false;
}
+ interval = listener->get_interval();
+ if (interval > 0)
+ listener->set_interval(interval);
+
+ batch_latency = listener->get_max_batch_latency();
+ listener->set_max_batch_latency(batch_latency);
+
+ _D("Start[%d] with the interval[%d] batch_latency[%d]",
+ listener->get_id(), interval, batch_latency);
+
return true;
}
int ret;
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
if (ret == -EAGAIN || ret == OP_SUCCESS)
return true;
+ _D("Stop[%d]", listener->get_id());
+
return false;
}
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return false;
}
+ _D("Set interval[%d, %d]", listener->get_id(), interval);
+
return true;
}
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return false;
}
+ _D("Set max batch latency[%d, %u]", listener->get_id(), max_batch_latency);
+
return true;
}
sensor::sensor_listener *listener;
int pause;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return false;
}
+ _D("Set pause option[%d, %d]", listener->get_id(), pause);
+
return true;
}
return -EIO;
}
+ _D("Set attribute[%d, %d, %d]", listener->get_id(), attribute, value);
+
return OP_SUCCESS;
}
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
{
sensor::sensor_listener *listener;
+ AUTOLOCK(lock);
+
auto it = listeners.find(handle);
retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
return OP_SUCCESS;
}
+API int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data)
+{
+ retvm_if(!provider, -EINVAL, "Invalid paramter");
+ retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+ sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+ p->set_attribute_str_cb(callback, user_data);
+
+ return OP_SUCCESS;
+}
+
API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data)
{
retvm_if(!provider, -EINVAL, "Invalid paramter");
return true;
}
+static std::unordered_map<int, sensord_provider_h> external_providers;
+static int provider_id = 0;
+
+typedef struct external_cb_info_s {
+ int id;
+ sensor_external_command_cb_t cb;
+ void *user_data;
+} external_cb_info_s;
+
+static void external_attr_cb(sensord_provider_h provider, int attribute, const char *data, int cnt, void *user_data)
+{
+ external_cb_info_s *info = (external_cb_info_s *)user_data;
+
+ if (info->cb)
+ info->cb(info->id, data, cnt, info->user_data);
+}
+
/* deprecated */
API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
{
#include <sensor_types.h>
#include <command_types.h>
#include <ipc_client.h>
+#include <cmutex.h>
using namespace sensor;
+static cmutex lock;
+
class listener_handler : public ipc::channel_handler
{
public:
void connected(ipc::channel *ch) {}
void disconnected(ipc::channel *ch)
{
- _D("Disconnected");
/* If channel->disconnect() is not explicitly called,
* listener will be restored */
m_listener->restore();
init();
}
+sensor_listener::sensor_listener(sensor_t sensor, ipc::event_loop *loop)
+: m_id(0)
+, m_sensor(reinterpret_cast<sensor_info *>(sensor))
+, m_client(NULL)
+, m_cmd_channel(NULL)
+, m_evt_channel(NULL)
+, m_handler(NULL)
+, m_evt_handler(NULL)
+, m_acc_handler(NULL)
+, m_loop(loop)
+, m_connected(false)
+, m_started(false)
+{
+ init();
+}
+
sensor_listener::~sensor_listener()
{
deinit();
void sensor_listener::deinit(void)
{
+ _D("Deinitializing..");
+ stop();
disconnect();
delete m_handler;
m_client = NULL;
m_attributes.clear();
+ _D("Deinitialized..");
}
int sensor_listener::get_id(void)
ret_if(!is_connected());
retm_if(!connect(), "Failed to restore listener");
+ _D("Restoring sensor listener");
+
/* Restore attributes/status */
if (m_started.load())
start();
m_cmd_channel = m_client->connect(NULL);
retvm_if(!m_cmd_channel, false, "Failed to connect to server");
- m_evt_channel = m_client->connect(m_handler, &m_loop, false);
+ m_evt_channel = m_client->connect(m_handler, m_loop, false);
retvm_if(!m_evt_channel, false, "Failed to connect to server");
ipc::message msg;
ret_if(!is_connected());
m_connected.store(false);
+ _D("Disconnecting..");
+
m_evt_channel->disconnect();
delete m_evt_channel;
m_evt_channel = NULL;
ipc::channel_handler *sensor_listener::get_event_handler(void)
{
+ AUTOLOCK(lock);
+
return m_evt_handler;
}
void sensor_listener::set_event_handler(ipc::channel_handler *handler)
{
+ AUTOLOCK(lock);
+
m_evt_handler = handler;
}
void sensor_listener::unset_event_handler(void)
{
+ AUTOLOCK(lock);
+
delete m_evt_handler;
m_evt_handler = NULL;
}
m_cmd_channel->read_sync(reply);
if (reply.header()->err < 0) {
- _E("Failed to stop listener[%d], sensor[%s]", get_id(), m_sensor->get_uri().c_str());
+ _E("Failed to stop listener[%d]", get_id());
return reply.header()->err;
}
_I("Listener[%d] set interval[%u]", get_id(), _interval);
+ /* If it is not started, store the value only */
+ if (!m_started.load()) {
+ m_attributes[SENSORD_ATTRIBUTE_INTERVAL] = _interval;
+ return OP_SUCCESS;
+ }
+
return set_attribute(SENSORD_ATTRIBUTE_INTERVAL, _interval);
}
{
_I("Listener[%d] set max batch latency[%u]", get_id(), max_batch_latency);
+ /* If it is not started, store the value only */
+ if (!m_started.load()) {
+ m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency;
+ return OP_SUCCESS;
+ }
+
return set_attribute(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY, max_batch_latency);
}
size = sizeof(cmd_listener_attr_str_t) + len;
- buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size];
+ buf = (cmd_listener_attr_str_t *) malloc(sizeof(char) * size);
retvm_if(!buf, -ENOMEM, "Failed to allocate memory");
msg.set_type(CMD_LISTENER_ATTR_STR);
buf->listener_id = m_id;
buf->attribute = attribute;
- memcpy(&buf->value, value, len);
+ memcpy(buf->value, value, len);
buf->len = len;
msg.enclose((char *)buf, size);
m_cmd_channel->send_sync(&msg);
m_cmd_channel->read_sync(reply);
- delete [] buf;
+ /* Message memory is released automatically after sending message,
+ so it doesn't need to free memory */
- return reply.header()->err;
+ if (reply.header()->err < 0)
+ return reply.header()->err;
+
+ return OP_SUCCESS;
}
int sensor_listener::get_sensor_data(sensor_data_t *data)
class sensor_listener {
public:
sensor_listener(sensor_t sensor);
+ sensor_listener(sensor_t sensor, ipc::event_loop *loop);
virtual ~sensor_listener();
int get_id(void);
ipc::channel_handler *m_handler;
ipc::channel_handler *m_evt_handler;
ipc::channel_handler *m_acc_handler;
- ipc::event_loop m_loop;
+ ipc::event_loop *m_loop;
std::atomic<bool> m_connected;
std::atomic<bool> m_started;
std::map<int, int> m_attributes;
}
sensor_info *info = get_info(uri);
- retv_if(!info, -EACCES);
+ retvm_if(!info, -EACCES, "There is no accessible sensor for uri[%s]", uri);
*sensor = (sensor_t)info;
return OP_SUCCESS;
infos = get_infos(uri);
size = infos.size();
- retv_if(size == 0, -EACCES);
+ retvm_if(size == 0, -EACCES, "There is no accessible sensors for uri[%s]", uri);
*list = (sensor_t *)malloc(sizeof(sensor_info *) * size);
retvm_if(!*list, -ENOMEM, "Failed to allocate memory");
{
for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
if ((*it).get_uri() == uri) {
- _I("Removing sensor[%s]", (*it).get_uri().c_str());
- it = m_sensors.erase(it);
+ m_sensors.erase(it);
+ _I("Removed sensor[%s]", uri);
return OP_SUCCESS;
}
_D("Restored manager");
}
-void sensor_manager::decode_sensors(const char *buf, std::vector<sensor_info> &infos)
+void sensor_manager::decode_sensors(const char *buf, std::list<sensor_info> &infos)
{
int count = 0;
sensor_info info;
sensor_info *sensor_manager::get_info(const char *uri)
{
if (strncmp(uri, utils::get_uri(ALL_SENSOR), strlen(utils::get_uri(ALL_SENSOR))) == 0)
- return &m_sensors[0];
+ return &m_sensors.front();
for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
if ((*it).get_uri() != uri)
#include <sensor_info.h>
#include <ipc_client.h>
#include <event_loop.h>
-#include <vector>
+#include <list>
#include <atomic>
#include "sensor_internal.h"
bool connect_channel(void);
bool is_connected(void);
- void decode_sensors(const char *buf, std::vector<sensor_info> &infos);
+ void decode_sensors(const char *buf, std::list<sensor_info> &infos);
bool get_sensors_internal(void);
bool has_privilege(std::string &uri);
std::atomic<bool> m_connected;
channel_handler *m_handler;
- std::vector<sensor_info> m_sensors;
+ std::list<sensor_info> m_sensors;
};
}
int size;
size = serialize(info, &bytes);
- retvm_if(size == -ENOMEM, -ENOMEM, "Failed to serialize");
+
ipc::message msg((const char *)bytes, size);
msg.set_type(CMD_PROVIDER_CONNECT);
m_channel->send_sync(&msg);
- delete []bytes;
+
return OP_SUCCESS;
}
int sensor_provider::publish(sensor_data_t *data, int len)
{
- for (int i = 0; i < data->value_count; ++i) {
- if (!(data->values[i] >= m_sensor.get_min_range() &&
- data->values[i] <= m_sensor.get_max_range())) {
- _E("Out of range");
- return OP_ERROR;
- }
- }
-
ipc::message msg;
msg.set_type(CMD_PROVIDER_PUBLISH);
msg.enclose((const char *)data, len);
m_handler->set_interval_cb(cb, user_data);
}
+void sensor_provider::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data)
+{
+ m_handler->set_attribute_str_cb(cb, user_data);
+}
+
void set_start_cb(sensord_provider_start_cb cb, void *user_data);
void set_stop_cb(sensord_provider_stop_cb cb, void *user_data);
void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data);
+ void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data);
int publish(sensor_data_t *data, int len);
, m_start_cb(NULL)
, m_stop_cb(NULL)
, m_interval_changed_cb(NULL)
+, m_attribute_str_cb(NULL)
, m_start_user_data(NULL)
, m_stop_user_data(NULL)
, m_interval_changed_user_data(NULL)
+, m_attribute_str_user_data(NULL)
{
}
if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_interval_changed_cb)
m_interval_changed_cb(m_provider, buf.value, m_interval_changed_user_data);
break;
+ case CMD_PROVIDER_ATTR_STR:
+ cmd_provider_attr_str_t *attr;
+
+ attr = (cmd_provider_attr_str_t *) new(std::nothrow) char[msg.size()];
+ retm_if(!attr, "Failed to allocate memory");
+
+ msg.disclose((char *)attr);
+
+ if (m_attribute_str_cb)
+ m_attribute_str_cb(m_provider, attr->attribute, attr->value, attr->len, m_attribute_str_user_data);
+
+ delete [] attr;
+ break;
}
}
m_interval_changed_cb = cb;
m_interval_changed_user_data = user_data;
}
+
+void sensor_provider::channel_handler::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data)
+{
+ m_attribute_str_cb = cb;
+ m_attribute_str_user_data = user_data;
+}
void set_start_cb(sensord_provider_start_cb cb, void *user_data);
void set_stop_cb(sensord_provider_stop_cb cb, void *user_data);
void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data);
+ void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data);
private:
sensor_provider *m_provider;
sensord_provider_start_cb m_start_cb;
sensord_provider_stop_cb m_stop_cb;
sensord_provider_interval_changed_cb m_interval_changed_cb;
+ sensord_provider_attribute_str_cb m_attribute_str_cb;
void *m_start_user_data;
void *m_stop_user_data;
void *m_interval_changed_user_data;
+ void *m_attribute_str_user_data;
};
}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "sensor_reader.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+#include <chrono>
+
+using namespace sensor;
+
+sensor_reader::sensor_reader()
+: m_reader(NULL)
+, m_event_loop(NULL)
+, m_mutex()
+, m_cond()
+, m_loop(NULL)
+, m_running(false)
+{
+ m_event_loop = new(std::nothrow) ipc::event_loop();
+ m_reader = new(std::nothrow) std::thread(&sensor::sensor_reader::read_event, this);
+ m_reader->detach();
+
+ if (!m_running)
+ wait_for_preparation();
+
+ _I("Created");
+}
+
+sensor_reader::~sensor_reader()
+{
+ _I("Destroying..");
+ retm_if(!m_reader, "Invalid reader");
+
+ m_running = false;
+
+ m_event_loop->stop();
+
+ delete m_reader;
+ m_reader = NULL;
+
+ delete m_event_loop;
+ m_event_loop = NULL;
+
+ _I("Destroyed");
+}
+
+ipc::event_loop *sensor_reader::get_event_loop(void)
+{
+ retvm_if(!m_event_loop, NULL, "Invalid context");
+
+ return m_event_loop;
+}
+
+void sensor_reader::wait_for_preparation(void)
+{
+ std::unique_lock<std::mutex> lock(m_mutex);
+ m_cond.wait_for(lock, std::chrono::seconds(1));
+}
+
+void sensor_reader::read_event(void)
+{
+ _I("RUN");
+ m_loop = g_main_loop_new(g_main_context_new(), false);
+ m_event_loop->set_mainloop(m_loop);
+
+ m_cond.notify_one();
+ m_running = true;
+
+ if (!m_event_loop->run())
+ _E("Failed to run event loop");
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 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_READER_H__
+#define __SENSOR_READER_H__
+
+#include <glib.h>
+#include <event_loop.h>
+
+#include <thread>
+#include <atomic>
+#include <condition_variable>
+
+namespace sensor {
+
+class sensor_reader {
+public:
+ sensor_reader();
+ ~sensor_reader();
+
+ ipc::event_loop *get_event_loop(void);
+
+private:
+ void wait_for_preparation(void);
+ void read_event(void);
+
+ std::thread *m_reader;
+ GMainLoop *m_loop;
+ ipc::event_loop *m_event_loop;
+ std::mutex m_mutex;
+ std::condition_variable m_cond;
+ std::atomic<bool> m_running;
+};
+
+}
+
+#endif /* __SENSOR_READER_H__ */
ADD_DEFINITIONS(-DENABLE_PEDOMETER)
ENDIF()
+IF("${GESTURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} gesture/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GESTURE)
+ENDIF()
+
MESSAGE("Sources: ${SRCS}")
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared")
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/fusion)
void auto_rotation_sensor::deinit(void)
{
+ if (!m_alg)
+ return;
+
delete m_alg;
+ m_alg = NULL;
}
int auto_rotation_sensor::get_sensor_info(const sensor_info2_t **info)
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return 1;
+ return 0;
}
int auto_rotation_sensor::start(observer_h ob)
#ifdef ENABLE_PEDOMETER
#include "pedometer/pedometer_sensor.h"
#endif
+#ifdef ENABLE_GESTURE
+#include "gesture/face_down_sensor.h"
+#include "gesture/pick_up_sensor.h"
+#endif
static std::vector<fusion_sensor_t> sensors;
extern "C" int create(fusion_sensor_t **fsensors)
{
#ifdef ENABLE_AUTO_ROTATION
- create_sensor<auto_rotation_sensor>("Accelerometer");
+ create_sensor<auto_rotation_sensor>("Auto Rotation Sensor");
#endif
#ifdef ENABLE_GRAVITY
create_sensor<pedometer_sensor>("Pedometer");
#endif
+#ifdef ENABLE_GESTURE
+ create_sensor<face_down_sensor>("Face Down Sensor");
+ create_sensor<pick_up_sensor>("Pick Up Sensor");
+#endif
*fsensors = &sensors[0];
return sensors.size();
}
#ifndef __FACE_DOWN_ALG_H__
#define __FACE_DOWN_ALG_H__
-#include <sensor_common.h>
+#include <sensor_types.h>
class face_down_alg {
public:
virtual ~face_down_alg() {};
- virtual void push_event(const sensor_event_t & event) = 0;
+ virtual void update(sensor_data_t *data) = 0;
virtual bool get_face_down(void) = 0;
};
* limitations under the License.
*
*/
+#include "face_down_alg_impl.h"
+
+#include <sensor_log.h>
#include <cmath>
#include <climits>
-#include <sensor_log.h>
-#include <face_down_alg_impl.h>
#define GRAVITY 9.80665
#define TWENTY_DEGREES 0.349066
{
}
-void face_down_alg_impl::push_event(const sensor_event_t & event)
+void face_down_alg_impl::update(sensor_data_t *data)
{
- //_I("face_down_alg: %llu acc[2]: %f",event.data->timestamp,event.data->values[2]);
- m_current_time = event.data->timestamp;
+ m_current_time = data->timestamp;
remove_old_up_time();
- if (event.data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES)))
- m_latest_down_time = event.data->timestamp;
+ if (data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES)))
+ m_latest_down_time = data->timestamp;
- if (event.data->values[2] > (GRAVITY * cos(TWENTY_DEGREES)))
- m_oldest_up_time.push(event.data->timestamp);
+ if (data->values[2] > (GRAVITY * cos(TWENTY_DEGREES)))
+ m_oldest_up_time.push(data->timestamp);
}
void face_down_alg_impl::remove_old_up_time(void)
{
if (m_current_time - m_latest_down_time < WINDOW_SIZE)
return m_latest_down_time;
+
return 0;
}
#ifndef __FACE_DOWN_ALG_IMPL_H__
#define __FACE_DOWN_ALG_IMPL_H__
-#include <sensor_common.h>
-#include <face_down_alg.h>
#include <queue>
+#include "face_down_alg.h"
+
class face_down_alg_impl : public virtual face_down_alg {
public:
face_down_alg_impl();
~face_down_alg_impl();
- void push_event(const sensor_event_t & event);
+ void update(sensor_data_t *data);
bool get_face_down(void);
+
private:
+ void remove_old_up_time(void);
+ unsigned long long is_facing_down(void);
+ unsigned long long was_facing_up(void);
+
unsigned long long m_current_time;
unsigned long long m_last_event_time;
unsigned long long m_latest_down_time;
std::queue<unsigned long long> m_oldest_up_time;
- void remove_old_up_time(void);
- unsigned long long is_facing_down();
- unsigned long long was_facing_up();
};
#endif /* __FACE_DOWN_ALG_IMPL_H__ */
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "face_down_sensor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#include "face_down_alg_impl.h"
+
+#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_face_down/tizen_default"
+#define NAME_VENDOR "tizen.org"
+
+#define SRC_ID_GRAVITY 0x1
+#define SRC_URI_GRAVITY "http://tizen.org/sensor/general/gravity"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: GESTURE_FACE_DOWN_SENSOR,
+ uri: NAME_SENSOR,
+ vendor: NAME_VENDOR,
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 50,
+ max_batch_count: 0,
+ wakeup_supported: false,
+ privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+ {SRC_ID_GRAVITY, SRC_URI_GRAVITY}
+};
+
+face_down_sensor::face_down_sensor()
+: m_state(0)
+, m_timestamp(0)
+, m_alg(NULL)
+{
+ if (!init())
+ throw OP_ERROR;
+}
+
+face_down_sensor::~face_down_sensor()
+{
+ deinit();
+}
+
+bool face_down_sensor::init(void)
+{
+ m_alg = get_alg();
+ retvm_if(!m_alg, false, "Not supported");
+ return true;
+}
+
+void face_down_sensor::deinit(void)
+{
+ if (!m_alg)
+ return;
+
+ delete m_alg;
+ m_alg = NULL;
+}
+
+int face_down_sensor::get_sensor_info(const sensor_info2_t **info)
+{
+ *info = &sensor_info;
+ return OP_SUCCESS;
+}
+
+int face_down_sensor::get_required_sensors(const required_sensor_s **sensors)
+{
+ *sensors = required_sensors;
+ return 1;
+}
+
+int face_down_sensor::update(uint32_t id, sensor_data_t *data, int len)
+{
+ int state;
+
+ m_alg->update(data);
+
+ state = m_alg->get_face_down();
+ retv_if(!state, OP_ERROR);
+
+ m_state = state;
+ m_timestamp = data->timestamp;
+
+ return OP_SUCCESS;
+}
+
+int face_down_sensor::get_data(sensor_data_t ** data, int *length)
+{
+ sensor_data_t *sensor_data;
+ sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
+ retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory");
+
+ sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+ sensor_data->timestamp = m_timestamp;
+ sensor_data->values[0] = m_state;
+ sensor_data->value_count = 1;
+
+ *data = sensor_data;
+ *length = sizeof(sensor_data_t);
+
+ return 0;
+}
+
+face_down_alg_impl *face_down_sensor::get_alg(void)
+{
+ face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl();
+ retvm_if(!alg, NULL, "Failed to allocate memory");
+
+ return alg;
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2016 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 __FACE_DOWN_SENSOR_H__
+#define __FACE_DOWN_SENSOR_H__
+
+#include <fusion_sensor.h>
+#include <sensor_types.h>
+
+#include "face_down_alg_impl.h"
+
+class face_down_sensor : public fusion_sensor {
+public:
+ face_down_sensor();
+ virtual ~face_down_sensor();
+
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
+
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
+
+private:
+ bool init(void);
+ void deinit(void);
+
+ face_down_alg_impl *get_alg(void);
+
+ int m_state;
+ unsigned long long m_timestamp;
+
+ face_down_alg_impl *m_alg;
+};
+
+#endif /* __FACE_DOWN_SENSOR_H__ */
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "pick_up_sensor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_pick_up/tizen_default"
+#define NAME_VENDOR "tizen.org"
+
+#define SRC_ID_MOVE 0x1
+#define SRC_URI_MOVE "http://tizen.org/sensor/general/gesture_movement/SENSOR_GESTURE_MOVEMENT"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: GESTURE_PICK_UP_SENSOR,
+ uri: NAME_SENSOR,
+ vendor: NAME_VENDOR,
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 0,
+ max_batch_count: 0,
+ wakeup_supported: false,
+ privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+ {SRC_ID_MOVE, SRC_URI_MOVE}
+};
+
+pick_up_sensor::pick_up_sensor()
+: m_state(0)
+, m_timestamp(0)
+{
+}
+
+pick_up_sensor::~pick_up_sensor()
+{
+}
+
+int pick_up_sensor::get_sensor_info(const sensor_info2_t **info)
+{
+ *info = &sensor_info;
+ return OP_SUCCESS;
+}
+
+int pick_up_sensor::get_required_sensors(const required_sensor_s **sensors)
+{
+ *sensors = required_sensors;
+ return 1;
+}
+
+int pick_up_sensor::update(uint32_t id, sensor_data_t *data, int len)
+{
+ int state = data->values[0];
+
+ _D("State : %d", state);
+
+ m_state = state;
+ m_timestamp = data->timestamp;
+
+ return OP_SUCCESS;
+}
+
+int pick_up_sensor::get_data(sensor_data_t **data, int *length)
+{
+ sensor_data_t *sensor_data;
+ sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
+ retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory");
+
+ sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+ sensor_data->timestamp = m_timestamp;
+ sensor_data->values[0] = m_state;
+ sensor_data->value_count = 1;
+
+ *data = sensor_data;
+ *length = sizeof(sensor_data_t);
+
+ return 0;
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 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 __PICK_UP_SENSOR_H__
+#define __PICK_UP_SENSOR_H__
+
+#include <fusion_sensor.h>
+#include <sensor_types.h>
+
+class pick_up_sensor : public fusion_sensor {
+public:
+ pick_up_sensor();
+ virtual ~pick_up_sensor();
+
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
+
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
+
+private:
+ int m_state;
+ unsigned long long m_timestamp;
+};
+
+#endif /* __PICK_UP_SENSOR_H__ */
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return 1;
+ return 0;
}
m_var_azimuth = vec;
m_gyro.m_time_stamp = 0;
- m_gyro_dt = 0;
}
template <typename TYPE>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sensor-physical CXX)
+INCLUDE(GNUInstallDirs)
+
+SET(ACCEL "OFF")
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/src/shared
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+# Common Options
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections")
+MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
+MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
+
+# Internal Debugging Options
+#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED dlog glib-2.0 vconf libtzplatform-config)
+
+FOREACH(flag ${PLUGINS_PKGS_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+
+FILE(GLOB SRCS *.cpp)
+
+IF("${ACCEL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} accel/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ACCEL)
+ENDIF()
+
+MESSAGE("Sources: ${SRCS}")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/physical)
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "accel_sensor.h"
+#include <sensor_log.h>
+
+#define URI_ACCEL "http://tizen.org/sensor/general/accelerometer"
+
+accel_sensor::accel_sensor()
+{
+ _I("accel_sensor is created : %#x", this);
+}
+
+accel_sensor::~accel_sensor()
+{
+ _I("accel_sensor is destroyed : %#x", this);
+}
+
+std::string accel_sensor::get_uri(void)
+{
+ return URI_ACCEL;
+}
+
+physical_sensor *accel_sensor::clone(void) const
+{
+ return new accel_sensor(*this);
+}
+
+int accel_sensor::start(observer_h ob)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::stop(observer_h ob)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::set_interval(observer_h ob, uint32_t interval)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::set_batch_latency(observer_h ob, uint32_t latency)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::set_attribute(observer_h ob, int32_t attr, int32_t value)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::set_attribute(observer_h ob, int32_t attr, const char *value, int len)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::flush(observer_h ob)
+{
+ return OP_DEFAULT;
+}
+
+int accel_sensor::on_event(sensor_data_t *data, int32_t len, int32_t remains)
+{
+ return OP_DEFAULT;
+}
*
*/
-#ifndef _PEDOMETER_SENSOR_H_
-#define _PEDOMETER_SENSOR_H_
+#ifndef __ACCEL_SENSOR_H__
+#define __ACCEL_SENSOR_H__
#include <physical_sensor.h>
-class pedometer_sensor : public physical_sensor {
+class accel_sensor : public physical_sensor {
public:
- pedometer_sensor();
- virtual ~pedometer_sensor();
-
- bool on_event(const sensor_data_t *data, int data_len, int remains);
-
-private:
- unsigned long long m_steps;
- unsigned long long m_walk_steps;
- unsigned long long m_run_steps;
- unsigned long long m_walk_up_steps;
- unsigned long long m_walk_down_steps;
- unsigned long long m_run_up_steps;
- unsigned long long m_run_down_steps;
- double m_distance;
- double m_calories;
-
- void accumulate(sensor_pedometer_data_t *data);
+ accel_sensor();
+ ~accel_sensor();
+
+ std::string get_uri(void);
+ physical_sensor *clone(void) const;
+
+ int start(observer_h ob);
+ int stop(observer_h ob);
+
+ int set_interval(observer_h ob, uint32_t interval);
+ int set_batch_latency(observer_h ob, uint32_t latency);
+ int set_attribute(observer_h ob, int32_t attr, int32_t value);
+ int set_attribute(observer_h ob, int32_t attr, const char *value, int len);
+ int flush(observer_h ob);
+ int on_event(sensor_data_t *data, int32_t len, int32_t remains);
};
-#endif /* _PEDOMETER_SENSOR_H_ */
+#endif /* __ACCEL_SENSOR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sensor_log.h>
+#include <physical_sensor.h>
+#include <vector>
+
+#ifdef ENABLE_ACCEL
+#include "accel/accel_sensor.h"
+#endif
+
+static std::vector<physical_sensor_t> sensors;
+
+template<typename _sensor>
+void create_sensor(const char *name)
+{
+ physical_sensor *instance = NULL;
+ try {
+ instance = new _sensor;
+ } catch (std::exception &e) {
+ _E("Failed to create %s sensor, exception: %s", name, e.what());
+ return;
+ } catch (int err) {
+ _ERRNO(err, _E, "Failed to create %s sensor device", name);
+ return;
+ }
+
+ sensors.push_back(instance);
+}
+
+extern "C" int create(physical_sensor_t **fsensors)
+{
+#ifdef ENABLE_ACCEL
+ create_sensor<accel_sensor>("Accelerometer");
+#endif
+ *fsensors = &sensors[0];
+ return sensors.size();
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 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.
+ *
+ */
+
+#pragma once
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+static inline void __freep(void *p)
+{
+ free(*(void**) p);
+}
+
+static inline void __closep(int *fd)
+{
+ if (*fd >= 0)
+ close(*fd);
+}
+
+static inline void __fclosep(FILE **f)
+{
+ if (*f)
+ fclose(*f);
+}
+
+static inline void int_to_bytes(int value, int width, char data[])
+{
+ /* Big-endian */
+ for (int i = width - 1; i >= 0; i--) {
+ data[i] = (value & 0xff);
+ value = value >> 8;
+ }
+}
+
+static inline unsigned int bytes_to_uint(char data[], int &cursor, int width)
+{
+ unsigned int sum = 0;
+
+ /* Big-endian */
+ for (int i = 0; i < width; ++i)
+ sum = (sum << 8) + (unsigned char)data[cursor++];
+
+ return sum;
+}
+
+#define _cleanup_free_ _cleanup_(__freep)
+#define _cleanup_close_ _cleanup_(__closep)
+#define _cleanup_fclose_ _cleanup_(__fclosep)
+#define GET_BYTES(value, width, data) int_to_bytes(value, width, data)
+#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <sensor_log.h>
-#include <accel_sensor.h>
-
-accel_sensor::accel_sensor()
-{
- _I("accel_sensor is created : %#x", this);
-}
-
-accel_sensor::~accel_sensor()
-{
-}
-
-sensor_type_t accel_sensor::get_type(void)
-{
- return ACCELEROMETER_SENSOR;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
-#include <dlfcn.h>
-
-#include <sensor_log.h>
-#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <face_down_sensor.h>
-#include <sensor_loader.h>
-#include <fusion_util.h>
-#include <face_down_alg_impl.h>
-
-#define SENSOR_NAME "SENSOR_FACE_DOWN"
-
-#define SENSOR_FREQUENCY 50
-
-face_down_sensor::face_down_sensor()
-: m_gravity_sensor(NULL)
-, m_time(0)
-, m_state(false)
-{
-}
-
-face_down_sensor::~face_down_sensor()
-{
- _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool face_down_sensor::init(void)
-{
- m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR);
-
- if (!m_gravity_sensor) {
- _W("cannot load gravity sensor sensor[%s]", SENSOR_NAME);
- return false;
- }
-
- m_alg = get_alg();
- if (!m_alg)
- return false;
-
- _I("%s is created!", SENSOR_NAME);
- return true;
-}
-
-sensor_type_t face_down_sensor::get_type(void)
-{
- return GESTURE_FACE_DOWN_SENSOR;
-}
-
-unsigned int face_down_sensor::get_event_type(void)
-{
- return CONVERT_TYPE_EVENT(GESTURE_FACE_DOWN_SENSOR);
-}
-
-const char *face_down_sensor::get_name(void)
-{
- return SENSOR_NAME;
-}
-
-bool face_down_sensor::get_sensor_info(sensor_info & info)
-{
- info.set_type(get_type());
- info.set_id(get_id());
- info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
- info.set_name(get_name());
- info.set_vendor("Samsung Electronics");
- info.set_min_range(0);
- info.set_max_range(1);
- info.set_resolution(1);
- info.set_min_interval(1);
- info.set_fifo_count(0);
- info.set_max_batch_count(0);
- info.set_supported_event(get_event_type());
- info.set_wakeup_supported(false);
-
- return true;
-}
-
-void face_down_sensor::synthesize(const sensor_event_t & event)
-{
- if (event.event_type != GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME)
- return;
-
- m_time = event.data->timestamp;
- m_alg->push_event(event);
- m_state = m_alg->get_face_down();
- if (!m_state)
- return;
-
- sensor_event_t *face_down_event;
- sensor_data_t *face_down_data;
- int data_length;
-
- face_down_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- retm_if(!face_down_event, "Failed to allocate memory");
-
- get_data(&face_down_data, &data_length);
- face_down_event->sensor_id = get_id();
- face_down_event->event_type = FACE_DOWN_RAW_DATA_EVENT;
- face_down_event->data_length = data_length;
- face_down_event->data = face_down_data;
-
- push(face_down_event);
-
- _I("[face_down_sensor] : True");
-}
-
-int face_down_sensor::get_data(sensor_data_t ** data, int *length)
-{
- sensor_data_t *sensor_data;
- sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory");
-
- sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
- sensor_data->timestamp = m_time;
- sensor_data->value_count = 1;
- sensor_data->values[0] = m_state;
-
- *data = sensor_data;
- *length = sizeof(sensor_data_t);
-
- return 0;
-}
-
-bool face_down_sensor::set_interval(unsigned long interval)
-{
- m_interval = interval;
- return true;
-}
-
-bool face_down_sensor::set_batch_latency(unsigned long latency)
-{
- return false;
-}
-
-bool face_down_sensor::on_start(void)
-{
- if (m_gravity_sensor)
- m_gravity_sensor->start();
-
- m_time = 0;
- m_state = false;
- return activate();
-}
-
-bool face_down_sensor::on_stop(void)
-{
- if (m_gravity_sensor)
- m_gravity_sensor->stop();
-
- m_time = 0;
- m_state = false;
-
- return deactivate();
-}
-
-bool face_down_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
- m_gravity_sensor->add_interval(client_id, interval, true);
- return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool face_down_sensor::delete_interval(int client_id, bool is_processor)
-{
- m_gravity_sensor->delete_interval(client_id, true);
- return sensor_base::delete_interval(client_id, is_processor);
-}
-
-face_down_alg_impl *face_down_sensor::get_alg(void)
-{
- face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl();
- retvm_if(!alg, NULL, "Failed to allocate memory");
-
- return alg;
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 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 __FACE_DOWN_SENSOR_H__
-#define __FACE_DOWN_SENSOR_H__
-
-#include <virtual_sensor.h>
-#include <sensor_types.h>
-#include <face_down_alg_impl.h>
-
-class face_down_sensor : public virtual_sensor {
-public:
- face_down_sensor();
- ~face_down_sensor();
-
- /* initialize sensor */
- bool init(void);
-
- /* sensor info */
- sensor_type_t get_type(void);
- unsigned int get_event_type(void);
- const char *get_name(void);
-
- bool get_sensor_info(sensor_info & info);
-
- /* synthesize event */
- void synthesize(const sensor_event_t & event);
-
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
-
- /* get data */
- int get_data(sensor_data_t ** data, int *length);
-private:
- sensor_base * m_gravity_sensor;
- face_down_alg_impl *m_alg;
-
- unsigned long long m_time;
- bool m_state;
- unsigned int m_interval;
-
- bool set_interval(unsigned long interval);
- bool set_batch_latency(unsigned long latency);
-
- bool on_start(void);
- bool on_stop(void);
- face_down_alg_impl *get_alg(void);
-};
-
-#endif /* __FACE_DOWN_SENSOR_H__ */
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <sensor_log.h>
-#include "hrm_sensor.h"
-
-hrm_sensor::hrm_sensor()
-{
- set_permission(SENSOR_PERMISSION_BIO);
-
- _I("hrm_sensor is created : %#x", this);
-}
-
-hrm_sensor::~hrm_sensor()
-{
- _I("hrm_sensor is destroyed : %#x", this);
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <sensor_log.h>
-#include "pedometer_sensor.h"
-
-enum value_index {
- IDX_STEPS = 0,
- IDX_WALK_STEPS,
- IDX_RUN_STEPS,
- IDX_DISTANCE,
- IDX_CALORIES,
- IDX_SPEED,
- IDX_FREQUENCY,
- IDX_STATE,
- IDX_WALK_UP,
- IDX_WALK_DOWN,
- IDX_RUN_UP,
- IDX_RUN_DOWN,
- IDX_STATE_EX,
-};
-
-pedometer_sensor::pedometer_sensor()
-: m_steps(0)
-, m_walk_steps(0)
-, m_run_steps(0)
-, m_walk_up_steps(0)
-, m_walk_down_steps(0)
-, m_run_up_steps(0)
-, m_run_down_steps(0)
-, m_distance(0)
-, m_calories(0)
-{
- set_permission(SENSOR_PERMISSION_BIO);
-
- _I("pedometer_sensor is created : %#x", this);
-}
-
-pedometer_sensor::~pedometer_sensor()
-{
-}
-
-bool pedometer_sensor::on_event(const sensor_data_t *data, int data_len, int remains)
-{
- if (data_len == sizeof(sensorhub_data_t))
- return false;
-
- accumulate((sensor_pedometer_data_t*)data);
- return true;
-}
-
-void pedometer_sensor::accumulate(sensor_pedometer_data_t *data)
-{
- m_steps += data->values[IDX_STEPS];
- m_walk_steps += data->values[IDX_WALK_STEPS];
- m_run_steps += data->values[IDX_RUN_STEPS];
- m_distance += data->values[IDX_DISTANCE];
- m_calories += data->values[IDX_CALORIES];
-
- m_walk_up_steps += data->values[IDX_WALK_UP];
- m_walk_down_steps += data->values[IDX_WALK_DOWN];
- m_run_up_steps += data->values[IDX_RUN_UP];
- m_run_down_steps += data->values[IDX_RUN_DOWN];
-
- data->values[IDX_STEPS] = m_steps;
- data->values[IDX_WALK_STEPS] = m_walk_steps;
- data->values[IDX_RUN_STEPS] = m_run_steps;
- data->values[IDX_DISTANCE] = m_distance;
- data->values[IDX_CALORIES] = m_calories;
-
- data->values[IDX_WALK_UP] = m_walk_up_steps;
- data->values[IDX_WALK_DOWN] = m_walk_down_steps;
- data->values[IDX_RUN_UP] = m_run_up_steps;
- data->values[IDX_RUN_DOWN] = m_run_down_steps;
-}
#include "info.h"
#include <stdio.h>
-#include <stdlib.h>
#include <glib.h>
#include <sensor_internal.h>
sensord_get_sensor_list(type, &sensors, &count);
show_info(sensors, count);
- if (sensors) {
- free(sensors);
- sensors = NULL;
- }
+ delete sensors;
return true;
}
virtual bool teardown(void) { return true; }
const std::string& name() const { return m_name; }
- sensor_type_t type() { return m_type; }
+ const sensor_type_t type() const { return m_type; }
virtual bool inject(int argc, char *argv[]) = 0;
{
int err;
int count;
- sensor_t *sensors = NULL;
+ sensor_t *sensors;
err = sensord_get_sensors(info.type, &sensors, &count);
ASSERT_EQ(err, 0);
handle = sensord_connect(sensors[info.index]);
- ASSERT_FREE((handle < 0), sensors);
ASSERT_GE(handle, 0);
- free(sensors);
- sensors = NULL;
-
return true;
}
bool sensor_adapter::start(sensor_info info, int &handle)
{
- sensor_t *sensors = NULL;
+ sensor_t *sensors;
int count;
int err;
bool ret;
err = sensord_get_sensors(info.type, &sensors, &count);
ASSERT_EQ(err, 0);
-
- ASSERT_FREE((info.index >= count), sensors);
ASSERT_LT(info.index, count);
-
- ASSERT_FREE((info.index < 0), sensors);
ASSERT_GE(info.index, 0);
handle = sensord_connect(sensors[info.index]);
- ASSERT_FREE((handle < 0), sensors);
ASSERT_GE(handle, 0);
ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL);
- ASSERT_FREE((ret != true), sensors);
ASSERT_TRUE(ret);
ret = sensord_start(handle, info.powersave);
- ASSERT_FREE((ret != true), sensors);
ASSERT_TRUE(ret);
free(sensors);
- sensors = NULL;
return true;
}
{GESTURE_WRIST_UP_SENSOR, "wristup"},
{GESTURE_WRIST_DOWN_SENSOR, "wristdown"},
{GESTURE_MOVEMENT_STATE_SENSOR, "movement_state"},
+ {GESTURE_PICK_UP_SENSOR, "pickup"},
+ {GESTURE_FACE_DOWN_SENSOR, "facedown"},
{WEAR_STATUS_SENSOR, "wear_status"},
{WEAR_ON_MONITOR_SENSOR, "wear_on"},
if (!strcmp(command, "test"))
manager = new(std::nothrow) tester_manager;
- else if (!strcmp(command, "inject"))
+ if (!strcmp(command, "inject"))
manager = new(std::nothrow) injector_manager;
- else if (!strcmp(command, "info"))
+ if (!strcmp(command, "info"))
manager = new(std::nothrow) info_manager;
- else if (!strcmp(command, "loopback"))
+ if (!strcmp(command, "loopback"))
manager = new(std::nothrow) loopback_manager;
if (!manager) {
} \
} while (0)
-#define ASSERT_FREE(expr, X) \
- do { if (expr) { free (X); X = NULL; } } while (0)
-
#define ASSERT_TRUE(condition) ASSERT(condition, ==, true)
#define ASSERT_FALSE(condition) ASSERT(condition, ==, false)
#define ASSERT_EQ(left, right) ASSERT(left, ==, right)
err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count);
ASSERT_EQ(err, 0);
- ASSERT_FREE((count < 0), sensors);
ASSERT_GT(count, 0);
free(sensors);
bool ret;
int handle;
sensor_t sensor;
- sensor_t *list = NULL;
- int count = 0;
+ sensor_t *list;
+ int count;
called = false;
ASSERT_EQ(err, 0);
handle = sensord_connect(sensor);
- ASSERT_FREE(((handle != 0) && list), list);
- ASSERT_EQ(handle, 0);
+ ASSERT_EQ(err, 0);
ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
ret = sensord_start(handle, 0);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
ret = sensord_change_event_interval(handle, 0, 100);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
ret = sensord_change_event_max_batch_latency(handle, 0, 100);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
mainloop::run();
ret = sensord_stop(handle);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
ret = sensord_unregister_event(handle, 1);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
ret = sensord_disconnect(handle);
- ASSERT_FREE(((ret != true) && list), list);
ASSERT_TRUE(ret);
free(list);
sensord_provider_set_resolution(provider, 0.01f);
sensord_add_provider(provider);
- sensord_remove_provider(provider);
+ sensord_remove_provider(provider);
sensord_destroy_provider(provider);
}
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(sensord CXX)
-SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session")
+SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session vconf")
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS})
int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len)
{
+ ipc::message msg;
+ cmd_provider_attr_str_t *buf;
+ size_t size;
+
+ size = sizeof(cmd_provider_attr_str_t) + len;
+
+ buf = (cmd_provider_attr_str_t *) malloc(sizeof(char) * size);
+ retvm_if(!buf, -ENOMEM, "Failed to allocate memory");
+
+ msg.set_type(CMD_PROVIDER_ATTR_STR);
+ memcpy(buf->value, value, len);
+ buf->attribute = attr;
+ buf->len = len;
+
+ msg.enclose((char *)buf, size);
+
+ m_ch->send_sync(&msg);
+
+ _I("Set attribute[%d] to sensor[%s]", attr, m_info.get_uri().c_str());
+
return OP_SUCCESS;
}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include <dbus_util.h>
-#include <gio/gio.h>
-
-static int wrist_up_total_cnt;
-static int wrist_up_lcdon_cnt;
-static int wrist_up_algo;
-
-static GDBusNodeInfo *introspection_data = NULL;
-static guint owner_id;
-
-static const gchar introspection_xml[] =
-"<node>"
-" <interface name='org.tizen.system.sensord'>"
-" <method name='check_privilege'>"
-" <arg type='i' name='response' direction='out'/>"
-" </method>"
-" <method name='wristup_lcdon_cnt'>"
-" <arg type='i' name='response' direction='out'/>"
-" </method>"
-" <method name='wristup_total_cnt'>"
-" <arg type='i' name='response' direction='out'/>"
-" </method>"
-" <method name='wristup_algo'>"
-" <arg type='i' name='response' direction='out'/>"
-" </method>"
-" </interface>"
-"</node>";
-
-static void method_call_handler(GDBusConnection *conn,
- const gchar *sender, const gchar *object_path,
- const gchar *iface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- int ret = DBUS_INIT;
-
- if (g_strcmp0(method_name, "check_privilege") == 0) {
- _D("check_privilege called");
- ret = DBUS_SUCCESS;
- } else if (g_strcmp0(method_name, "wristup_lcdon_cnt") == 0) {
- _D("wristup_lcdon_cnt called, %d", wrist_up_lcdon_cnt);
- ret = wrist_up_lcdon_cnt;
- } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) {
- _D("wristup_total_cnt called, %d", wrist_up_total_cnt);
- ret = wrist_up_total_cnt;
- } else if (g_strcmp0(method_name, "wristup_algo") == 0) {
- _D("wristup_algo called, %d", wrist_up_algo);
- ret = wrist_up_algo;
- } else {
- _D("No matched method call");
- ret = DBUS_FAILED;
- }
-
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", ret));
-}
-
-static const GDBusInterfaceVTable interface_vtable =
-{
- method_call_handler,
- NULL,
- NULL
-};
-
-static void on_bus_acquired(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- guint registration_id;
-
- if (!connection) {
- _E("connection is null");
- return;
- }
-
- registration_id = g_dbus_connection_register_object(connection,
- SENSORD_OBJECT_PATH,
- introspection_data->interfaces[0],
- &interface_vtable,
- NULL, /* user_data */
- NULL, /* user_data_free_func */
- NULL); /* GError** */
-
- if (registration_id == 0)
- _E("Failed to g_dbus_connection_register_object");
-
- _I("Gdbus method call registrated");
-}
-
-static void on_name_acquired(GDBusConnection *conn,
- const gchar *name, gpointer user_data)
-{
-}
-
-static void on_name_lost(GDBusConnection *conn,
- const gchar *name, gpointer user_data)
-{
- _E("Dbus name is lost!");
-}
-
-int get_lcdon_count(void)
-{
- return wrist_up_lcdon_cnt;
-}
-
-void increase_lcdon_count(void)
-{
- wrist_up_lcdon_cnt++;
-}
-
-void reset_lcdon_count(void)
-{
- wrist_up_lcdon_cnt = 0;
-}
-
-int get_total_count(void)
-{
- return wrist_up_total_cnt;
-}
-
-void increase_total_count(void)
-{
- wrist_up_total_cnt++;
-}
-
-void reset_total_count(void)
-{
- wrist_up_total_cnt = 0;
-}
-
-void set_wrist_up_algo(int mode)
-{
- wrist_up_algo = mode;
-}
-
-void init_dbus(void)
-{
-#ifndef GLIB_VERSION_2_36
- g_type_init();
-#endif
-
- introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
- if (introspection_data == NULL) {
- _E("Failed to init g_dbus_node_info_new_for_xml");
- return;
- }
-
- owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- SENSORD_BUS_NAME,
- (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
- | G_BUS_NAME_OWNER_FLAGS_REPLACE),
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- NULL,
- NULL);
- wrist_up_total_cnt = 0;
- wrist_up_lcdon_cnt = 0;
-}
-
-void fini_dbus(void)
-{
- if (owner_id != 0)
- g_bus_unown_name(owner_id);
-
- if (introspection_data)
- g_dbus_node_info_unref(introspection_data);
-}
+++ /dev/null
-/*
- * sensord
- *
- * Copyright (c) 2014 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 _DBUS_UTIL_H_
-#define _DBUS_UTIL_H_
-
-#define SENSORD_BUS_NAME "org.tizen.system.sensord"
-#define SENSORD_OBJECT_PATH "/Org/Tizen/System/SensorD"
-#define SENSORD_INTERFACE_NAME SENSORD_BUS_NAME
-
-enum dbus_ret {
- DBUS_INIT = -1,
- DBUS_FAILED = 0,
- DBUS_SUCCESS = 1
-};
-
-int get_lcdon_count(void);
-void increase_lcdon_count(void);
-void reset_lcdon_count(void);
-
-int get_total_count(void);
-void increase_total_count(void);
-void reset_total_count(void);
-void set_wrist_up_algo(int mode);
-
-void init_dbus(void);
-void fini_dbus(void);
-
-#endif /* SENSORD_GDBUS_H_ */
*/
#include <sensor_log.h>
-#include <dbus_util.h>
#include <new>
#include <csignal>
std::set_new_handler(on_new_failed);
- init_dbus();
-
server::run();
- fini_dbus();
-
_I("Stopped");
return 0;
, m_sensor(sensor)
, m_hal_id(hal_id)
, m_prev_interval(0)
+, m_prev_latency(0)
{
}
int physical_sensor_handler::read_fd(std::vector<uint32_t> &ids)
{
- retv_if(observer_count() == 0, OP_ERROR);
retv_if(!m_device, -EINVAL);
int size;
{
retv_if(!m_device, -EINVAL);
+ bool ret;
int policy = OP_DEFAULT;
+ ret = add_observer(ob);
+ retvm_if(!ret, OP_SUCCESS, "Listener is already added");
+
if (m_sensor) {
policy = m_sensor->start(ob);
- retv_if(policy <= OP_ERROR, policy);
+ if (policy <= OP_ERROR) {
+ remove_observer(ob);
+ return policy;
+ }
}
- add_observer(ob);
-
if (policy == OP_DEFAULT) {
if (observer_count() > 1)
return OP_SUCCESS; /* already started */
std::vector<int> temp;
for (auto it = m_batch_latency_map.begin(); it != m_batch_latency_map.end(); ++it)
- if (it->second > 0)
- temp.push_back(it->second);
+ temp.push_back(it->second);
if (temp.empty())
- return 0;
+ return -1;
batch_latency = *std::min_element(temp.begin(), temp.end());
retv_if(!m_device, -EINVAL);
bool ret = false;
- int _latency = latency;
+ int32_t cur_latency = latency;
int policy = OP_DEFAULT;
if (m_sensor) {
retv_if(policy <= OP_ERROR, policy);
}
- m_batch_latency_map[ob] = _latency;
+ m_batch_latency_map[ob] = cur_latency;
+
+ if (policy == OP_DEFAULT)
+ cur_latency = get_min_batch_latency();
+
+ retv_if(m_prev_latency == cur_latency, OP_SUCCESS);
+
+ ret = m_device->set_batch_latency(m_hal_id, cur_latency);
+
+ m_prev_latency = cur_latency;
+
+ _I("Set batch latency[%d] to sensor[%s]", cur_latency, m_info.get_uri().c_str());
+
+ return (ret ? OP_SUCCESS : OP_ERROR);
+}
+
+int physical_sensor_handler::delete_batch_latency(sensor_observer *ob)
+{
+ bool ret = false;
+ int policy = OP_DEFAULT;
+ int32_t latency;
+
+ m_batch_latency_map.erase(ob);
+
+ latency = get_min_batch_latency();
+ retv_if(m_prev_latency == latency, OP_SUCCESS);
- if (_latency <= latency)
- return OP_SUCCESS;
+ ret = m_device->set_batch_latency(m_hal_id, latency);
- ret = m_device->set_batch_latency(m_hal_id, _latency);
+ m_prev_latency = latency;
return (ret ? OP_SUCCESS : OP_ERROR);
}
int set_interval(sensor_observer *ob, int32_t interval);
int set_batch_latency(sensor_observer *ob, int32_t latency);
+ int delete_batch_latency(sensor_observer *ob);
int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
int flush(sensor_observer *ob);
physical_sensor *m_sensor;
uint32_t m_hal_id;
int32_t m_prev_interval;
+ int32_t m_prev_latency;
std::unordered_map<sensor_observer *, int> m_interval_map;
std::unordered_map<sensor_observer *, int> m_batch_latency_map;
static std::vector<uint32_t> ids;
-sensor_event_handler::sensor_event_handler(physical_sensor_handler *sensor)
-: m_sensor(sensor)
+sensor_event_handler::sensor_event_handler()
{
}
+void sensor_event_handler::add_sensor(physical_sensor_handler *sensor)
+{
+ ret_if(!sensor);
+
+ m_sensors.insert(sensor);
+}
+
+void sensor_event_handler::remove_sensor(physical_sensor_handler *sensor)
+{
+ ret_if(!sensor);
+
+ m_sensors.erase(sensor);
+}
+
bool sensor_event_handler::handle(int fd, ipc::event_condition condition)
{
sensor_info info;
- sensor_data_t *data = NULL;
+ sensor_data_t *data;
+ physical_sensor_handler *sensor;
int length = 0;
- int remains = 1;
+ int remains;
- if (m_sensor->read_fd(ids) < 0)
- return true;
+ retv_if(m_sensors.empty(), false);
+
+ ids.clear();
- auto result = std::find(std::begin(ids), std::end(ids), m_sensor->get_hal_id());
+ auto it = m_sensors.begin();
- if (result == std::end(ids))
- {
- ids.clear();
+ /* sensors using the same fd share read_fd in common.
+ * so just call read_fd on the first sensor */
+ if ((*it)->read_fd(ids) < 0)
return true;
- }
- while (remains > 0) {
- remains = m_sensor->get_data(&data, &length);
- if (remains < 0) {
- _E("Failed to get sensor data");
- break;
- }
+ for (; it != m_sensors.end(); ++it) {
+ remains = 1;
+ sensor = *it;
- if (m_sensor->on_event(data, length, remains) < 0) {
- free(data);
- data = NULL;
+ /* check whether the id of this sensor is in id list(parameter) or not */
+ auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id());
+ if (result == std::end(ids))
continue;
- }
- info = m_sensor->get_sensor_info();
+ while (remains > 0) {
+ remains = sensor->get_data(&data, &length);
+ if (remains < 0) {
+ _E("Failed to get sensor data");
+ break;
+ }
+
+ if (sensor->on_event(data, length, remains) < 0) {
+ free(data);
+ continue;
+ }
+
+ info = sensor->get_sensor_info();
- //_I("[Data] allocate %p", data);
- if (data) {
- if (m_sensor->notify(info.get_uri().c_str(), data, length) < 0) {
+ //_I("[Data] allocate %p", data);
+ if (sensor->notify(info.get_uri().c_str(), data, length) < 0) {
free(data);
- data = NULL;
}
+ info.clear();
}
- info.clear();
}
- ids.clear();
-
return true;
}
#define __SENSOR_EVENT_HANDLER__
#include <event_handler.h>
+#include <set>
+
#include "physical_sensor_handler.h"
namespace sensor {
class sensor_event_handler : public ipc::event_handler
{
public:
- sensor_event_handler(physical_sensor_handler *sensor);
+ sensor_event_handler();
+
+ void add_sensor(physical_sensor_handler *sensor);
+ void remove_sensor(physical_sensor_handler *sensor);
bool handle(int fd, ipc::event_condition condition);
private:
- physical_sensor_handler *m_sensor;
+ std::set<physical_sensor_handler *> m_sensors;
};
}
case EXERCISE_STANDALONE_SENSOR:
m_info.add_privilege(PRIVILEGE_LOCATION_URI);
break;
+ case GPS_CTRL_SENSOR:
+ m_info.add_privilege(PRIVILEGE_PLATFORM_URI);
+ break;
default:
break;
}
return false;
}
-void sensor_handler::add_observer(sensor_observer *ob)
+bool sensor_handler::add_observer(sensor_observer *ob)
{
- ret_if(has_observer(ob));
+ retv_if(has_observer(ob), false);
m_observers.push_back(ob);
+ return true;
}
void sensor_handler::remove_observer(sensor_observer *ob)
for (auto it = m_observers.begin(); it != m_observers.end(); ++it)
(*it)->update(uri, msg);
- if (msg->ref_count() == 0) {
- delete msg;
- msg = NULL;
- }
-
set_cache(data, len);
+ if (msg->ref_count() == 0)
+ msg->unref();
+
return OP_SUCCESS;
}
void sensor_handler::set_cache(sensor_data_t *data, int size)
{
- retm_if(data == NULL, "Nothing to copy from as source is NULL");
- retm_if(size <= 0, "data is of size 0");
-
- if (m_last_data_size != size) {
- m_last_data = (sensor_data_t*)realloc(m_last_data, size);
+ if (m_last_data == NULL) {
+ m_last_data = (sensor_data_t*)malloc(size);
retm_if(m_last_data == NULL, "Memory allocation failed");
- m_last_data_size = size;
}
+ m_last_data_size = size;
memcpy(m_last_data, data, size);
}
return 0;
}
+
+int sensor_handler::delete_batch_latency(sensor_observer *ob)
+{
+ return 0;
+}
/* publisher */
bool has_observer(sensor_observer *ob);
- void add_observer(sensor_observer *ob);
+ bool add_observer(sensor_observer *ob);
void remove_observer(sensor_observer *ob);
int notify(const char *type, sensor_data_t *data, int len);
uint32_t observer_count(void);
virtual int set_interval(sensor_observer *ob, int32_t interval) = 0;
virtual int set_batch_latency(sensor_observer *ob, int32_t latency) = 0;
+ virtual int delete_batch_latency(sensor_observer *ob);
virtual int set_attribute(sensor_observer *ob, int32_t attr, int32_t value) = 0;
virtual int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) = 0;
virtual int flush(sensor_observer *ob) = 0;
#include <sensor_types.h>
#include "sensor_handler.h"
+#include "sensor_policy_monitor.h"
using namespace sensor;
, m_uri(uri)
, m_manager(manager)
, m_ch(ch)
+, m_started(false)
, m_passive(false)
, m_pause_policy(SENSORD_PAUSE_ALL)
, m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED)
, m_last_accuracy(SENSOR_ACCURACY_UNDEFINED)
{
+ sensor_policy_monitor::get_instance().add_listener(this);
}
sensor_listener_proxy::~sensor_listener_proxy()
{
+ sensor_policy_monitor::get_instance().remove_listener(this);
stop();
}
m_ch->send(acc_msg);
}
-int sensor_listener_proxy::start(void)
+int sensor_listener_proxy::start(bool policy)
{
+ int ret;
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
+ retvm_if(m_started && !policy, OP_SUCCESS, "Sensor is already started");
_D("Listener[%d] try to start", get_id());
- /* TODO: listen pause policy */
- return sensor->start(this);
+ ret = sensor->start(this);
+ retv_if (ret < 0, OP_ERROR);
+
+ /* m_started is changed only when it is explicitly called by user,
+ * not automatically determined by any pause policy. */
+ if (policy)
+ return OP_SUCCESS;
+
+ m_started = true;
+ return OP_SUCCESS;
}
-int sensor_listener_proxy::stop(void)
+int sensor_listener_proxy::stop(bool policy)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
-
- /* TODO: listen pause policy */
+ retvm_if(!m_started && !policy, OP_SUCCESS, "Sensor is already stopped");
_D("Listener[%d] try to stop", get_id());
int ret = sensor->stop(this);
retv_if(ret < 0, OP_ERROR);
+ /* attributes and m_started are changed only when it is explicitly called by user,
+ * not automatically determined by any policy. */
+ if (policy)
+ return OP_SUCCESS;
+
/* unset attributes */
- set_interval(POLL_1HZ_MS);
- set_max_batch_latency(0);
+ set_interval(POLL_MAX_HZ_MS);
+ delete_batch_latency();
+ m_started = false;
return OP_SUCCESS;
}
return sensor->set_batch_latency(this, max_batch_latency);
}
+int sensor_listener_proxy::delete_batch_latency(void)
+{
+ sensor_handler *sensor = m_manager->get_sensor(m_uri);
+ retv_if(!sensor, -EINVAL);
+
+ _I("Listener[%d] try to delete batch latency", get_id());
+
+ return sensor->delete_batch_latency(this);
+}
+
int sensor_listener_proxy::set_passive_mode(bool passive)
{
/* TODO: passive mode */
} else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) {
m_axis_orientation = value;
return OP_SUCCESS;
+ } else if (attribute == SENSORD_ATTRIBUTE_FLUSH) {
+ return flush();
}
return sensor->set_attribute(this, attribute, value);
sensor_info info = sensor->get_sensor_info();
return info.get_privilege();
}
+
+void sensor_listener_proxy::on_policy_changed(int policy, int value)
+{
+ ret_if(m_started == false);
+ ret_if(policy != SENSORD_ATTRIBUTE_PAUSE_POLICY);
+ ret_if(m_pause_policy == SENSORD_PAUSE_NONE);
+
+ _D("power_save_state[%d], listener[%d] pause policy[%d]",
+ value, get_id(), m_pause_policy);
+
+ if (value & m_pause_policy)
+ stop(true);
+ if (!(value & m_pause_policy))
+ start(true);
+}
#include "sensor_manager.h"
#include "sensor_observer.h"
+#include "sensor_policy_listener.h"
namespace sensor {
-class sensor_listener_proxy : public sensor_observer {
+class sensor_listener_proxy : public sensor_observer, sensor_policy_listener {
public:
sensor_listener_proxy(uint32_t id,
std::string uri, sensor_manager *manager, ipc::channel *ch);
/* sensor observer */
int update(const char *uri, ipc::message *msg);
- int start(void);
- int stop(void);
+ int start(bool policy = false);
+ int stop(bool policy = false);
int set_interval(unsigned int interval);
int set_max_batch_latency(unsigned int max_batch_latency);
+ int delete_batch_latency(void);
int set_passive_mode(bool passive);
int set_attribute(int attribute, int value);
int set_attribute(int attribute, const char *value, int len);
int get_data(sensor_data_t **data, int *len);
std::string get_required_privileges(void);
+ /* sensor_policy_listener interface */
+ void on_policy_changed(int policy, int value);
+
private:
void update_event(ipc::message *msg);
void update_accuracy(ipc::message *msg);
sensor_manager *m_manager;
ipc::channel *m_ch;
+ bool m_started;
bool m_passive;
int m_pause_policy;
int m_axis_orientation;
int size;
size = serialize(info, &bytes);
- retm_if(size == -ENOMEM, "Failed to serialize");
ipc::message msg((const char *)bytes, size);
msg.set_type(CMD_MANAGER_SENSOR_ADDED);
send(msg);
- delete []bytes;
}
void sensor_manager::send_removed_msg(const std::string &uri)
return sensors;
}
+static physical_sensor *create_physical_sensor(std::string uri, physical_sensor_registry_t &psensors)
+{
+ for (auto it = psensors.begin(); it != psensors.end(); ++it) {
+ if (uri.find((*it)->get_uri()) != std::string::npos) {
+ _D("%s, %s", uri.c_str(), (*it)->get_uri().c_str());
+ return (*it)->clone();
+ }
+ }
+
+ return NULL;
+}
+
void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices,
physical_sensor_registry_t &psensors)
{
int count = (*it)->get_sensors(&info);
for (int i = 0; i < count; ++i) {
- /* TODO: psensors */
+ physical_sensor *sensor = NULL;
+ sensor_info pinfo(info[i]);
+ std::string uri = pinfo.get_uri();
+
+ sensor = create_physical_sensor(uri, psensors);
+ if (sensor)
+ sensor->set_device(it->get());
+
psensor = new(std::nothrow) physical_sensor_handler(
- info[i], it->get(), info[i].id, NULL);
+ info[i], it->get(), info[i].id, sensor);
retm_if(!psensor, "Failed to allocate memory");
- sensor_info sinfo = psensor->get_sensor_info();
- m_sensors[sinfo.get_uri()] = psensor;
+ m_sensors[uri] = psensor;
}
}
}
void sensor_manager::register_handler(physical_sensor_handler *sensor)
{
- ret_if(sensor->get_poll_fd() < 0);
+ sensor_event_handler *handler = NULL;
+ int fd = sensor->get_poll_fd();
+
+ ret_if(fd < 0);
+
+ auto it = m_event_handlers.find(fd);
- sensor_event_handler *handler = new(std::nothrow) sensor_event_handler(sensor);
+ if (it != m_event_handlers.end()) {
+ it->second->add_sensor(sensor);
+ return;
+ }
+
+ handler = new(std::nothrow) sensor_event_handler();
retm_if(!handler, "Failed to allocate memory");
- m_loop->add_event(sensor->get_poll_fd(),
+ handler->add_sensor(sensor);
+ m_event_handlers[fd] = handler;
+
+ m_loop->add_event(fd,
ipc::EVENT_IN | ipc::EVENT_HUP | ipc::EVENT_NVAL, handler);
}
#include "physical_sensor_handler.h"
#include "fusion_sensor_handler.h"
#include "external_sensor_handler.h"
+#include "sensor_event_handler.h"
namespace sensor {
sensor_map_t m_sensors;
std::vector<ipc::channel *> m_channels;
+ std::map<int, sensor_event_handler *> m_event_handlers;
};
}
/*
* sensord
*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
*
*/
-#ifndef _HRM_SENSOR_H_
-#define _HRM_SENSOR_H_
+#ifndef __SENSOR_POLICY_LISTENER_H__
+#define __SENSOR_POLICY_LISTENER_H__
-#include <physical_sensor.h>
-
-class hrm_sensor : public physical_sensor {
+namespace sensor {
+class sensor_policy_listener {
public:
- hrm_sensor();
- virtual ~hrm_sensor();
-};
+ virtual ~sensor_policy_listener() {}
-#endif /* _HRM_SENSOR_H_ */
+ virtual void on_policy_changed(int policy, int value) = 0;
+};
+}
+#endif /* __SENSOR_POLICY_LISTENER_H__ */
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "sensor_policy_monitor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#ifndef VCONFKEY_SETAPPL_PSMODE
+#define VCONFKEY_SETAPPL_PSMODE "db/setting/psmode"
+#endif
+
+using namespace sensor;
+
+static int get_power_save_state(void)
+{
+ int ret;
+ int state = 0;
+ int pm_state, ps_state;
+
+ ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
+
+ if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF)
+ state |= SENSORD_PAUSE_ON_DISPLAY_OFF;
+
+ ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state);
+
+ if (!ret && ps_state != SETTING_PSMODE_NORMAL)
+ state |= SENSORD_PAUSE_ON_POWERSAVE_MODE;
+
+ return state;
+}
+
+static void power_save_state_cb(keynode_t *node, void *data)
+{
+ int power_save_state = get_power_save_state();
+
+ sensor_policy_monitor::get_instance().on_policy_changed(SENSORD_ATTRIBUTE_PAUSE_POLICY, power_save_state);
+}
+
+sensor_policy_monitor& sensor_policy_monitor::get_instance(void)
+{
+ static sensor_policy_monitor mon;
+ return mon;
+}
+
+sensor_policy_monitor::sensor_policy_monitor()
+{
+ vconf_notify_key_changed(VCONFKEY_PM_STATE, power_save_state_cb, NULL);
+ vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb, NULL);
+}
+
+sensor_policy_monitor::~sensor_policy_monitor()
+{
+ vconf_ignore_key_changed(VCONFKEY_PM_STATE, power_save_state_cb);
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb);
+}
+
+void sensor_policy_monitor::add_listener(sensor_policy_listener *listener)
+{
+ ret_if(!listener);
+
+ m_listeners.insert(listener);
+}
+
+void sensor_policy_monitor::remove_listener(sensor_policy_listener *listener)
+{
+ ret_if(!listener);
+
+ m_listeners.erase(listener);
+}
+
+void sensor_policy_monitor::on_policy_changed(int policy, int value)
+{
+ auto it = m_listeners.begin();
+
+ while (it != m_listeners.end()) {
+ (*it)->on_policy_changed(policy, value);
+ ++it;
+ }
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 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_POLICY_MONITOR_H__
+#define __SENSOR_POLICY_MONITOR_H__
+
+#include <channel.h>
+#include <message.h>
+#include <vconf.h>
+#include <set>
+
+#include "sensor_policy_listener.h"
+
+namespace sensor {
+
+class sensor_policy_monitor {
+public:
+ ~sensor_policy_monitor();
+
+ static sensor_policy_monitor& get_instance(void);
+
+ void add_listener(sensor_policy_listener *listener);
+ void remove_listener(sensor_policy_listener *listener);
+
+ void on_policy_changed(int policy, int value);
+
+private:
+ sensor_policy_monitor();
+
+ std::set<sensor_policy_listener *> m_listeners;
+};
+
+}
+
+#endif /* __SENSOR_POLICY_MONITOR_H__ */
virtual ~sensor_publisher() {}
virtual bool has_observer(sensor_observer *ob) = 0;
- virtual void add_observer(sensor_observer *ob) = 0;
+ virtual bool add_observer(sensor_observer *ob) = 0;
virtual void remove_observer(sensor_observer *ob) = 0;
virtual int notify(const char *type, sensor_data_t *data, int len) = 0;
};
msg.disclose((char *)&buf);
- sensor_listener_proxy *listener = NULL;
+ sensor_listener_proxy *listener;
listener = new(std::nothrow) sensor_listener_proxy(listener_id,
buf.sensor, m_manager, ch);
retvm_if(!listener, OP_ERROR, "Failed to allocate memory");
-
- if (!has_privileges(ch->get_fd(), listener->get_required_privileges())) {
- delete listener;
- listener = NULL;
- _E("Permission denied[%d, %s]", listener_id,
- m_listeners[listener_id]->get_required_privileges().c_str());
- return -EACCES;
- }
+ retvm_if(!has_privileges(ch->get_fd(), listener->get_required_privileges()),
+ -EACCES, "Permission denied[%d, %s]",
+ listener_id, m_listeners[listener_id]->get_required_privileges().c_str());
buf.listener_id = listener_id;
reply.enclose((const char *)&buf, sizeof(buf));
reply.header()->err = OP_SUCCESS;
- if (!ch->send_sync(&reply)) {
- delete listener;
+ if (!ch->send_sync(&reply))
return OP_ERROR;
- }
_I("Connected sensor_listener[fd(%d) -> id(%u)]", ch->get_fd(), listener_id);
m_listeners[listener_id] = listener;
}
/* TODO : check return value */
if (ret < 0)
- _W("Return : %d", ret);
+ _D("Return : %d", ret);
return send_reply(ch, OP_SUCCESS);
}
return -EACCES;
}
- int ret = m_listeners[id]->set_attribute(buf->attribute, (char *)&buf->value, buf->len);
+ int ret = m_listeners[id]->set_attribute(buf->attribute, buf->value, buf->len);
if (ret < 0) {
delete [] buf;
return ret;
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(sensord-shared CXX)
-SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0")
+SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0 vconf libtzplatform-config")
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(SHARED_PKGS REQUIRED ${DEPENDENTS})
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <pthread.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <cbase_lock.h>
+#include <sensor_log.h>
+
+cbase_lock::cbase_lock()
+{
+ m_history_mutex = PTHREAD_MUTEX_INITIALIZER;
+}
+
+cbase_lock::~cbase_lock()
+{
+ pthread_mutex_destroy(&m_history_mutex);
+}
+
+void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line)
+{
+ int ret = 0;
+ char m_curent_info[OWNER_INFO_LEN];
+ struct timeval sv;
+ unsigned long long lock_waiting_start_time = 0;
+ unsigned long long lock_acquired_time = 0;
+ unsigned long long waiting_time = 0;
+
+ snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line);
+
+ if (type == LOCK_TYPE_MUTEX)
+ ret = try_lock_impl();
+ else if (type == LOCK_TYPE_READ)
+ ret = try_read_lock_impl();
+ else if (type == LOCK_TYPE_WRITE)
+ ret = try_write_lock_impl();
+
+ if (ret == 0) {
+ pthread_mutex_lock(&m_history_mutex);
+ snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
+ pthread_mutex_unlock(&m_history_mutex);
+ return;
+ }
+
+ gettimeofday(&sv, NULL);
+ lock_waiting_start_time = MICROSECONDS(sv);
+
+ pthread_mutex_lock(&m_history_mutex);
+ _I("%s is waiting for getting %s(%#x) owned in %s",
+ m_curent_info, expr, this, m_owner_info);
+ pthread_mutex_unlock(&m_history_mutex);
+
+ if (type == LOCK_TYPE_MUTEX)
+ lock_impl();
+ else if (type == LOCK_TYPE_READ)
+ read_lock_impl();
+ else if (type == LOCK_TYPE_WRITE)
+ write_lock_impl();
+
+ gettimeofday(&sv, NULL);
+ lock_acquired_time = MICROSECONDS(sv);
+
+ waiting_time = lock_acquired_time - lock_waiting_start_time;
+
+ pthread_mutex_lock(&m_history_mutex);
+ _I("%s acquires lock after waiting %lluus, %s(%#x) was previously owned in %s",
+ m_curent_info, waiting_time, expr, this, m_owner_info);
+ snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
+ pthread_mutex_unlock(&m_history_mutex);
+}
+
+void cbase_lock::lock(lock_type type)
+{
+ if (type == LOCK_TYPE_MUTEX)
+ lock_impl();
+ else if (type == LOCK_TYPE_READ)
+ read_lock_impl();
+ else if (type == LOCK_TYPE_WRITE)
+ write_lock_impl();
+}
+
+void cbase_lock::unlock(void)
+{
+ unlock_impl();
+}
+
+int cbase_lock::lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::read_lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::write_lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::try_lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::try_read_lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::try_write_lock_impl(void)
+{
+ return 0;
+}
+
+int cbase_lock::unlock_impl(void)
+{
+ return 0;
+}
+
+Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line)
+: m_lock(m)
+{
+ m_lock.lock(type, expr, module, func, line);
+}
+
+Autolock::Autolock(cbase_lock &m, lock_type type)
+: m_lock(m)
+{
+ m_lock.lock(type);
+}
+
+Autolock::~Autolock()
+{
+ m_lock.unlock();
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2013 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 _CBASE_LOCK_H_
+#define _CBASE_LOCK_H_
+
+#include <pthread.h>
+
+enum lock_type {
+ LOCK_TYPE_MUTEX,
+ LOCK_TYPE_READ,
+ LOCK_TYPE_WRITE,
+};
+
+#ifndef MICROSECONDS
+#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+#endif
+
+#ifdef _LOCK_DEBUG
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
+#define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__)
+#define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
+#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
+#define UNLOCK(x) (x).unlock()
+#else
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE)
+#define LOCK(x) (x).lock()
+#define LOCK_R(x) (x).lock(LOCK_TYPE_READ)
+#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE)
+#define UNLOCK(x) (x).unlock()
+#endif
+
+class cbase_lock {
+public:
+ cbase_lock();
+ virtual ~cbase_lock();
+
+ void lock(lock_type type, const char* expr, const char *module, const char *func, int line);
+ void lock(lock_type type);
+ void unlock(void);
+
+protected:
+ virtual int lock_impl(void);
+ virtual int read_lock_impl(void);
+ virtual int write_lock_impl(void);
+
+ virtual int try_lock_impl(void);
+ virtual int try_read_lock_impl(void);
+ virtual int try_write_lock_impl(void);
+
+ virtual int unlock_impl(void);
+private:
+ pthread_mutex_t m_history_mutex;
+ static const int OWNER_INFO_LEN = 256;
+ char m_owner_info[OWNER_INFO_LEN];
+};
+
+class Autolock {
+private:
+ cbase_lock& m_lock;
+public:
+ Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line);
+ Autolock(cbase_lock &m, lock_type type);
+ ~Autolock();
+};
+
+#endif /* _CBASE_LOCK_H_ */
#include "sensor_log.h"
#include "channel_event_handler.h"
-#define SYSTEMD_SOCK_BUF_SIZE 40000
+#define SYSTEMD_SOCK_BUF_SIZE (128*1024)
using namespace ipc;
if (!m_ch->send_sync(m_msg))
return false;
- if (m_msg) {
+ if (m_msg)
m_msg->unref();
- if(m_msg->ref_count() <= 0) {
- delete m_msg;
- m_msg = NULL;
- }
- }
return false;
}
, m_loop(NULL)
, m_connected(false)
{
+ _D("Created");
}
channel::~channel()
{
- /* disconnect() should not be called here */
+ _D("Destroyed[%llu]", m_event_id);
+ disconnect();
}
-void channel::bind(channel_handler *handler, event_loop *loop)
+uint64_t channel::bind(void)
+{
+ retv_if(!m_loop, 0);
+ m_event_id = m_loop->add_event(m_socket->get_fd(),
+ (EVENT_IN | EVENT_HUP | EVENT_NVAL),
+ dynamic_cast<channel_event_handler *>(m_handler));
+
+ _D("Bound[%llu]", m_event_id);
+ return m_event_id;
+}
+
+uint64_t channel::bind(channel_handler *handler, event_loop *loop, bool loop_bind)
{
m_handler = handler;
m_loop = loop;
if (m_handler)
m_handler->connected(this);
-}
-void channel::bind(void)
-{
- ret_if(!m_loop);
- m_event_id = m_loop->add_event(m_socket->get_fd(),
- (EVENT_IN | EVENT_HUP | EVENT_NVAL),
- dynamic_cast<channel_event_handler *>(m_handler));
+ if (loop_bind)
+ bind();
+
+ return m_event_id;
}
-bool channel::connect(channel_handler *handler, event_loop *loop)
+uint64_t channel::connect(channel_handler *handler, event_loop *loop, bool loop_bind)
{
if (!m_socket->connect())
return false;
- bind(handler, loop);
- return true;
+ bind(handler, loop, loop_bind);
+
+ _D("Connected[%llu]", m_event_id);
+ return m_event_id;
}
void channel::disconnect(void)
{
- ret_if(!is_connected());
+ if (!is_connected()) {
+ _D("Channel is not connected");
+ return;
+ }
+
m_connected.store(false);
+ _D("Disconnecting..[%llu]", m_event_id);
+
if (m_handler) {
m_handler->disconnected(this);
m_handler = NULL;
}
if (m_loop) {
+ _D("Remove event[%llu]", m_event_id);
m_loop->remove_event(m_event_id, true);
m_loop = NULL;
m_event_id = 0;
}
if (m_socket) {
+ _D("Release socket[%d]", m_socket->get_fd());
delete m_socket;
m_socket = NULL;
}
+
+ _D("Disconnected");
}
bool channel::send(message *msg)
{
+ int retry_cnt = 0;
+ int cur_buffer_size = 0;
+
retv_if(!m_loop, false);
- int cur_buffer_size = m_socket->get_current_buffer_size();
- retv_if(cur_buffer_size > SYSTEMD_SOCK_BUF_SIZE, false);
+ while (retry_cnt < 3) {
+ cur_buffer_size = m_socket->get_current_buffer_size();
+ if (cur_buffer_size <= SYSTEMD_SOCK_BUF_SIZE)
+ break;
+ usleep(3000);
+ retry_cnt++;
+ }
+ retvm_if(retry_cnt >= 3, false, "Socket buffer[%d] is exceeded", cur_buffer_size);
send_event_handler *handler = new(std::nothrow) send_event_handler(this, msg);
retvm_if(!handler, false, "Failed to allocate memory");
bool channel::send_sync(message *msg)
{
- retv_if(!msg, false);
+ retvm_if(!msg, false, "Invalid message");
+ retvm_if(msg->size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg->size());
ssize_t size = 0;
char *buf = msg->body();
/* header */
size = m_socket->send(reinterpret_cast<void *>(msg->header()),
- sizeof(message_header), true);
- retv_if(size <= 0, false);
- retv_if(msg->size() <= 0, true);
+ sizeof(message_header), true);
+ retvm_if(size <= 0, false, "Failed to send header");
+
+ /* if body size is zero, skip to send body message */
+ retv_if(msg->size() == 0, true);
/* body */
size = m_socket->send(buf, msg->size(), true);
- retv_if(size <= 0, false);
+ retvm_if(size <= 0, false, "Failed to send body");
return true;
}
}
/* body */
+ if (header.length >= MAX_MSG_CAPACITY) {
+ _E("header.length error %u", header.length);
+ return false;
+ }
+
if (header.length > 0) {
size = m_socket->recv(&buf, header.length, select);
retv_if(size <= 0, false);
{
return m_fd;
}
-
-void channel::set_event_id(uint64_t id)
-{
- m_event_id = id;
-}
channel(socket *sock);
~channel();
- /* TODO */
- void bind(void);
- void bind(channel_handler *handler, event_loop *loop);
+ uint64_t bind(void);
+ uint64_t bind(channel_handler *handler, event_loop *loop, bool loop_bind);
- bool connect(channel_handler *handler, event_loop *loop);
+ uint64_t connect(channel_handler *handler, event_loop *loop, bool loop_bind);
void disconnect(void);
bool is_connected(void);
bool set_option(int type, int value);
int get_fd(void) const;
- void set_event_id(uint64_t id);
private:
int m_fd;
return false;
if (condition & (EVENT_HUP)) {
+ _D("The other proccess is dead");
m_ch->disconnect();
+ m_ch = NULL;
return false;
}
if (!m_ch->read_sync(msg, false)) {
- m_ch->disconnect();
+ m_ch = NULL;
return false;
}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <cmutex.h>
+#include <sensor_log.h>
+
+cmutex::cmutex()
+{
+ pthread_mutexattr_t mutex_attr;
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&m_mutex, &mutex_attr);
+ pthread_mutexattr_destroy(&mutex_attr);
+}
+
+cmutex::~cmutex()
+{
+ pthread_mutex_destroy(&m_mutex);
+}
+
+void cmutex::lock(void)
+{
+#ifdef _LOCK_DEBUG
+ cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__);
+#else
+ cbase_lock::lock(LOCK_TYPE_MUTEX);
+#endif
+}
+
+void cmutex::lock(const char* expr, const char *module, const char *func, int line)
+{
+ cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line);
+}
+
+int cmutex::lock_impl(void)
+{
+ return pthread_mutex_lock(&m_mutex);
+}
+
+int cmutex::try_lock_impl(void)
+{
+ return pthread_mutex_trylock(&m_mutex);
+}
+
+int cmutex::unlock_impl(void)
+{
+ return pthread_mutex_unlock(&m_mutex);
+}
/*
* sensord
*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2013 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.
*
*/
-#ifndef _ACCEL_SENSOR_H_
-#define _ACCEL_SENSOR_H_
+#ifndef _CMUTEX_H_
+#define _CMUTEX_H_
-#include <physical_sensor.h>
+#include "cbase_lock.h"
-class accel_sensor : public physical_sensor {
+class cmutex : public cbase_lock {
public:
- accel_sensor();
- ~accel_sensor();
+ cmutex();
+ virtual ~cmutex();
- sensor_type_t get_type(void);
-};
+ void lock(void);
+ void lock(const char* expr, const char *module, const char *func, int line);
+
+protected:
+ int lock_impl(void);
+ int try_lock_impl(void);
+ int unlock_impl(void);
-#endif /* _ACCEL_SENSOR_H_ */
+private:
+ pthread_mutex_t m_mutex;
+};
+#endif /* _CMUTEX_H_ */
#include "sensor_info.h"
#define SENSOR_CHANNEL_PATH "/run/.sensord.socket"
-#define MAX_BUF_SIZE 10240
+#define MAX_BUF_SIZE (16*1024)
/* TODO: OOP - create serializer interface */
enum cmd_type_e {
CMD_PROVIDER_STOP,
CMD_PROVIDER_ATTR_INT,
CMD_PROVIDER_PUBLISH,
+ CMD_PROVIDER_ATTR_STR,
/* Etc */
CMD_HAS_PRIVILEGE = 0x1000,
int value;
} cmd_provider_attr_int_t;
+typedef struct {
+ int attribute;
+ int len;
+ char value[0];
+} cmd_provider_attr_str_t;
+
typedef struct {
char sensor[NAME_MAX];
} cmd_has_privilege_t ;
, m_sequence(1)
, m_term_fd(-1)
{
- if (m_mainloop) {
- g_main_loop_quit(m_mainloop);
- g_main_loop_unref(m_mainloop);
- }
-
m_mainloop = mainloop;
}
event_loop::~event_loop()
{
- remove_all_events();
+ _D("Destoryed");
+}
+
+void event_loop::set_mainloop(GMainLoop *mainloop)
+{
+ retm_if(!mainloop, "Invalid mainloop");
+
+ m_mainloop = mainloop;
}
uint64_t event_loop::add_event(const int fd, const event_condition cond, event_handler *handler)
m_handlers[id] = info;
- /* _D("Added[%llu](fd:%d)", id, fd); */
+ /* _D("Added event[%llu], fd[%d]", id, fd); */
return id;
}
{
GSource *src;
- retvm_if(m_terminating.load(), false,
+ retvm_if(m_terminating.load(), 0,
"Failed to remove event, because event_loop is terminated");
src = g_idle_source_new();
- retvm_if(!src, false, "Failed to allocate memory");
+ retvm_if(!src, 0, "Failed to allocate memory");
g_source_unref(src);
/* Not Supported yet */
- return false;
+ return 0;
}
bool event_loop::remove_event(uint64_t id, bool close_channel)
g_io_channel_shutdown(it->second->g_ch, TRUE, NULL);
release_info(it->second);
- m_handlers.erase(it);
+ m_handlers.erase(id);
- /* _D("Removed[%llu]", id); */
+ /* _D("Removed event[%llu]", id); */
return true;
}
void event_loop::release_info(handler_info *info)
{
- ret_if(!info->g_ch || info->id == 0);
+ retm_if(!info->g_ch || info->id == 0, "Invalid handler information");
+ /* _D("Releasing event..[%llu]", info->id); */
g_source_destroy(info->g_src);
g_source_unref(info->g_src);
- info->g_src = NULL;
g_io_channel_unref(info->g_ch);
info->g_ch = NULL;
info->handler = NULL;
delete info;
- info = NULL;
+
+ /* _D("Released event[%llu]", info->id); */
}
class terminator : public event_handler
bool event_loop::run(int timeout)
{
retvm_if(!m_mainloop, false, "Invalid GMainLoop");
- retv_if(is_running(), false);
+ retvm_if(is_running(), false, "Already started");
if (timeout > 0) {
GSource *src = g_timeout_source_new(timeout);
class handler_info {
public:
- handler_info(int64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop)
+ handler_info(uint64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop)
: id(_id)
, fd(_fd)
, g_ch(_ch)
event_loop(GMainLoop *mainloop);
~event_loop();
+ void set_mainloop(GMainLoop *mainloop);
+
uint64_t add_event(const int fd, const event_condition cond, event_handler *handler);
uint64_t add_idle_event(unsigned int priority, idle_handler *handler);
socket *sock = NULL;
channel *ch = NULL;
channel_event_handler *ev_handler = NULL;
- bool ret = false;
- retvm_if(access(m_path.c_str(), F_OK), NULL,
- "Failed to access to %s", m_path.c_str());
sock = new(std::nothrow) stream_socket();
retvm_if(!sock, NULL, "Failed to allocate memory");
if (!ev_handler) {
delete ch;
delete sock;
- _E("Faield to allocate memory");
+ _E("Failed to allocate memory");
return NULL;
}
- ret = ch->connect(ev_handler, loop);
- if(ret == false) {
- delete ch;
- delete sock;
- delete ev_handler;
- _E("Faield to connect");
- return NULL;
- }
+ uint64_t id = ch->connect(ev_handler, loop, bind);
- if (loop && bind) {
- uint64_t id = loop->add_event(sock->get_fd(),
- (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);
- ch->set_event_id(id);
- }
+ _D("Connected[%llu]", id);
- _I("Connected");
return ch;
}
{
m_accept_sock.accept(cli_sock);
- _I("Accepted[%d]", cli_sock.get_fd());
+ _D("Accepted[%d]", cli_sock.get_fd());
}
bool ipc_server::bind(channel_handler *handler, event_loop *loop)
register_acceptor();
- _I("Bound[%d]", m_accept_sock.get_fd());
+ _D("Bound[%d]", m_accept_sock.get_fd());
return true;
}
channel_event_handler *ev_handler = new(std::nothrow) channel_event_handler(ch, m_handler);
retm_if(!ev_handler, "Failed to allocate memory");
- ch->bind(ev_handler, m_event_loop);
- uint64_t id = m_event_loop->add_event(fd,
- (event_condition)(EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);
+ uint64_t id = ch->bind(ev_handler, m_event_loop, true);
if (id == 0)
delete ev_handler;
+
+ _D("Registered event[%llu]", id);
}
void ipc_server::register_acceptor(void)
m_handler = NULL;
- _I("Closed");
return true;
}
fclose(*f);
}
+static inline void int_to_bytes(int value, int width, char data[])
+{
+ /* Big-endian */
+ for (int i = width - 1; i >= 0; i--) {
+ data[i] = (value & 0xff);
+ value = value >> 8;
+ }
+}
+
+static inline unsigned int bytes_to_uint(char data[], int &cursor, int width)
+{
+ unsigned int sum = 0;
+
+ /* Big-endian */
+ for (int i = 0; i < width; ++i)
+ sum = (sum << 8) + (unsigned char)data[cursor++];
+
+ return sum;
+}
+
#define _cleanup_free_ _cleanup_(__freep)
#define _cleanup_close_ _cleanup_(__closep)
#define _cleanup_fclose_ _cleanup_(__fclosep)
+#define GET_BYTES(value, width, data) int_to_bytes(value, width, data)
+#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#include <sensor_log.h>
#include <atomic>
-#include <memory>
-
using namespace ipc;
message::message(size_t capacity)
: m_size(0)
, m_capacity(capacity)
-, m_msg(new(std::nothrow) char[sizeof(char) * capacity])
+, m_msg((char *)malloc(sizeof(char) * capacity))
, ref_cnt(0)
{
m_header.id = sequence++;
m_header.type = UNDEFINED_TYPE;
m_header.length = m_size;
m_header.err = 0;
-
- for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
- m_header.ancillary[i] = NULL;
}
message::message(const void *msg, size_t sz)
: m_size(sz)
, m_capacity(sz)
-, m_msg(new(std::nothrow) char[sizeof(char) * sz])
+, m_msg((char *)msg)
, ref_cnt(0)
{
m_header.id = sequence++;
m_header.type = UNDEFINED_TYPE;
m_header.length = m_size;
m_header.err = 0;
- ::memcpy(m_msg, msg, sz);
- for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
- m_header.ancillary[i] = NULL;
}
message::message(const message &msg)
: m_size(msg.m_size)
, m_capacity(msg.m_capacity)
-, m_msg(new(std::nothrow) char[(sizeof(char) * msg.m_capacity)])
+, m_msg((char *)malloc(sizeof(char) * msg.m_capacity))
, ref_cnt(0)
{
::memcpy(&m_header, &msg.m_header, sizeof(message_header));
m_header.type = UNDEFINED_TYPE;
m_header.length = 0;
m_header.err = error;
-
- for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
- m_header.ancillary[i] = NULL;
}
message::~message()
{
- if (m_msg) {
- delete [] m_msg;
+ if (m_msg && ref_cnt == 0) {
+ free(m_msg);
m_msg = NULL;
}
}
{
ref_cnt--;
- /*if (ref_cnt > 0 || !m_msg)
+ if (ref_cnt > 0 || !m_msg)
return;
- delete [] m_msg;
+ free(m_msg);
m_msg = NULL;
- delete this;*/
+ delete this;
}
int message::ref_count(void)
#include <stdlib.h> /* size_t */
#include <atomic>
-#define MAX_MSG_CAPACITY 10240
+#define MAX_MSG_CAPACITY (16*1024)
#define MAX_HEADER_RESERVED 3
namespace ipc {
#define LOG_DUMP(fp, fmt, arg...) \
do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
+#define log_oom() ({ \
+ _E("Out of memory"); \
+ -ENOMEM;})
+
+
#endif /* __SENSOR_LOG_H__ */
#define PRIVILEGE_LOCATION_STR "location"
#define PRIVILEGE_LOCATION_URI "http://tizen.org/privilege/location"
+#define PRIVILEGE_PLATFORM_STR "platform"
+#define PRIVILEGE_PLATFORM_URI "http://tizen.org/privilege/internal/default/platform"
+
#define URI_PRIV_INDEX 4
#define URI_SENSOR_TYPE_INDEX 5
{GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/general/gyroscope_rotation_vector"},
{GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/general/geomagnetic_rotation_vector"},
+ {SIGNIFICANT_MOTION_SENSOR, "http://tizen.org/sensor/general/significant_motion"},
+
{HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/human_pedometer"},
{HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_monitor"},
{HUMAN_SLEEP_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_detector"},
{EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.rowing"},
{EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.stepper"},
- {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/healthinfo/external_exercise"},
{FUSION_SENSOR, "http://tizen.org/sensor/general/fusion"},
{AUTO_ROTATION_SENSOR, "http://tizen.org/sensor/general/auto_rotation"},
{GESTURE_WRIST_UP_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_up"},
{GESTURE_WRIST_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_down"},
{GESTURE_MOVEMENT_STATE_SENSOR, "http://tizen.org/sensor/general/gesture_movement_state"},
+ {GESTURE_PICK_UP_SENSOR, "http://tizen.org/sensor/general/gesture_pick_up"},
{GESTURE_FACE_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_face_down"},
{ACTIVITY_TRACKER_SENSOR, "http://tizen.org/sensor/general/activity_tracker"},
{ACTIVITY_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/activity_level_monitor"},
{GPS_BATCH_SENSOR, "http://tizen.org/sensor/location/gps_batch"},
+ {PPG_BATCH_SENSOR, "http://tizen.org/sensor/healthinfo/ppg_batch"},
+ {GPS_TIMESYNC_SENSOR, "http://tizen.org/sensor/location/gps_timesync"},
{HRM_CTRL_SENSOR, "http://tizen.org/sensor/general/hrm_ctrl"},
+ {REG_CTRL_SENSOR, "http://tizen.org/sensor/general/reg_ctrl"},
+ {GPS_CTRL_SENSOR, "http://tizen.org/sensor/general/gps_ctrl"},
{WEAR_STATUS_SENSOR, "http://tizen.org/sensor/general/wear_status"},
{WEAR_ON_MONITOR_SENSOR, "http://tizen.org/sensor/general/wear_on_monitor"},
{PRESSURE_INDICATOR_SENSOR, "http://tizen.org/sensor/general/pressure_indicator"},
{PRESSURE_ALERT_SENSOR, "http://tizen.org/sensor/general/pressure_alert"},
{HR_CALORIE_SENSOR, "http://tizen.org/sensor/healthinfo/hr_calorie"},
+ {SWIMMING_TRACKER_SENSOR, "http://tizen.org/sensor/healthinfo/swimming_tracker"},
+ {SWIMMING_OUTDOOR_SENSOR, "http://tizen.org/sensor/healthinfo/swimming_outdoor"},
+ {AUTO_SWIMMING_SENSOR, "http://tizen.org/sensor/healthinfo/auto_swimming"},
+ {INACTIVITY_DETECTOR_SENSOR, "http://tizen.org/sensor/general/inactivity_detector"},
+ {STRESS_TRACKER_SENSOR, "http://tizen.org/sensor/healthinfo/stress_tracker"},
+ {FAKE_MOTION_SENSOR, "http://tizen.org/sensor/general/fake_motion"},
+ {GEOFENCE_SENSOR, "http://tizen.org/sensor/general/geofence"},
+ {INACTIVITY_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/inactivity_detector"},
+ {HRM_BP_SENSOR, "http://tizen.org/sensor/healthinfo/hrm_bp"},
+ {ECG_SENSOR, "http://tizen.org/sensor/healthinfo/ecg"},
+ {FALL_DETECTION_SENSOR, "http://tizen.org/sensor/general/fall_detection"},
{CONTEXT_SENSOR, "http://tizen.org/sensor/general/context"},
{MOTION_SENSOR, "http://tizen.org/sensor/general/motion"},
return PRIVILEGE_HEALTHINFO_URI;
else if (uri.substr(start + 1, size) == PRIVILEGE_LOCATION_STR)
return PRIVILEGE_LOCATION_URI;
+ else if (uri.substr(start + 1, size) == PRIVILEGE_PLATFORM_STR)
+ return PRIVILEGE_PLATFORM_URI;
return "";
}
#include "sensor_log.h"
-#define SOCK_TIMEOUT 3
+#define SOCK_TIMEOUT 10
using namespace ipc;
return false;
}
- _D("Connected[%d]", m_sock_fd);
-
return true;
}
return false;
}
- _D("Bound to path[%d, %s]", m_sock_fd, m_path.c_str());
-
return true;
}
client_sock.set_fd(fd);
/* TODO : socket type should be adjusted here */
- _D("Accepted[%d, %d]", m_sock_fd, fd);
-
return true;
}
bool socket::create_by_type(const std::string &path, int type)
{
m_sock_fd = ::create_systemd_socket(path, type);
- if (m_sock_fd < 0) {
- _D("Creating the UDS instead of systemd socket..");
+ if (m_sock_fd < 0)
m_sock_fd = create_unix_socket(type);
- } else {
+ else
m_listening.store(true);
- }
retvm_if((m_sock_fd < 0), false, "Failed to create socket");
/* TODO */
/*retvm_if(!set_reuse_addr(), false, "Failed to reuse address"); */
- _D("Created[%d]", m_sock_fd);
-
m_path = path;
return true;