当前位置: 首页>>代码示例>>C++>>正文


C++ ola::NewCallback方法代码示例

本文整理汇总了C++中ola::NewCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ ola::NewCallback方法的具体用法?C++ ola::NewCallback怎么用?C++ ola::NewCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ola的用法示例。


在下文中一共展示了ola::NewCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NewCallback

/**
 * Create a new DesignatedControllerConnection.
 * This listens for connections from the controllers, and will ensure that if
 * any controllers try to connect, at least one will be picked as the
 * designated controller.
 */
DesignatedControllerConnection::DesignatedControllerConnection(
    ola::io::SelectServerInterface *ss,
    const IPV4Address &ip_address,
    ola::e133::MessageBuilder *message_builder,
    TCPConnectionStats *tcp_stats,
    unsigned int max_queue_size)
    : m_ip_address(ip_address),
      m_max_queue_size(max_queue_size),
      m_ss(ss),
      m_message_builder(message_builder),
      m_tcp_stats(tcp_stats),
      m_tcp_socket(NULL),
      m_health_checked_connection(NULL),
      m_message_queue(NULL),
      m_incoming_tcp_transport(NULL),
      m_tcp_socket_factory(
          NewCallback(this, &DesignatedControllerConnection::NewTCPConnection)),
      m_listening_tcp_socket(&m_tcp_socket_factory),
      m_root_inflator(
          NewCallback(this, &DesignatedControllerConnection::RLPDataReceived)),
      m_unsent_messages(false) {
  m_root_inflator.AddInflator(&m_e133_inflator);
  m_e133_inflator.AddInflator(&m_e133_status_inflator);

  m_e133_status_inflator.SetStatusHandler(
      NewCallback(this, &DesignatedControllerConnection::HandleStatusMessage));
}
开发者ID:Jazeido,项目名称:ola,代码行数:33,代码来源:DesignatedControllerConnection.cpp

示例2: testRemoveWriteWhenReadable

/*
 * Check that RemoveWriteDescriptor is reentrant.
 * Similar to the case above, but this removes & deletes the descriptor from
 * within the OnRead callback of the same descriptor.
 */
void SelectServerTest::testRemoveWriteWhenReadable() {
  // Ownership is transferred to the SelectServer.
  LoopbackDescriptor *loopback = new LoopbackDescriptor();
  loopback->Init();

  loopback->SetOnData(NewCallback(
      this, &SelectServerTest::ReadDataAndRemove,
      static_cast<ConnectedDescriptor*>(loopback)));
  loopback->SetOnWritable(NewCallback(this, &SelectServerTest::NullHandler));

  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(loopback));
  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(loopback));
  OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(1, write_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());

  // Send some data to make this descriptor readable.
  uint8_t data[] = {'a'};
  loopback->Send(data, arraysize(data));

  m_ss->Run();
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
}
开发者ID:Jurrie,项目名称:ola,代码行数:30,代码来源:SelectServerTest.cpp

示例3: testRemoveOthersWhenWriteable

/*
 * Check that we don't invalid iterators by removing descriptors during an
 * on_Write callback.
 */
void SelectServerTest::testRemoveOthersWhenWriteable() {
  Descriptors read_set, write_set, delete_set;
  LoopbackDescriptor loopback1, loopback2, loopback3;
  loopback1.Init();
  loopback2.Init();
  loopback3.Init();

  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback1));
  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback2));
  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback3));

  write_set.insert(&loopback1);
  write_set.insert(&loopback2);
  write_set.insert(&loopback3);

  loopback1.SetOnWritable(NewCallback(
      this, &SelectServerTest::NullHandler));
  loopback2.SetOnWritable(NewCallback(
      this,
      &SelectServerTest::RemoveAndDeleteDescriptors,
      read_set, write_set, delete_set));

  loopback3.SetOnWritable(NewCallback(
      this, &SelectServerTest::NullHandler));

  OLA_ASSERT_EQ(3, write_descriptor_count->Get());
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());

  m_ss->Run();

  OLA_ASSERT_EQ(0, write_descriptor_count->Get());
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
}
开发者ID:Jurrie,项目名称:ola,代码行数:38,代码来源:SelectServerTest.cpp

