Example #1
0
/*
 * Test the Method Callbacks
 */
void CallbackTest::testMethodCallbacks4() {
  // test 2 arg callbacks that return unsigned ints
  BaseCallback4<void, unsigned int, int, char, const string&> *c1 =
    NewSingleCallback(
      this,
      &CallbackTest::Method4);
  c1->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE, TEST_STRING_VALUE);
  BaseCallback4<void, unsigned int, int, char, const string&> *c2 = NewCallback(
      this,
      &CallbackTest::Method4);
  c2->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE, TEST_STRING_VALUE);
  c2->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE, TEST_STRING_VALUE);
  delete c2;

  // test 2 arg callbacks that return bools
  BaseCallback4<bool, unsigned int, int, char, const string&> *c3 =
    NewSingleCallback(
      this,
      &CallbackTest::BoolMethod4);
  OLA_ASSERT_TRUE(c3->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE,
                         TEST_STRING_VALUE));
  BaseCallback4<bool, unsigned int, int, char, const string&> *c4 =
    NewCallback(
      this,
      &CallbackTest::BoolMethod4);
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE,
                         TEST_STRING_VALUE));
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE, TEST_INT_VALUE2, TEST_CHAR_VALUE,
                         TEST_STRING_VALUE));
  delete c4;
}
Example #2
0
/*
 * Check that queued messages work.
 */
void DmxTriWidgetTest::testQueuedMessages() {
  UID source(1, 2);
  UID destination(0x707a, 0xffffff00);
  vector<string> packets;
  PopulateTod();

  // first try a response which is too short
  const RDMRequest *request = NewQueuedMessageRequest(source, destination, 1);
  uint8_t expected_rdm_command[] = {0x3a, 0x02, 0x01};
  uint8_t small_response[] = {0x3a, 0x04};
  m_endpoint->AddExpectedUsbProDataAndReturn(
      EXTENDED_LABEL,
      expected_rdm_command,
      sizeof(expected_rdm_command),
      EXTENDED_LABEL,
      small_response,
      sizeof(small_response));

  m_widget->SendRDMRequest(
      request,
      NewSingleCallback(this,
                        &DmxTriWidgetTest::ValidateStatus,
                        ola::rdm::RDM_INVALID_RESPONSE,
                        packets));
  m_ss.Run();
  m_endpoint->Verify();

  // now try a proper response
  request = NewQueuedMessageRequest(source, destination, 1);
  uint8_t queued_response[] = {0x3a, 0x00, 0x00, 0x60, 0x52};
  m_endpoint->AddExpectedUsbProDataAndReturn(
      EXTENDED_LABEL,
      expected_rdm_command,
      sizeof(expected_rdm_command),
      EXTENDED_LABEL,
      queued_response,
      sizeof(queued_response));

  uint8_t return_data = 0x52;
  ola::rdm::RDMGetResponse response(
      destination,
      source,
      0,  // transaction #
      ola::rdm::RDM_ACK,
      0,  // message count
      10,  // sub device
      0x0060,  // param id
      &return_data,
      sizeof(return_data));  // data length

  m_widget->SendRDMRequest(
      request,
      NewSingleCallback(this,
                        &DmxTriWidgetTest::ValidateResponse,
                        ola::rdm::RDM_COMPLETED_OK,
                        static_cast<const RDMResponse*>(&response),
                        packets));
  m_ss.Run();
  m_endpoint->Verify();
}
/**
 * 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());
}
Example #4
0
/*
 * 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;
}
Example #5
0
/*
 * Fetch the state of a plugin.
 */
int FetchPluginState(OlaClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaClient *client = wrapper->GetClient();
  if (opts.plugin_id == 0) {
    DisplayPluginStateHelp(opts);
    exit(1);
  }
  if (!opts.state.empty()) {
    bool state;
    if (ola::StringToBoolTolerant(opts.state, &state)) {
      cout << "Setting state to " << (state ? "enabled" : "disabled") << endl;
      client->SetPluginState(
          (ola::ola_plugin_id) opts.plugin_id,
          state,
          NewSingleCallback(&HandleAck, ss));
    } else {
      cerr << "Invalid state: " << opts.state << endl;
      DisplayPluginStateHelp(opts);
      exit(1);
    }
  } else {
    client->FetchPluginState((ola::ola_plugin_id) opts.plugin_id,
                             NewSingleCallback(&DisplayPluginState, ss));
  }
  return 0;
}
Example #6
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;
  }
}
/*
 * Check that nacks work as expected.
 */
