本文整理汇总了C++中ola::NewSingleCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ ola::NewSingleCallback方法的具体用法?C++ ola::NewSingleCallback怎么用?C++ ola::NewSingleCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ola
的用法示例。
在下文中一共展示了ola::NewSingleCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewSingleCallback
/*
* 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;
}
示例2: testQueuedMessages
/*
* 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();
}
示例3: 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());
}
示例4: FetchPluginState
/*
* 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;
}
示例5: MessageQueue
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;
}
}
示例6: testNack
/*
* 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;
}
示例7: testMultipleDiscovery
/*
* 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();
}
示例8: RunDiscovery
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));
}
}
示例9: FetchPluginInfo
/*
* 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;
}
示例10: SendRequest
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));
}
}
示例11: testSingleTimeouts
/*
* 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));
}
示例12: RunIncrementalDiscovery
void JaRulePortHandleImpl::RunIncrementalDiscovery(
RDMDiscoveryCallback *callback) {
OLA_INFO << "Incremental discovery triggered";
m_discovery_agent.StartIncrementalDiscovery(
NewSingleCallback(this, &JaRulePortHandleImpl::DiscoveryComplete,
callback));
}
示例13: controller
/*
* 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();
}
示例14: testReentrantDiscovery
/*
* 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();
}
示例15: _InTransferComplete
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();
}
}