示例4: NewSingleCallback

/*
 * Test the single argument function closures
 */
void CallbackTest::testFunctionCallbacks1() {
  // single arg, void return closures
  BaseCallback1<void, unsigned int> *c1 = NewSingleCallback(&Function1);
  c1->Run(TEST_INT_VALUE);
  BaseCallback1<void, unsigned int> *c2 = NewCallback(&Function1);
  c2->Run(TEST_INT_VALUE);
  c2->Run(TEST_INT_VALUE);
  delete c2;

  // test a function that returns bool
  BaseCallback1<bool, unsigned int> *c3 = NewSingleCallback(&BoolFunction1);
  OLA_ASSERT_TRUE(c3->Run(TEST_INT_VALUE));
  BaseCallback1<bool, unsigned int> *c4 = NewCallback(&BoolFunction1);
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE));
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE));
  delete c4;

  // single arg, void return closures
  BaseCallback1<void, int> *c6 = NewSingleCallback(
      &Function2,
      TEST_INT_VALUE);
  c6->Run(TEST_INT_VALUE2);
  BaseCallback1<void, int> *c7 = NewCallback(
    &Function2,
    TEST_INT_VALUE);
  c7->Run(TEST_INT_VALUE2);
  c7->Run(TEST_INT_VALUE2);
  delete c7;
}
开发者ID:inggiinggita,项目名称:ola,代码行数:32,代码来源:CallbackTest.cpp

示例5: NewCallback

/**
 * Create a new E133Receiver.
 * @param socket the UDP socket to read from
 * @param status_callback the callback to run when status messages are
 * received.
 * @param rdm_callback the callback to run when RDM messages are received.
 */
E133Receiver::E133Receiver(ola::network::UDPSocket *socket,
                           StatusCallback *status_callback,
                           RDMCallback *rdm_callback)
    : m_udp_socket(socket),
      m_status_callback(status_callback),
      m_rdm_callback(rdm_callback),
      m_root_inflator(new plugin::e131::RootInflator()),
      m_e133_inflator(new plugin::e131::E133Inflator()),
      m_rdm_inflator(new plugin::e131::RDMInflator()),
      m_e133_status_inflator(new plugin::e131::E133StatusInflator()),
      m_incoming_udp_transport(
          new plugin::e131::IncomingUDPTransport(
            m_udp_socket,
            m_root_inflator.get())) {
  m_root_inflator->AddInflator(m_e133_inflator.get());
  m_e133_inflator->AddInflator(m_rdm_inflator.get());
  m_e133_inflator->AddInflator(m_e133_status_inflator.get());

  m_rdm_inflator->SetRDMHandler(
      NewCallback(this, &E133Receiver::HandlePacket));
  m_e133_status_inflator->SetStatusHandler(
      NewCallback(this, &E133Receiver::HandleStatusMessage));

  m_udp_socket->SetOnData(
        NewCallback(m_incoming_udp_transport.get(),
                    &ola::plugin::e131::IncomingUDPTransport::Receive));
}
开发者ID:Jazeido,项目名称:ola,代码行数:34,代码来源:E133Receiver.cpp

示例6: PortId

