case CMD_LISTENER_EVENT:
if (m_listener->get_event_handler())
m_listener->get_event_handler()->read(ch, msg);
+ break;
case CMD_LISTENER_ACC_EVENT:
if (m_listener->get_accuracy_handler())
m_listener->get_accuracy_handler()->read(ch, msg);
+ break;
}
}
: m_id(0)
, m_sensor(reinterpret_cast<sensor_info *>(sensor))
, m_client(NULL)
-, m_channel(NULL)
+, m_cmd_channel(NULL)
+, m_evt_channel(NULL)
, m_handler(NULL)
, m_evt_handler(NULL)
, m_acc_handler(NULL)
bool sensor_listener::connect(void)
{
- m_channel = m_client->connect(m_handler, &m_loop);
- retvm_if(!m_channel, false, "Failed to connect to server");
+ 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);
+ retvm_if(!m_evt_channel, false, "Failed to connect to server");
ipc::message msg;
ipc::message reply;
memcpy(buf.sensor, m_sensor->get_uri().c_str(), m_sensor->get_uri().size());
msg.set_type(CMD_LISTENER_CONNECT);
msg.enclose((const char *)&buf, sizeof(buf));
- m_channel->send_sync(&msg);
+ m_evt_channel->send_sync(&msg);
- m_channel->read_sync(reply);
+ m_evt_channel->read_sync(reply);
reply.disclose((char *)&buf);
m_id = buf.listener_id;
m_connected.store(true);
+ m_evt_channel->bind();
+
_D("Listener ID[%d]", get_id());
return true;
ret_if(!is_connected());
m_connected.store(false);
- ipc::message msg;
- ipc::message reply;
-
- msg.set_type(CMD_LISTENER_DISCONNECT);
- m_channel->send_sync(&msg);
+ m_evt_channel->disconnect();
+ delete m_evt_channel;
+ m_evt_channel = NULL;
- m_channel->read_sync(reply);
- m_channel->disconnect();
-
- delete m_channel;
- m_channel = NULL;
+ m_cmd_channel->disconnect();
+ delete m_cmd_channel;
+ m_cmd_channel = NULL;
_I("Disconnected[%d]", get_id());
}
ipc::message reply;
cmd_listener_start_t buf;
- retvm_if(!m_channel, -EINVAL, "Failed to connect to server");
+ retvm_if(!m_cmd_channel, -EINVAL, "Failed to connect to server");
buf.listener_id = m_id;
msg.set_type(CMD_LISTENER_START);
msg.enclose((char *)&buf, sizeof(buf));
- m_channel->send_sync(&msg);
- m_channel->read_sync(reply);
+ m_cmd_channel->send_sync(&msg);
+ m_cmd_channel->read_sync(reply);
if (reply.header()->err < 0)
return reply.header()->err;
ipc::message reply;
cmd_listener_stop_t buf;
- retvm_if(!m_channel, -EINVAL, "Failed to connect to server");
+ retvm_if(!m_cmd_channel, -EINVAL, "Failed to connect to server");
retvm_if(!m_started.load(), -EAGAIN, "Already stopped");
buf.listener_id = m_id;
msg.set_type(CMD_LISTENER_STOP);
msg.enclose((char *)&buf, sizeof(buf));
- m_channel->send_sync(&msg);
- m_channel->read_sync(reply);
+ m_cmd_channel->send_sync(&msg);
+ m_cmd_channel->read_sync(reply);
if (reply.header()->err < 0)
return reply.header()->err;
ipc::message reply;
cmd_listener_attr_int_t buf;
- retvm_if(!m_channel, false, "Failed to connect to server");
+ retvm_if(!m_cmd_channel, false, "Failed to connect to server");
buf.listener_id = m_id;
buf.attribute = attribute;
msg.set_type(CMD_LISTENER_ATTR_INT);
msg.enclose((char *)&buf, sizeof(buf));
- m_channel->send_sync(&msg);
- m_channel->read_sync(reply);
+ m_cmd_channel->send_sync(&msg);
+ m_cmd_channel->read_sync(reply);
if (reply.header()->err < 0)
return reply.header()->err;
ipc::message reply;
cmd_listener_attr_str_t buf;
- retvm_if(!m_channel, false, "Failed to connect to server");
+ retvm_if(!m_cmd_channel, false, "Failed to connect to server");
msg.set_type(CMD_LISTENER_ATTR_STR);
buf.listener_id = m_id;
msg.enclose((char *)&buf, sizeof(buf) + len);
- m_channel->send_sync(&msg);
- m_channel->read_sync(reply);
+ m_cmd_channel->send_sync(&msg);
+ m_cmd_channel->read_sync(reply);
return reply.header()->err;
}
ipc::message reply;
cmd_listener_get_data_t buf;
- retvm_if(!m_channel, false, "Failed to connect to server");
+ retvm_if(!m_cmd_channel, false, "Failed to connect to server");
buf.listener_id = m_id;
msg.set_type(CMD_LISTENER_GET_DATA);
msg.enclose((char *)&buf, sizeof(buf));
- m_channel->send_sync(&msg);
- m_channel->read_sync(reply);
- /* TODO */
- /*
+ m_cmd_channel->send_sync(&msg);
+ m_cmd_channel->read_sync(reply);
+
reply.disclose((char *)&buf);
- memcpy(data, buf.data, sizeof(buf.len));
- */
+ int size = sizeof(sensor_data_t);
+
+ if (buf.len > size || buf.len < 0) {
+ data->accuracy = -1;
+ data->value_count = 0;
+ /* TODO: it should return OP_ERROR */
+ return OP_SUCCESS;
+ }
+
+ memcpy(data, &buf.data, buf.len);
return OP_SUCCESS;
}