Exemple #1
0
void SimpleE133Device::OnTCPConnect(TCPSocket *socket) {
  OLA_INFO << "Opened new TCP connection: " << socket;

  m_socket.reset(socket);
  m_in_transport.reset(new IncomingTCPTransport(&m_root_inflator, socket));

  m_message_queue.reset(
      new MessageQueue(m_socket.get(), &m_ss, m_message_builder.pool()));

  m_health_checked_connection.reset(new E133HealthCheckedConnection(
      &m_message_builder,
      m_message_queue.get(),
      NewSingleCallback(this, &SimpleE133Device::SocketClosed),
      &m_ss));

  socket->SetOnData(NewCallback(this, &SimpleE133Device::ReceiveTCPData));
  socket->SetOnClose(NewSingleCallback(this, &SimpleE133Device::SocketClosed));
  m_ss.AddReadDescriptor(socket);


  if (!m_health_checked_connection->Setup()) {
    OLA_WARN << "Failed to setup heartbeat controller for " << m_controller;
    SocketClosed();
    return;
  }
}
/**
 * Send an RDM Request.
 * This packs the data into a ACN structure and sends it.
 */
bool SimpleE133Controller::SendRequest(const UID &uid,
                                       uint16_t endpoint,
                                       RDMRequest *raw_request) {
  auto_ptr<RDMRequest> request(raw_request);

  IPV4Address *target_address = ola::STLFind(&m_uid_to_ip, uid);
  if (!target_address) {
    OLA_WARN << "UID " << uid << " not found";
    return false;
  }

  IPV4SocketAddress target(*target_address, E133_PORT);
  OLA_INFO << "Sending to " << target << "/" << uid << "/" << endpoint;

  // Build the E1.33 packet.
  IOStack packet(m_message_builder.pool());
  RDMCommandSerializer::Write(*request, &packet);
  RDMPDU::PrependPDU(&packet);
  m_message_builder.BuildUDPRootE133(
      &packet, ola::acn::VECTOR_FRAMING_RDMNET, 0, endpoint);

  // Send the packet
  m_udp_socket.SendTo(&packet, target);
  if (!packet.Empty()) {
    return false;
  }

  return true;
}