void ArtNetInputPort::PostSetUniverse(Universe *old_universe,
                                      Universe *new_universe) {
  if (new_universe)
    m_node->SetOutputPortUniverse(PortId(), new_universe->UniverseId() % 0xf);
  else
    m_node->DisableOutputPort(PortId());

  if (new_universe && !old_universe) {
    m_node->SetDMXHandler(
        PortId(),
        &m_buffer,
        NewCallback(static_cast<ola::BasicInputPort*>(this),
                    &ArtNetInputPort::DmxChanged));
    m_node->SetOutputPortRDMHandlers(
        PortId(),
        NewCallback(
            this,
            &ArtNetInputPort::RespondWithTod),
        NewCallback(
            this,
            &ArtNetInputPort::TriggerDiscovery),
        ola::NewCallback(
            static_cast<ola::BasicInputPort*>(this),
            &ArtNetInputPort::HandleRDMRequest));

  } else if (!new_universe) {
    m_node->SetDMXHandler(PortId(), NULL, NULL);
    m_node->SetOutputPortRDMHandlers(PortId(), NULL, NULL, NULL);
  }

  if (new_universe)
    TriggerRDMDiscovery(
        NewSingleCallback(this, &ArtNetInputPort::SendTODWithUIDs));
}
开发者ID:NextGenIntelligence,项目名称:ola,代码行数:34,代码来源:ArtNetPort.cpp

示例7: TimeInterval

SimpleE133Device::SimpleE133Device(const Options &options)
    : m_controller(options.controller),
      m_message_builder(ola::acn::CID::Generate(), "E1.33 Device"),
      m_tcp_socket_factory(NewCallback(this, &SimpleE133Device::OnTCPConnect)),
      m_connector(&m_ss, &m_tcp_socket_factory,
                  TimeInterval(FLAGS_tcp_connect_timeout_ms / 1000,
                               (FLAGS_tcp_connect_timeout_ms % 1000) * 1000)),
      m_backoff_policy(TimeInterval(
            FLAGS_tcp_retry_interval_ms / 1000,
            (FLAGS_tcp_retry_interval_ms % 1000) * 1000)),
      m_root_inflator(NewCallback(this, &SimpleE133Device::RLPDataReceived)) {
  m_connector.AddEndpoint(options.controller, &m_backoff_policy);
}
开发者ID:Tuckie,项目名称:ola,代码行数:13,代码来源:basic-device.cpp

示例8: testSendBlob

/**
 * Check that we send OSC messages correctly.
 */
void OSCNodeTest::testSendBlob() {
  // First up create a UDP socket to receive the messages on.
  // Port 0 means 'ANY'
  IPV4SocketAddress socket_address(IPV4Address::Loopback(), 0);
  // Bind the socket, set the callback, and register with the select server.
  OLA_ASSERT_TRUE(m_udp_socket.Bind(socket_address));
  m_udp_socket.SetOnData(NewCallback(this, &OSCNodeTest::UDPSocketReady));
  OLA_ASSERT_TRUE(m_ss.AddReadDescriptor(&m_udp_socket));
  // Store the local address of the UDP socket so we know where to tell the
  // OSCNode to send to.
  OLA_ASSERT_TRUE(m_udp_socket.GetSocketAddress(&socket_address));

  // Setup the OSCTarget pointing to the local socket address
  OSCTarget target(socket_address, TEST_OSC_ADDRESS);
  // Add the target to the node.
  m_osc_node->AddTarget(TEST_GROUP, target);
  // Send the data
  OLA_ASSERT_TRUE(m_osc_node->SendData(TEST_GROUP, OSCNode::FORMAT_BLOB,
                  m_dmx_data));

  // Run the SelectServer this will return either when UDPSocketReady
  // completes, or the abort timeout triggers.
  m_ss.Run();

  // Remove target
  OLA_ASSERT_TRUE(m_osc_node->RemoveTarget(TEST_GROUP, target));
  // Try to remove it a second time
  OLA_ASSERT_FALSE(m_osc_node->RemoveTarget(TEST_GROUP, target));

  // Try to remove the target from a group that doesn't exist
  OLA_ASSERT_FALSE(m_osc_node->RemoveTarget(TEST_GROUP + 1, target));
}
开发者ID:Jazeido,项目名称:ola,代码行数:35,代码来源:OSCNodeTest.cpp

示例9: main

/*
 * Main.
 */
