/* * Copyright information and license terms for this software can be * found in the file LICENSE that is included with the distribution */ // The simplest possible PVA monitor #include #if !defined(_WIN32) #include #define USE_SIGNAL #endif #include #include static volatile bool done; #ifdef USE_SIGNAL static pvac::MonitorSync * volatile subscription; static void handler(int num) { (void)num; done = true; pvac::MonitorSync *mon = subscription; if(mon) mon->wake(); } #endif int main(int argc, char *argv[]) { try { if(argc<=1) { std::cerr<<"Usage: "<\n"; return 1; } pvac::ClientProvider provider("pva"); pvac::ClientChannel channel(provider.connect(argv[1])); pvac::MonitorSync mon(channel.monitor()); #ifdef USE_SIGNAL subscription = &mon; signal(SIGINT, handler); signal(SIGTERM, handler); signal(SIGQUIT, handler); #endif int ret = 0; while(!done) { if(!mon.wait()) // updates mon.event continue; switch(mon.event.event) { // Subscription network/internal error case pvac::MonitorEvent::Fail: std::cerr<\n"; done = true; break; // Underlying channel becomes disconnected case pvac::MonitorEvent::Disconnect: std::cout<\n"; break; // Data queue becomes not-empty case pvac::MonitorEvent::Data: // We drain event FIFO completely while(mon.poll()) { std::cout<\n"; } break; } } #ifdef USE_SIGNAL signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGQUIT, SIG_DFL); subscription = 0; #endif return ret; }catch(std::exception& e){ std::cerr<<"Error: "<