void DmxTriWidgetTest::testNack() {
  UID source(1, 2);
  UID destination(0x707a, 0xffffff00);

  PopulateTod();

  RDMRequest *request = NewRequest(source, destination, NULL, 0);

  uint8_t expected_rdm_command[] = {0x38, 0x02, 0x00, 0x0a, 0x01, 0x28};
  uint8_t nack_pid_response[] = {0x38, 0x20};  // unknown pid
  m_endpoint->AddExpectedUsbProDataAndReturn(
      EXTENDED_LABEL,
      expected_rdm_command,
      sizeof(expected_rdm_command),
      EXTENDED_LABEL,
      nack_pid_response,
      sizeof(nack_pid_response));

  RDMResponse *response = ola::rdm::NackWithReason(
      request,
      ola::rdm::NR_UNKNOWN_PID);

  m_widget->SendRDMRequest(
      request,
      NewSingleCallback(this,
                        &DmxTriWidgetTest::ValidateResponse,
                        ola::rdm::RDM_COMPLETED_OK,
                        static_cast<const RDMResponse*>(response)));
  m_ss.Run();
  m_endpoint->Verify();
  delete response;

  // try a proxy buffer full
  request = NewRequest(source, destination, NULL, 0);

  uint8_t nack_proxy_response[] = {0x38, 0x2a};  // bad proxy
  m_endpoint->AddExpectedUsbProDataAndReturn(
      EXTENDED_LABEL,
      expected_rdm_command,
      sizeof(expected_rdm_command),
      EXTENDED_LABEL,
      nack_proxy_response,
      sizeof(nack_proxy_response));

  response = ola::rdm::NackWithReason(
      request,
      ola::rdm::NR_PROXY_BUFFER_FULL);

  m_widget->SendRDMRequest(
      request,
      NewSingleCallback(this,
                        &DmxTriWidgetTest::ValidateResponse,
                        ola::rdm::RDM_COMPLETED_OK,
                        static_cast<const RDMResponse*>(response)));
  m_ss.Run();
  m_endpoint->Verify();
  delete response;
}
/*
 * Check that attempting a discovery while another is running fails.
 */
void QueueingRDMControllerTest::testMultipleDiscovery() {
  MockRDMController mock_controller;
  auto_ptr<ola::rdm::DiscoverableQueueingRDMController> controller(
      new ola::rdm::DiscoverableQueueingRDMController(&mock_controller, 1));

  UIDSet uids, uids2;
  UID uid1(2, 3);
  UID uid2(10, 11);
  UID uid3(20, 22);
  UID uid4(65, 45);
  uids.AddUID(uid1);
  uids.AddUID(uid2);
  uids2.AddUID(uid3);
  uids2.AddUID(uid4);

  // trigger discovery, this doesn't run the callback immediately
  mock_controller.AddExpectedDiscoveryCall(true, NULL);
  controller->RunFullDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyDiscoveryComplete,
          &uids));
  mock_controller.Verify();
  OLA_ASSERT_FALSE(m_discovery_complete_count);

  // trigger discovery again, this should queue the discovery request
  controller->RunIncrementalDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyDiscoveryComplete,
          &uids2));
  mock_controller.Verify();

  // and again
  controller->RunIncrementalDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyDiscoveryComplete,
          &uids2));
  mock_controller.Verify();

  // return from the first one, this will trigger the second discovery call
  mock_controller.AddExpectedDiscoveryCall(false, NULL);
  mock_controller.RunDiscoveryCallback(uids);
  OLA_ASSERT_TRUE(m_discovery_complete_count);
  m_discovery_complete_count = 0;
  mock_controller.Verify();

  // now return from the second one, which should complete the 2nd and 3rd
  // requests
  mock_controller.RunDiscoveryCallback(uids2);
  OLA_ASSERT_EQ(2, m_discovery_complete_count);
  m_discovery_complete_count = 0;
  mock_controller.Verify();
}
Example #9
0
/*
 * Test the Method Callbacks
 */
