X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Frmr_dump.cpp;h=860caf57ef6647428eb4dd8a2f363d65637591de;hb=6ef23e1d7f7f47ccab5be6ff1b68e5cfdda80ad2;hp=5cced219d2c4127aebf032f3fee872eb164d8e76;hpb=0b08d9dc1639e926c1df4535703b67903a86aad7;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/examples/rmr_dump.cpp b/examples/rmr_dump.cpp index 5cced21..860caf5 100644 --- a/examples/rmr_dump.cpp +++ b/examples/rmr_dump.cpp @@ -27,9 +27,9 @@ on by the application. The verbosity level may be used to increase the amount of detail given for the tracked messages. - This writes to the TTY which is slow, so do not expect it to be able + This writes to the TTY which is slow, so do not expect it to be able to process and report on a high rate of messages. Also, forwarded - messages will reach the intended target, however if the target + messages will reach the intended target, however if the target attempts to send a response the response will come back to THIS application, and not the message origination; this cannot be a bit of middleware in it's current form. @@ -37,7 +37,12 @@ Date: 25 March 2020 Author: E. Scott Daniels + Caution: This example code is pulled directly into one or more of the documents + (starting from the "start-example" tag below. Use caution with + line lengths and contents because of the requirement that this + be documentation as well as working code. */ +// start-example #include #include #include @@ -50,15 +55,15 @@ by the framework. */ typedef struct { - int vlevel; // verbosity level - bool forward; // if true, message is forwarded - int stats_freq; // header/stats after n messages - std::atomic pcount; // messages processed - std::atomic icount; // messages ignored - std::atomic hdr; // number of messages before next header + int vlevel; // verbosity level + bool forward; // if true, message is forwarded + int stats_freq; // header/stats after n messages + std::atomic pcount; // messages processed + std::atomic icount; // messages ignored + std::atomic hdr; // number of messages before next header } cb_info_t; -// ---------------------------------------------------------- +// ---------------------------------------------------------------------- /* Dump bytes to tty. @@ -73,10 +78,10 @@ void dump( unsigned const char* buf, int len ) { for( i = 0; i < len; i++ ) { cheater[j++] = isprint( buf[i] ) ? buf[i] : '.'; fprintf( stdout, "%02x ", buf[i] ); - + if( j == 16 ) { cheater[j] = 0; - fprintf( stdout, " | %s\n %04x | ", cheater, i+1 ); + fprintf( stdout, " | %s\n %04x | ", cheater, i+1 ); j = 0; } } @@ -87,7 +92,7 @@ void dump( unsigned const char* buf, int len ) { fprintf( stdout, " " ); } cheater[j] = 0; - fprintf( stdout, " | %s\n", cheater ); + fprintf( stdout, " | %s\n", cheater ); } } @@ -101,10 +106,10 @@ void stats( cb_info_t& cbi ) { curv = cbi.hdr--; if( curv == 0 ) { // stats when we reach 0 - fprintf( stdout, "ignored: %ld processed: %ld\n", + fprintf( stdout, "ignored: %ld processed: %ld\n", cbi.icount.load(), cbi.pcount.load() ); if( cbi.vlevel > 0 ) { - fprintf( stdout, "\n %5s %5s %2s %5s\n", + fprintf( stdout, "\n %5s %5s %2s %5s\n", "MTYPE", "SUBID", "ST", "PLLEN" ); } @@ -112,8 +117,8 @@ void stats( cb_info_t& cbi ) { } } -void cb1( Message& mbuf, int mtype, int subid, int len, - Msg_component payload, void* data ) { +void cb1( xapp::Message& mbuf, int mtype, int subid, int len, + xapp::Msg_component payload, void* data ) { cb_info_t* cbi; long total_count; @@ -135,7 +140,7 @@ void cb1( Message& mbuf, int mtype, int subid, int len, if( cbi->forward ) { // forward with no change to len or payload - mbuf.Send_msg( Message::NO_CHANGE, NULL ); + mbuf.Send_msg( xapp::Message::NO_CHANGE, NULL ); } } @@ -143,8 +148,8 @@ void cb1( Message& mbuf, int mtype, int subid, int len, registered as the default callback; it counts the messages that we aren't giving details about. */ -void cbd( Message& mbuf, int mtype, int subid, int len, - Msg_component payload, void* data ) { +void cbd( xapp::Message& mbuf, int mtype, int subid, int len, + xapp::Msg_component payload, void* data ) { cb_info_t* cbi; if( (cbi = (cb_info_t *) data) == NULL ) { @@ -156,7 +161,7 @@ void cbd( Message& mbuf, int mtype, int subid, int len, if( cbi->forward ) { // forward with no change to len or payload - mbuf.Send_msg( Message::NO_CHANGE, NULL ); + mbuf.Send_msg( xapp::Message::NO_CHANGE, NULL ); } } @@ -187,7 +192,7 @@ int main( int argc, char** argv ) { cbi->forward = true; break; - case 'p': // define port + case 'p': // define port port = argv[ai+1]; ai++; break; @@ -219,9 +224,13 @@ int main( int argc, char** argv ) { default: fprintf( stderr, "unrecognised option: %s\n", argv[ai] ); - fprintf( stderr, "usage: %s [-f] [-p port] [-s stats-freq] [-t thread-count] [-v | -V n] msg-type1 ... msg-typen\n", argv[0] ); - fprintf( stderr, "\tstats frequency is in number of messages received\n" ); - fprintf( stderr, "\tverbose levels (-V) 0 counts only, 1 message info 2 payload dump\n" ); + fprintf( stderr, "usage: %s [-f] [-p port] " + "[-s stats-freq] [-t thread-count] " + "[-v | -V n] msg-type1 ... msg-typen\n", + argv[0] ); + fprintf( stderr, "\tstats frequency is based on # of messages received\n" ); + fprintf( stderr, "\tverbose levels (-V) 0 counts only, " + "1 message info 2 payload dump\n" ); exit( 1 ); } @@ -235,7 +244,7 @@ int main( int argc, char** argv ) { x = std::unique_ptr( new Xapp( port, cbi->forward ) ); // register callback for each type on the command line - while( ai < argc ) { + while( ai < argc ) { mtype = atoi( argv[ai] ); ai++; fprintf( stderr, " capturing messages for type %d\n", mtype );