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)); } }
void DmxMonitor::RegisterComplete(const string &error) { if (!error.empty()) { std::cerr << "Register command failed with " << errno << std::endl; m_client.GetSelectServer()->Terminate(); } }
/* * Setup the monitoring console */ bool DmxMonitor::Init() { /* set up ola connection */ if (!m_client.Setup()) { printf("error: %s", strerror(errno)); return false; } OlaCallbackClient *client = m_client.GetClient(); client->SetDmxCallback(ola::NewCallback(this, &DmxMonitor::NewDmx)); client->RegisterUniverse( m_universe, ola::REGISTER, ola::NewSingleCallback(this, &DmxMonitor::RegisterComplete)); /* init curses */ m_window = initscr(); if (!m_window) { printf("unable to open main-screen\n"); return false; } savetty(); start_color(); noecho(); raw(); keypad(m_window, TRUE); m_client.GetSelectServer()->AddReadDescriptor(&m_stdin_descriptor); m_stdin_descriptor.SetOnData( ola::NewCallback(this, &DmxMonitor::StdinReady)); m_client.GetSelectServer()->RegisterRepeatingTimeout( 500, ola::NewCallback(this, &DmxMonitor::CheckDataLoss)); CalcScreenGeometry(); ChangePalette(m_palette_number); m_buffer.Blackout(); timerclear(&m_last_data); DrawScreen(); return true; }
void UniverseTracker::Input(char c) { switch (c) { case 'q': m_wrapper->GetSelectServer()->Terminate(); break; case 'p': PrintStats(); break; case 'r': ResetStats(); break; default: break; } }
void Tracker::LogTime() { TimeStamp now; m_clock.CurrentTime(&now); TimeInterval delta = now - m_send_time; if (delta > m_max) { m_max = delta; } m_sum += delta.MicroSeconds(); OLA_INFO << "RPC took " << delta; if (FLAGS_count == ++m_count) { m_wrapper.GetSelectServer()->Terminate(); } else { SendRequest(); } }
void Tracker::Start() { ola::io::SelectServer *ss = m_wrapper.GetSelectServer(); m_signal_thread.InstallSignalHandler( SIGINT, ola::NewCallback(ss, &ola::io::SelectServer::Terminate)); m_signal_thread.InstallSignalHandler( SIGTERM, ola::NewCallback(ss, &ola::io::SelectServer::Terminate)); SendRequest(); ss->Execute(ola::NewSingleCallback(this, &Tracker::StartSignalThread)); ss->Run(); // Print this via cout to ensure we actually get some output by default // It also means you can just see the stats and not each individual request // if you want. cout << "--------------" << endl; cout << "Sent " << m_count << " RPCs" << endl; cout << "Max was " << m_max.MicroSeconds() << " microseconds" << endl; cout << "Mean " << m_sum / m_count << " microseconds" << endl; }
bool UniverseTracker::Run() { m_clock.CurrentTime(&m_start_time); m_wrapper->GetSelectServer()->Run(); return true; }
/* * Called when there is input from the keyboard */ void DmxMonitor::StdinReady() { int c = wgetch(m_window); switch (c) { case KEY_HOME: current_channel = 0; first_channel = 0; DrawScreen(); break; case KEY_END: current_channel = DMX_UNIVERSE_SIZE - 1; if (channels_per_screen >= DMX_UNIVERSE_SIZE) { first_channel = 0; } else { first_channel = current_channel - (channels_per_screen - 1); } DrawScreen(); break; case 'l': case 'L': case KEY_RIGHT: if (current_channel < DMX_UNIVERSE_SIZE - 1) { current_channel++; if (current_channel >= static_cast<int>(first_channel + channels_per_screen)) { first_channel += channels_per_line; } DrawScreen(); } break; case 'h': case 'H': case KEY_LEFT: if (current_channel > 0) { current_channel--; if (current_channel < first_channel) { first_channel -= channels_per_line; if (first_channel < 0) first_channel = 0; } DrawScreen(); } break; case 'j': case 'J': case KEY_DOWN: current_channel += channels_per_line; if (current_channel >= DMX_UNIVERSE_SIZE) current_channel = DMX_UNIVERSE_SIZE - 1; if (current_channel >= static_cast<int>(first_channel + channels_per_screen)) { first_channel += channels_per_line; } DrawScreen(); break; case 'k': case 'K': case KEY_UP: current_channel -= channels_per_line; if (current_channel < 0) current_channel = 0; if (current_channel < first_channel) { first_channel -= channels_per_line; if (first_channel < 0) first_channel = 0; } DrawScreen(); break; case 'M': case 'm': if (++display_mode >= DISP_MODE_MAX) display_mode = 0; DrawScreen(); break; case 'N': case 'n': m_channels_offset = !m_channels_offset; DrawScreen(false); break; case 'P': case 'p': ChangePalette(++m_palette_number); DrawScreen(); break; case 'Q': case 'q': m_client.GetSelectServer()->Terminate(); break; default: break; } }
bool Tracker::Setup() { return m_wrapper.Setup(); }
void Tracker::StartSignalThread() { if (!m_signal_thread.Start()) { m_wrapper.GetSelectServer()->Terminate(); } }