void CallbackTest::testMethodCallbacks2() {
  // test 2 arg callbacks that return void
  BaseCallback2<void, unsigned int, int> *c1 = NewSingleCallback(
      this,
      &CallbackTest::Method2);
  c1->Run(TEST_INT_VALUE, TEST_INT_VALUE2);
  BaseCallback2<void, unsigned int, int> *c2 = NewCallback(
      this,
      &CallbackTest::Method2);
  c2->Run(TEST_INT_VALUE, TEST_INT_VALUE2);
  c2->Run(TEST_INT_VALUE, TEST_INT_VALUE2);
  delete c2;

  // test 2 arg callbacks that return bools
  BaseCallback2<bool, unsigned int, int> *c3 = NewSingleCallback(
      this,
      &CallbackTest::BoolMethod2);
  OLA_ASSERT_TRUE(c3->Run(TEST_INT_VALUE, TEST_INT_VALUE2));
  BaseCallback2<bool, unsigned int, int> *c4 = NewCallback(
      this,
      &CallbackTest::BoolMethod2);
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE, TEST_INT_VALUE2));
  OLA_ASSERT_TRUE(c4->Run(TEST_INT_VALUE, TEST_INT_VALUE2));
  delete c4;

  // test 1 create time, 2 run time arg callbacks that return void
  BaseCallback2<void, int, char> *c5 = NewSingleCallback(
      this,
      &CallbackTest::Method3,
      TEST_INT_VALUE);
  c5->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE);
  BaseCallback2<void, int, char> *c6 = NewCallback(
      this,
      &CallbackTest::Method3,
      TEST_INT_VALUE);
  c6->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE);
  c6->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE);
  delete c6;

  // test 1 create time, 2 run time arg callbacks that return bools
  BaseCallback2<bool, int, char> *c7 = NewSingleCallback(
      this,
      &CallbackTest::BoolMethod3,
      TEST_INT_VALUE);
  OLA_ASSERT_TRUE(c7->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE));
  BaseCallback2<bool, int, char> *c8 = NewCallback(
      this,
      &CallbackTest::BoolMethod3,
      TEST_INT_VALUE);
  OLA_ASSERT_TRUE(c8->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE));
  OLA_ASSERT_TRUE(c8->Run(TEST_INT_VALUE2, TEST_CHAR_VALUE));
  delete c8;
}
 void RunDiscovery(bool incremental) {
   JaRuleWidget *widget = m_widget_manager->GetWidget();
   if (!widget) {
     return;
   }
   if (incremental) {
     widget->RunIncrementalDiscovery(
         NewSingleCallback(this, &InputHandler::DiscoveryComplete));
   } else {
     widget->RunFullDiscovery(
         NewSingleCallback(this, &InputHandler::DiscoveryComplete));
   }
 }
Example #11
0
/*
 * Fetch information on plugins.
 */
int FetchPluginInfo(OlaCallbackClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaCallbackClient *client = wrapper->GetClient();
  if (opts.plugin_id > 0) {
    client->FetchPluginDescription(
        (ola::ola_plugin_id) opts.plugin_id,
        NewSingleCallback(&DisplayPluginDescription, ss));
  } else {
    client->FetchPluginList(
        NewSingleCallback(&DisplayPlugins, ss, opts.list_plugin_ids));
  }
  return 0;
}
Example #12
0
void Tracker::SendRequest() {
  m_clock.CurrentTime(&m_send_time);
  if (FLAGS_send_dmx) {
    m_wrapper.GetClient()->SendDmx(
        FLAGS_universe,
        m_buffer,
        NewSingleCallback(this, &Tracker::SendComplete));

  } else {
    m_wrapper.GetClient()->FetchDmx(
        FLAGS_universe,
        NewSingleCallback(this, &Tracker::GotDmx));
  }
}
/*
 * Check RegisterSingleTimeout works.
 */
void TimeoutManagerTest::testSingleTimeouts() {
  MockClock clock;
  TimeoutManager timeout_manager(&m_map, &clock);

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  TimeInterval timeout_interval(1, 0);
  timeout_id id1 = timeout_manager.RegisterSingleTimeout(
      timeout_interval,
      NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 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.CurrentTime(&last_checked_time);
  TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, timeout_interval);

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_EQ(0u, GetEventCounter(1));
  OLA_ASSERT_LT(next, TimeInterval(0, 500000));

  clock.AdvanceTime(0, 500000);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_TRUE(next.IsZero());
  OLA_ASSERT_EQ(1u, GetEventCounter(1));

  OLA_ASSERT_FALSE(timeout_manager.EventsPending());

  // now add another timeout and then remove it
  timeout_id id2 = timeout_manager.RegisterSingleTimeout(
      timeout_interval,
      NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 2u));
  OLA_ASSERT_NE(id2, ola::thread::INVALID_TIMEOUT);
  OLA_ASSERT_TRUE(timeout_manager.EventsPending());
  OLA_ASSERT_EQ(0u, GetEventCounter(2));

  timeout_manager.CancelTimeout(id2);

  clock.AdvanceTime(1, 0);
  clock.CurrentTime(&last_checked_time);
  next = timeout_manager.ExecuteTimeouts(&last_checked_time);
  OLA_ASSERT_FALSE(timeout_manager.EventsPending());
  OLA_ASSERT_EQ(0u, GetEventCounter(2));
}
Example #14
0
void JaRulePortHandleImpl::RunIncrementalDiscovery(
    RDMDiscoveryCallback *callback) {
  OLA_INFO << "Incremental discovery triggered";
  m_discovery_agent.StartIncrementalDiscovery(
      NewSingleCallback(this, &JaRulePortHandleImpl::DiscoveryComplete,
      callback));
}
/*
 * Check that interleaving requests and discovery commands work.
 */
