* @retval 0 Successful
* @retval -EINVAL Invalid parameter
* @retval -EPERM Operation not permitted
+ * @retval -EIO Input/Output error
*/
int sensord_listener_get_attribute_str(int handle, int attribute, char **value, int *len);
/**
+ * @brief Set the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to change
+ * @param[in] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ * @retval -EIO Input/Output error
+ */
+int sensord_set_attribute_int(sensor_t sensor, int attribute, int value);
+
+/**
+ * @brief Get the attribute to a connected sensor
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] attribute an attribute to get value
+ * @param[out] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensord_get_attribute_int(sensor_t sensor, int attribute, int *value);
+
+/**
* @brief Send data to sensorhub
*
* @param[in] handle a handle represensting a connected context sensor.
return OP_SUCCESS;
}
+API int sensord_set_attribute_int(sensor_t sensor, int attribute, int value)
+{
+ if (!sensor) {
+ _E("Failed to validate the parameter");
+ return -EINVAL;
+ }
+
+ int ret = manager.set_attribute(sensor, attribute, value);
+ if (ret < 0) {
+ _E("Failed to set attribute[%d, %d]", attribute, value);
+ return ret;
+ }
+
+ _D("Set attribute[%s, %d, %d]",
+ ((sensor_info *)(sensor))->get_uri().c_str(), attribute, value);
+
+ return OP_SUCCESS;
+}
+
+API int sensord_get_attribute_int(sensor_t sensor, int attribute, int* value)
+{
+ if (!sensor || !value) {
+ _E("Failed to validate the parameter");
+ return -EINVAL;
+ }
+
+ int ret = manager.get_attribute(sensor, attribute, value);
+ if (ret < 0) {
+ _E("Failed to get attribute[%d]", attribute);
+ return ret;
+ }
+
+ _D("Get attribute[%s, %d, %d]",
+ ((sensor_info *)(sensor))->get_uri().c_str(), attribute, *value);
+
+ return OP_SUCCESS;
+}
+
API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
{
sensor::sensor_listener *listener;
return false;
}
+int sensor_manager::set_attribute(sensor_t sensor, int attribute, int value)
+{
+ if (!sensor) {
+ _E("Failed to validate the parameter");
+ return -EINVAL;
+ }
+
+ if (!m_cmd_channel) {
+ _E("Failed to connect to server");
+ return -EIO;
+ }
+
+ ipc::message msg;
+ ipc::message reply;
+ cmd_manager_attr_int_t buf = {0, };
+
+ buf.attribute = attribute;
+ buf.value = value;
+
+ sensor_info *info = (sensor_info*)sensor;
+ memcpy(buf.sensor, info->get_uri().c_str(), info->get_uri().size());
+
+ msg.set_type(CMD_MANAGER_SET_ATTR_INT);
+ msg.enclose((char*)&buf, sizeof(buf));
+
+ bool ret = m_cmd_channel->send_sync(msg);
+ if (!ret) {
+ _E("Failed to send command to set attribute");
+ return -EIO;
+ }
+
+ ret = m_cmd_channel->read_sync(reply);
+ if (!ret) {
+ _E("Failed to read reply to set attribute");
+ return -EIO;
+ }
+
+ if (reply.header()->err < 0) {
+ _E("Failed to set attribute");
+ return reply.header()->err;
+ }
+
+ return OP_SUCCESS;
+}
+
+int sensor_manager::get_attribute(sensor_t sensor, int attribute, int *value)
+{
+ if (!sensor || !value) {
+ _E("Failed to validate the parameters");
+ return -EINVAL;
+ }
+
+ if (!m_cmd_channel) {
+ _E("Failed to connect to server");
+ return -EIO;
+ }
+
+ ipc::message msg;
+ ipc::message reply;
+ cmd_manager_attr_int_t buf = {0, };
+
+ buf.attribute = attribute;
+
+ sensor_info *info = (sensor_info*)sensor;
+ memcpy(buf.sensor, info->get_uri().c_str(), info->get_uri().size());
+
+ msg.set_type(CMD_MANAGER_GET_ATTR_INT);
+ msg.enclose((char*)&buf, sizeof(buf));
+
+ bool ret = m_cmd_channel->send_sync(msg);
+ if (!ret) {
+ _E("Failed to send command to get attribute");
+ return -EIO;
+ }
+
+ ret = m_cmd_channel->read_sync(reply);
+ if (!ret) {
+ _E("Failed to read reply to get attribute");
+ return -EIO;
+ }
+
+ if (reply.header()->err < 0) {
+ _E("Failed to get attribute");
+ return reply.header()->err;
+ }
+
+ if (!reply.header()->length || !reply.body()) {
+ _E("Failed to get attribute");
+ return -EIO;
+ }
+
+ *value = ((cmd_manager_attr_int_t *)reply.body())->value;
+
+ return OP_SUCCESS;
+}
+
int sensor_manager::add_sensor(sensor_info &info)
{
retv_if(is_supported(info.get_uri().c_str()), OP_ERROR);
bool is_supported(sensor_t sensor);
bool is_supported(const char *uri);
+ int set_attribute(sensor_t sensor, int attribute, int value);
+ int get_attribute(sensor_t sensor, int attribute, int *value);
+
/* sensor provider */
int add_sensor(sensor_info &info);
int add_sensor(sensor_provider *provider);
#include "permission_checker.h"
#include "application_sensor_handler.h"
+#define CONVERT_ATTR_TYPE(attr) ((attr) >> 8)
+
using namespace sensor;
using namespace ipc;
err = manager_connect(ch, msg); break;
case CMD_MANAGER_SENSOR_LIST:
err = manager_get_sensor_list(ch, msg); break;
+ case CMD_MANAGER_SET_ATTR_INT:
+ err = manager_set_attr_int(ch, msg); break;
+ case CMD_MANAGER_GET_ATTR_INT:
+ err = manager_get_attr_int(ch, msg); break;
case CMD_LISTENER_CONNECT:
err = listener_connect(ch, msg); break;
case CMD_LISTENER_START:
return OP_SUCCESS;
}
+int server_channel_handler::manager_preprocess_attr(channel *ch, cmd_manager_attr_int_t &buf, sensor_handler **sensor)
+{
+ if (!ch || !sensor)
+ return -EINVAL;
+
+ sensor_handler *find_sensor = m_manager->get_sensor(buf.sensor);
+ if (!find_sensor) {
+ _E("Failed to find sensor");
+ return OP_ERROR;
+ }
+
+ sensor_info info = find_sensor->get_sensor_info();
+ sensor_type_t type = (sensor_type_t) CONVERT_ATTR_TYPE(buf.attribute);
+ if (type != info.get_type()) {
+ _E("Invalid attribute with sensor type");
+ return -EINVAL;
+ }
+
+ std::string privilege = info.get_privilege();
+ int ret = has_privileges(ch->get_fd(), privilege);
+ if (!ret) {
+ _E("Permission denied[%s]", privilege.c_str());
+ return -EPERM;
+ }
+ *sensor = find_sensor;
+
+ return OP_SUCCESS;
+}
+
+int server_channel_handler::manager_set_attr_int(channel *ch, message &msg)
+{
+ cmd_manager_attr_int_t buf;
+ msg.disclose((char *)&buf, sizeof(buf));
+
+ sensor_handler *sensor;
+ int ret = manager_preprocess_attr(ch, buf, &sensor);
+ if (ret < 0)
+ return ret;
+
+ ret = sensor->set_attribute(NULL, buf.attribute, buf.value);
+ if (ret < 0) {
+ _E("Failed to set attribute");
+ return ret;
+ }
+
+ return send_reply(ch, OP_SUCCESS);
+}
+
+int server_channel_handler::manager_get_attr_int(channel *ch, message &msg)
+{
+ cmd_manager_attr_int_t buf;
+ msg.disclose((char *)&buf, sizeof(buf));
+
+ sensor_handler *sensor;
+ int ret = manager_preprocess_attr(ch, buf, &sensor);
+ if (ret < 0)
+ return ret;
+
+ int value;
+ ret = sensor->get_attribute(buf.attribute, &value);
+ if (ret < 0) {
+ _E("Failed to get attribute");
+ return ret;
+ }
+
+ message reply;
+ cmd_manager_attr_int_t ret_buf;
+
+ ret_buf.attribute = buf.attribute;
+ ret_buf.value = value;
+
+ reply.enclose((char *)&ret_buf, sizeof(ret_buf));
+ reply.header()->err = OP_SUCCESS;
+ reply.set_type(CMD_MANAGER_GET_ATTR_INT);
+ ret = ch->send_sync(reply);
+ if (!ret)
+ return OP_ERROR;
+
+ return OP_SUCCESS;
+}
+
int server_channel_handler::listener_connect(channel *ch, message &msg)
{
static uint32_t listener_id = 1;
#include "sensor_manager.h"
#include "sensor_listener_proxy.h"
#include "application_sensor_handler.h"
+#include "command_types.h"
namespace sensor {
int manager_connect(ipc::channel *ch, ipc::message &msg);
int manager_disconnect(ipc::channel *ch, ipc::message &msg);
int manager_get_sensor_list(ipc::channel *ch, ipc::message &msg);
-
+ int manager_preprocess_attr(ipc::channel *ch, cmd_manager_attr_int_t &buf,
+ sensor_handler **sensor);
+ int manager_set_attr_int(ipc::channel *ch, ipc::message &msg);
+ int manager_get_attr_int(ipc::channel *ch, ipc::message &msg);
int listener_connect(ipc::channel *ch, ipc::message &msg);
int listener_disconnect(ipc::channel *ch, ipc::message &msg);
CMD_MANAGER_SENSOR_LIST,
CMD_MANAGER_SENSOR_ADDED,
CMD_MANAGER_SENSOR_REMOVED,
+ CMD_MANAGER_SET_ATTR_INT,
+ CMD_MANAGER_GET_ATTR_INT,
/* Listener */
CMD_LISTENER_EVENT = 0x200,
} cmd_manager_sensor_list_t;
typedef struct {
+ int attribute;
+ int value;
+ char sensor[NAME_MAX];
+} cmd_manager_attr_int_t;
+
+typedef struct {
int listener_id;
char sensor[NAME_MAX];
} cmd_listener_connect_t;