// RSTP Client Daemon - Writing received data to queues // Revised: 10 August 2005 // Release: 6 May 2007 // Copyright (C) 2007 Nicholas Luther // License: GPL // // qclient.cpp // compile with: // g++ -o qclient qclient.cpp -lradar_queue -lradar_stp // #include #include using namespace libradar_stp; #include #include #include #include #include #include #include using namespace std; #include #include #include #include #include bool quitnow = false; string prog_id("RSTPCD"); string filter_file; Filter filter; RSTPClientIf client; void datacb ( void* ref, const string& stream, const string& data ); void catchsig ( int s ) { if ( s == 13 ) // SIGPIPE isn't a very good reason to quit! return; quitnow = true; } int main ( int argc, char** argv ) { string conf_file("rstpconf.txt"); bool daemonize = false; bool have_args = false; // parse cmd line for ( int argi = 1; argi < argc; ++argi ) { string arg( argv[argi] ); if ( argi + 1 < argc ) { if ( arg == "-r" ) { conf_file = argv[argi+1]; have_args = true; } else if ( arg == "-p" ) { prog_id = argv[argi+1]; have_args = true; } else if ( arg == "-f" ) { filter_file = argv[argi+1]; have_args = true; } } if ( arg == "-v" || arg == "-h" || arg == "--help" || arg == "--version" ) { cout << argv[0] << " usage:" << endl << argv[0] << " [-r rstpconf] [-f filter] [-p progid] [-d]" << endl << endl << "Linked to libradar_stp and libradar_queue" << endl << endl; return 0; } else if ( arg == "-d" ) { daemonize = true; have_args = true; } } // initialize filter if ( !filter_file.empty() ) { filter.setFile( filter_file ); } if ( !have_args ) { cerr << argv[0] << " starting with default arguments." << endl; cerr << "Send SIGINT to stop." << endl; cerr << "Use --help to figure out how to run this." << endl; } signal( 2, catchsig ); signal( 15, catchsig ); signal( 13, catchsig ); if ( daemonize ) { daemon( 0, 0 ); } //RSTPClientIf c; client.setDataCallback( datacb, 0 ); client.loadFile( conf_file ); client.start(); while ( !quitnow ) { sleep (1); } client.quit(); return 0; } void datacb ( void* ref, const string& stream, const string& data ) { #ifdef DEBUG cerr << "received data, stream " << stream << ", length: " << data.length() << endl; #endif if ( !filter_file.empty() && !filter.check( data, 0 ) ) { return; } #ifdef DEBUG cerr << "passed filter check, pushing to queues" << endl; #endif vector queues = radarq_get_queues( prog_id, RADARQ_MODE_WRITE ); for ( vector::iterator it = queues.begin(); it != queues.end(); ++it ) { radarq_queue_push( (*it), data ); } }