void QueueingRDMControllerTest::testRequestAndDiscovery() {
  MockRDMController mock_controller;
  auto_ptr<ola::rdm::DiscoverableQueueingRDMController> controller(
      new ola::rdm::DiscoverableQueueingRDMController(&mock_controller, 1));

  UIDSet uids;
  UID uid1(2, 3);
  UID uid2(10, 11);
  uids.AddUID(uid1);
  uids.AddUID(uid2);

  // Send a request, but don't run the RDM request callback
  RDMRequest *get_request = NewGetRequest(m_source, m_destination);
  mock_controller.ExpectCallAndCapture(get_request);

  RDMReply *expected_reply = new RDMReply(
      ola::rdm::RDM_COMPLETED_OK,
      NewGetResponse(m_destination, m_source));

  controller->SendRDMRequest(
      get_request,
      ola::NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyResponse,
          expected_reply));

  // now queue up a discovery request
  controller->RunFullDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyDiscoveryComplete,
          &uids));
  mock_controller.Verify();
  OLA_ASSERT_FALSE(m_discovery_complete_count);

  // now run the RDM callback, this should unblock the discovery process
  mock_controller.AddExpectedDiscoveryCall(true, NULL);
  mock_controller.RunRDMCallback(expected_reply);
  mock_controller.Verify();

  // now queue another RDM request
  RDMRequest *get_request2 = NewGetRequest(m_source, m_destination);
  RDMReply *expected_reply2 = new RDMReply(
      ola::rdm::RDM_COMPLETED_OK,
      NewGetResponse(m_destination, m_source));
  mock_controller.ExpectCallAndReplyWith(get_request2, expected_reply2);

  // discovery is still running so this won't send the request just yet.
  controller->SendRDMRequest(
      get_request2,
      ola::NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyResponse,
          expected_reply2));

  // now finish the discovery
  mock_controller.RunDiscoveryCallback(uids);
  OLA_ASSERT_TRUE(m_discovery_complete_count);
  mock_controller.Verify();
}
/*
 * Verify reentrant discovery works
 */
void QueueingRDMControllerTest::testReentrantDiscovery() {
  MockRDMController mock_controller;
  auto_ptr<ola::rdm::DiscoverableQueueingRDMController> controller(
      new ola::rdm::DiscoverableQueueingRDMController(&mock_controller, 1));

  UIDSet uids;
  UID uid1(2, 3);
  UID uid2(10, 11);
  uids.AddUID(uid1);
  uids.AddUID(uid2);

  // trigger discovery, the ReentrantDiscovery starts a new discovery from
  // within the callback of the first.
  mock_controller.AddExpectedDiscoveryCall(true, NULL);
  controller->RunFullDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::ReentrantDiscovery,
          controller.get(),
          &uids));
  mock_controller.Verify();

  // this will finish the first discovery attempt, and start the second
  mock_controller.AddExpectedDiscoveryCall(true, NULL);
  mock_controller.RunDiscoveryCallback(uids);
  OLA_ASSERT_TRUE(m_discovery_complete_count);
  m_discovery_complete_count = 0;
  mock_controller.Verify();

  // now unblock the second
  mock_controller.RunDiscoveryCallback(uids);
  OLA_ASSERT_TRUE(m_discovery_complete_count);
  m_discovery_complete_count = 0;
  mock_controller.Verify();
}
Example #17
0
void OpenLightingDevice::_InTransferComplete() {
  TimeStamp now;
  Clock clock;
  clock.CurrentTime(&now);
  OLA_INFO << "In transfer completed in " << (now - m_out_sent_time)
           << ", status is "
           << LibUsbAdaptor::ErrorCodeToString(m_in_transfer->status);

  if (m_in_transfer->status == LIBUSB_TRANSFER_COMPLETED) {
    // Ownership of the buffer is transferred to the HandleData method,
    // running on the SS thread.
    m_ss->Execute(
        NewSingleCallback(
          this, &OpenLightingDevice::HandleData,
          reinterpret_cast<const uint8_t*>(m_in_transfer->buffer),
          static_cast<unsigned int>(m_in_transfer->actual_length)));
  } else {
    delete[] m_in_transfer->buffer;
  }

  MutexLocker locker(&m_mutex);
  m_in_in_progress = false;
  m_pending_requests--;
  if (m_pending_requests) {
    SubmitInTransfer();
  }
}
Example #18
0
/*
 * Check that we don't invalid iterators by removing descriptors during an
 * on_read callback.
 */
