3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
23 Abstract: This is a simple xAPP which includes using the config support
24 in the framework. It is based on the xapp_t1 example and doesn't
25 do much more than that.
28 Author: E. Scott Daniels
30 Caution: This example code is pulled directly into one or more of the documents
31 (starting from the "start-example" tag below. Use caution with
32 line lengths and contents because of the requirement that this
33 be documentation as well as working code.
38 #include "ricxfcpp/config.hpp"
39 #include "ricxfcpp/message.hpp"
40 #include "ricxfcpp/msg_component.hpp"
41 #include <ricxfcpp/metrics.hpp>
42 #include "ricxfcpp/xapp.hpp"
44 int vlevel = 0; // verbose mode set via config
47 Just print something to the tty when we receive a message
48 and are in verbose mode.
50 void cb1( xapp::Message& mbuf, int mtype, int subid, int len,
51 xapp::Msg_component payload, void* data ) {
53 fprintf( stdout, "message received is %d bytes long\n", len );
58 Driven when the configuration changes. We snarf the verbose
59 level from the new config and update it. If it changed to
60 >0, incoming messages should be recorded with a tty message.
61 If set to 0, then tty output will be disabled.
63 void config_cb( xapp::Config& c, void* data ) {
66 if( (vp = (int *) data) != NULL ) {
67 *vp = c.Get_control_value( "verbose_level", *vp );
71 int main( int argc, char** argv ) {
74 std::unique_ptr<xapp::Config> cfg;
76 // only parameter recognised is the config file name
78 cfg = std::unique_ptr<xapp::Config>( new xapp::Config( std::string( argv[1] ) ) );
80 cfg = std::unique_ptr<xapp::Config>( new xapp::Config( ) );
83 // must get a port from the config; no default
84 auto port = cfg->Get_port( "rmr-data" );
86 fprintf( stderr, "<FAIL> no port in config file\n" );
90 // dig other data from the config
91 vlevel = cfg->Get_control_value( "verbose_level", 0 );
92 nthreads = cfg->Get_control_value( "thread_count", 1 );
93 // very simple flag processing (no bounds/error checking)
96 fprintf( stderr, "<XAPP> listening on port: %s\n", port.c_str() );
97 fprintf( stderr, "<XAPP> starting %d threads\n", nthreads );
100 // register the config change notification callback
101 cfg->Set_callback( config_cb, (void *) &vlevel );
103 x = new Xapp( port.c_str(), true );
104 x->Add_msg_cb( 1, cb1, x ); // register message callback
106 x->Run( nthreads ); // let framework drive
107 // control should not return