X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Fxapp_t1.cpp;h=0de4e110e97e8b2cb79311e0ae19e1f40b205e32;hb=ef3620529c936a8790d6970c57198b4caee09c0d;hp=5ec8536aa055f7bdabd7d0ef82fa511322d6051d;hpb=6ef23e1d7f7f47ccab5be6ff1b68e5cfdda80ad2;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/examples/xapp_t1.cpp b/examples/xapp_t1.cpp index 5ec8536..0de4e11 100644 --- a/examples/xapp_t1.cpp +++ b/examples/xapp_t1.cpp @@ -45,6 +45,7 @@ #include "ricxfcpp/message.hpp" #include "ricxfcpp/msg_component.hpp" +#include #include "ricxfcpp/xapp.hpp" // counts; not thread safe @@ -55,7 +56,10 @@ long cbd_count = 0; long cb1_lastts = 0; long cb1_lastc = 0; -// respond with 2 messages for each type 1 received +/* + Respond with 2 messages for each type 1 received + Send metrics every 1000 messages. +*/ void cb1( xapp::Message& mbuf, int mtype, int subid, int len, xapp::Msg_component payload, void* data ) { long now; @@ -66,6 +70,16 @@ void cb1( xapp::Message& mbuf, int mtype, int subid, int len, mbuf.Send_response( 101, -1, 5, (unsigned char *) "OK2\n" ); cb1_count++; + + if( cb1_count % 1000 == 0 && data != NULL ) { // send metrics every 1000 messages + auto x = (Xapp *) data; + auto msgm = std::shared_ptr( x->Alloc_msg( 4096 ) ); + + auto m = std::unique_ptr( new xapp::Metrics( msgm ) ); + m->Push_data( "tst_cb1", (double) cb1_count ); + m->Push_data( "tst_cb2", (double) cb2_count ); + m->Send(); + } } // just count messages @@ -111,7 +125,7 @@ int main( int argc, char** argv ) { fprintf( stderr, " starting %d threads\n", nthreads ); x = new Xapp( port, true ); - x->Add_msg_cb( 1, cb1, NULL ); // register callbacks + x->Add_msg_cb( 1, cb1, x ); // register callbacks x->Add_msg_cb( 2, cb2, NULL ); x->Add_msg_cb( x->DEFAULT_CALLBACK, cbd, NULL );