void SelectServerTest::testRemoveOthersWhenReadable() {
  Descriptors read_set, write_set, delete_set;
  LoopbackDescriptor loopback1, loopback2, loopback3;
  loopback1.Init();
  loopback2.Init();
  loopback3.Init();

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

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

  loopback2.SetOnClose(NewSingleCallback(
      this,
      &SelectServerTest::RemoveAndDeleteDescriptors,
      read_set, write_set, delete_set));

  OLA_ASSERT_EQ(0, write_descriptor_count->Get());
  OLA_ASSERT_EQ(4, connected_read_descriptor_count->Get());

  loopback2.CloseClient();
  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());
}
Example #19
0
/*
 * Send a fetch device info request
 * @param client  the ola client
 * @param opts  the const options
 */
int FetchDeviceInfo(OlaCallbackClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaCallbackClient *client = wrapper->GetClient();
  client->FetchDeviceInfo((ola::ola_plugin_id) opts.plugin_id,
                          NewSingleCallback(&DisplayDevices, ss));
  return 0;
}
Example #20
0
/*
 * Main
 */
int main(int argc, char *argv[]) {
  ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
  OlaCallbackClientWrapper ola_client;
  options opts;

  InitOptions(&opts);
  opts.cmd = argv[0];

  // decide how we should behave
  SetMode(&opts);

  if (opts.m == DEVICE_PATCH)
    ParsePatchOptions(argc, argv, &opts);
  else if (opts.m == SET_PORT_PRIORITY)
    ParseSetPriorityOptions(argc, argv, &opts);
  else
    ParseOptions(argc, argv, &opts);

  if (opts.help)
    DisplayHelpAndExit(opts);

  if (!ola_client.Setup()) {
    OLA_FATAL << "Setup failed";
    exit(1);
  }

  switch (opts.m) {
    case DEVICE_INFO:
      FetchDeviceInfo(&ola_client, opts);
      break;
    case DEVICE_PATCH:
      Patch(&ola_client, opts);
      break;
    case PLUGIN_INFO:
      FetchPluginInfo(&ola_client, opts);
      break;
    case PLUGIN_STATE:
      FetchPluginState(&ola_client, opts);
      break;
    case UNIVERSE_INFO:
      ola_client.GetClient()->FetchUniverseList(
          NewSingleCallback(&DisplayUniverses,
          ola_client.GetSelectServer(), opts.list_universe_ids));
      break;
    case UNIVERSE_NAME:
      SetUniverseName(&ola_client, opts);
      break;
    case UNI_MERGE:
      SetUniverseMergeMode(&ola_client, opts);
      break;
    case SET_DMX:
      SendDmx(&ola_client, opts);
      break;
    case SET_PORT_PRIORITY:
      SetPortPriority(&ola_client, opts);
  }

  ola_client.GetSelectServer()->Run();
  return 0;
}
Example #21
0
/*
 * Send a ConfigureDevice() request
 * @param message the request to send
 */
bool OlaConfigurator::SendMessage(const google::protobuf::Message &message) {
  string request_string;
  message.SerializeToString(&request_string);
  return m_client->ConfigureDevice(
      m_alias,
      request_string,
      NewSingleCallback(this, &OlaConfigurator::HandleConfigResponse));
}
Example #22
0
/*
 * Check that method that fail return correctly
 */