int main(int argc, char **argv) {
  ola::AppInit(&argc, argv, "[ options ]", "Ja Rule Admin Tool");

  auto_ptr<UID> controller_uid(UID::FromString(FLAGS_controller_uid));
  if (!controller_uid.get()) {
    OLA_WARN << "Invalid Controller UID: '" << FLAGS_controller_uid << "'";
    exit(ola::EXIT_USAGE);
  }

  if (controller_uid->IsBroadcast()) {
    OLA_WARN << "The controller UID should not be a broadcast UID";
    exit(ola::EXIT_USAGE);
  }

  SelectServer ss;
  WidgetManager widget_manager(*controller_uid);
  InputHandler input_handler(&ss, *controller_uid, &widget_manager);

  USBDeviceManager manager(
    &ss, NewCallback(&widget_manager, &WidgetManager::WidgetEvent));
  if (!manager.Start()) {
    exit(ola::EXIT_UNAVAILABLE);
  }
  ss.Run();
  return ola::EXIT_OK;
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:29,代码来源:ja-rule-controller.cpp

示例10: testAbortedRepeatingTimeouts

/*
 * Check returning false from a repeating timeout cancels the timeout.
 */
void TimeoutManagerTest::testAbortedRepeatingTimeouts() {
  MockClock clock;
  TimeoutManager timeout_manager(&m_map, &clock);

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  TimeInterval timeout_interval(1, 0);
  timeout_id id1 = timeout_manager.RegisterRepeatingTimeout(
      timeout_interval,
      NewCallback(this, &TimeoutManagerTest::HandleAbortedEvent, 1u));
  OLA_ASSERT_NE(id1, ola::thread::INVALID_TIMEOUT);

  TimeStamp last_checked_time;

  clock.AdvanceTime(0, 1);  // Small offset to work around timer precision
  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(1u, GetEventCounter(1));

  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(2u, GetEventCounter(1));

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:30,代码来源:TimeoutManagerTest.cpp

示例11: testPauseAndResume

/**
 * Check pausing doesn't mark the channel as bad.
 */
void HealthCheckedConnectionTest::testPauseAndResume() {
  MockHealthCheckedConnection connection(&socket,
                                         &m_ss,
                                         heartbeat_interval,
                                         options,
                                         &m_clock);
  socket.SetOnData(
      NewCallback(&connection, &MockHealthCheckedConnection::ReadData));
  connection.Setup();
  m_ss.AddReadDescriptor(&socket);
  connection.Setup();

  m_ss.RegisterSingleTimeout(
      TimeInterval(1, 0),
      NewSingleCallback(this,
                        &HealthCheckedConnectionTest::PauseReading,
                        &connection));
  m_ss.RegisterSingleTimeout(
      TimeInterval(3, 0),
      NewSingleCallback(this,
                        &HealthCheckedConnectionTest::ResumeReading,
                        &connection));

  m_ss.Run();
  OLA_ASSERT_TRUE(connection.ChannelOk());
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:29,代码来源:HealthCheckedConnectionTest.cpp

示例12: AddMaster

void AvahiDiscoveryAgent::AddMaster(AvahiIfIndex interface,
                                    AvahiProtocol protocol,
                                    const std::string &name,
                                    const std::string &type,
                                    const std::string &domain) {
  OLA_INFO << "(Browser) NEW: service " << name << " of type " << type
           << " in domain " << domain << ", iface" << interface
           << ", proto " << protocol;

  MutexLocker lock(&m_masters_mu);

  auto_ptr<MasterResolver> master(new MasterResolver(
      NewCallback(this, &AvahiDiscoveryAgent::MasterChanged),
      m_client.get(), interface, protocol, name, type, domain));

  // We get the callback multiple times for the same instance
  MasterResolverList::iterator iter = m_masters.begin();
  for (; iter != m_masters.end(); ++iter) {
    if ((**iter) == *master) {
      return;
    }
  }
  if (master->StartResolution()) {
    MasterEntry entry;
    master->GetMasterEntry(&entry);
    m_masters.push_back(master.release());
    m_master_callback->Run(MASTER_ADDED, entry);
  }
}
开发者ID:nomis52,项目名称:glowing-wookie,代码行数:29,代码来源:AvahiDiscoveryAgent.cpp

示例13: main

/*
 * Startup the server.
 */
int main(int argc, char *argv[]) {
  std::ostringstream help_msg;
  help_msg <<
      "The OLA SLP client.\n"
      "\n"
      "Examples:\n"
      "   " << argv[0] << " register service:myserv.x://myhost.com\n"
      "   " << argv[0] << " findsrvs service:myserv.x\n"
      "   " << argv[0] << " findsrvs service:myserv.x";

  ola::AppInit(&argc, argv, "[options] command-and-arguments", help_msg.str());

  vector<string> args;
  for (int i = 1; i < argc; i++) {
    args.push_back(argv[i]);
  }

  auto_ptr<Command> command(CreateCommand(args));
  if (!command.get()) {
    ola::DisplayUsage();
    exit(ola::EXIT_OK);
  }

  ola::slp::SLPClientWrapper client_wrapper;
  if (!client_wrapper.Setup())
    exit(1);

  SelectServer *ss = client_wrapper.GetSelectServer();
  command->SetTermination(NewCallback(ss, &SelectServer::Terminate));

  if (!command->Execute(client_wrapper.GetClient()))
    exit(1);
  ss->Run();
}
开发者ID:Tuckie,项目名称:ola,代码行数:37,代码来源:slp-client.cpp

示例14: NewCallback

/**
 * Init the device.
 */
bool E133Device::Init() {
  OLA_INFO << "Attempting to start E1.33 device at " << m_ip_address;

  // setup the TCP socket
  bool listen_ok = m_tcp_socket.Listen(m_ip_address,
                                       ola::plugin::e131::E133_PORT);
  if (!listen_ok) {
    m_tcp_socket.Close();
    return false;
  }

  // setup the UDP socket
  if (!m_udp_socket.Init()) {
    m_tcp_socket.Close();
    return false;
  }

  if (!m_udp_socket.Bind(ola::plugin::e131::E133_PORT)) {
    m_tcp_socket.Close();
    return false;
  }

  m_udp_socket.SetOnData(
        NewCallback(&m_incoming_udp_transport,
                    &ola::plugin::e131::IncomingUDPTransport::Receive));

  // add both to the Select Server
  m_ss->AddReadDescriptor(&m_udp_socket);
  m_ss->AddReadDescriptor(&m_tcp_socket);
  return true;
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:34,代码来源:E133Device.cpp

示例15: DesignatedControllerConnection

/**
 * Init the device.
 */
bool E133Device::Init() {
  if (m_controller_connection.get()) {
    OLA_WARN << "Init already performed";
    return false;
  }

  OLA_INFO << "Attempting to start E1.33 device at " << m_ip_address;

  m_controller_connection.reset(new DesignatedControllerConnection(
        m_ss, m_ip_address, &m_message_builder, &m_tcp_stats));

  if (!m_controller_connection->Init()) {
    m_controller_connection.reset();
    return false;
  }

  // setup the UDP socket
  if (!m_udp_socket.Init()) {
    m_controller_connection.reset();
    return false;
  }

  if (!m_udp_socket.Bind(IPV4SocketAddress(IPV4Address::WildCard(),
                                           ola::acn::E133_PORT))) {
    m_controller_connection.reset();
    return false;
  }

  m_udp_socket.SetOnData(
        NewCallback(&m_incoming_udp_transport,
                    &ola::plugin::e131::IncomingUDPTransport::Receive));

  m_ss->AddReadDescriptor(&m_udp_socket);
  return true;
}
开发者ID:Jazeido,项目名称:ola,代码行数:38,代码来源:E133Device.cpp


注:本文中的ola::NewCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。