void RpcChannelTest::testFailedEcho() {
  m_request.set_data("foo");
  m_stub->FailedEcho(
      &m_controller,
      &m_request,
      &m_reply,
      NewSingleCallback(this, &RpcChannelTest::FailedEchoComplete));
  m_ss.Run();
}
Example #23
0
 void OnTCPConnect(TCPSocket *socket) {
   OLA_INFO << "New connection: " << socket;
   socket->SetOnData(
       NewCallback(this, &Server::ReceiveTCPData, socket));
   socket->SetOnClose(
       NewSingleCallback(this, &Server::SocketClosed, socket));
   m_ss.AddReadDescriptor(socket);
   m_sockets.push_back(socket);
 }
Example #24
0
void DmxTriWidgetTest::AckSingleTxAndExpectData() {
  AckSingleTX();
  uint8_t expected_dmx_command[] = {0x21, 0x00, 0x00, 3, 2, 3, 45};
  m_endpoint->AddExpectedUsbProMessage(
      EXTENDED_LABEL,
      expected_dmx_command,
      sizeof(expected_dmx_command),
      NewSingleCallback(this, &DmxTriWidgetTest::AckSingleTxAndTerminate));
}
Example #25
0
/*
 * send a set name request
 * @param client the ola client
 * @param opts  the const options
 */
int SetUniverseName(OlaCallbackClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaCallbackClient *client = wrapper->GetClient();
  if (opts.uni == INVALID_VALUE) {
    DisplayUniverseNameHelp(opts);
    exit(1);
  }
  client->SetUniverseName(opts.uni, opts.uni_name,
                          NewSingleCallback(&UniverseNameComplete, ss));
  return 0;
}
Example #26
0
/*
 * Fetch the state of a plugin.
 */
int FetchPluginState(OlaCallbackClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaCallbackClient *client = wrapper->GetClient();
  if (opts.plugin_id == 0) {
    DisplayPluginStateHelp(opts);
    exit(1);
  }
  client->FetchPluginState((ola::ola_plugin_id) opts.plugin_id,
                           NewSingleCallback(&DisplayPluginState, ss));
  return 0;
}
Example #27
0
/**
 * Test the MultiCallback works with a 0 limit
 */
void MultiCallbackTest::testZeroLimit() {
  BaseCallback0<void> *callback = NewSingleCallback(
      this,
      &MultiCallbackTest::CallbackMethod);

  CPPUNIT_ASSERT_EQUAL(0, m_callback_count);
  BaseCallback0<void> *multi_callback = NewMultiCallback(0, callback);
  CPPUNIT_ASSERT_EQUAL(1, m_callback_count);

  (void) multi_callback;
}
Example #28
0
/*
 * Set the priority of a port
 */
void SetPortPriority(OlaCallbackClientWrapper *wrapper, const options &opts) {
  SelectServer *ss = wrapper->GetSelectServer();
  OlaCallbackClient *client = wrapper->GetClient();

  if (opts.device_id == INVALID_VALUE || opts.port_id == INVALID_VALUE) {
    DisplaySetPriorityHelp(opts);
    exit(1);
  }

  if (opts.priority_mode == ola::PRIORITY_MODE_INHERIT) {
    client->SetPortPriorityInherit(
        opts.device_id, opts.port_id, opts.port_direction,
        NewSingleCallback(&SetPortPriorityComplete, ss));
  } else if (opts.priority_mode == ola::PRIORITY_MODE_STATIC) {
    client->SetPortPriorityOverride(
        opts.device_id, opts.port_id, opts.port_direction, opts.priority_value,
        NewSingleCallback(&SetPortPriorityComplete, ss));
  } else {
    DisplaySetPriorityHelp(opts);
  }
}
void QueueingRDMControllerTest::ReentrantDiscovery(
    ola::rdm::DiscoverableQueueingRDMController *controller,
    UIDSet *expected_uids,
    const UIDSet &uids) {
  OLA_ASSERT_EQ(*expected_uids, uids);
  m_discovery_complete_count++;
  controller->RunFullDiscovery(
      NewSingleCallback(
          this,
          &QueueingRDMControllerTest::VerifyDiscoveryComplete,
          expected_uids));
}
Example #30
0
/**
 * Test the MultiCallback works with a single limit
 */
void MultiCallbackTest::testSingleLimit() {
  BaseCallback0<void> *callback = NewSingleCallback(
      this,
      &MultiCallbackTest::CallbackMethod);

  CPPUNIT_ASSERT_EQUAL(0, m_callback_count);
  BaseCallback0<void> *multi_callback = NewMultiCallback(1, callback);
  CPPUNIT_ASSERT_EQUAL(0, m_callback_count);

  multi_callback->Run();
  CPPUNIT_ASSERT_EQUAL(1, m_callback_count);
}