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 demo xapp which controls it's own listen
24 loop (does not register callbacks and does not invoke the
25 run function in the xapp instance.
28 Author: E. Scott Daniels
39 #include "ricxfcpp/xapp.hpp"
41 // ----------------------------------------------------------
43 extern int main( int argc, char** argv ) {
44 std::unique_ptr<Xapp> xfw;
45 std::unique_ptr<Message> msg;
46 Msg_component payload; // special type of unique pointer to the payload
51 int response_to = 0; // max timeout wating for a response
52 char* port = (char *) "4555";
54 int rmtype; // received message type
55 int delay = 1000000; // mu-sec delay; default 1s
59 while( ai < argc ) { // very simple flag processing (no bounds/error checking)
60 if( argv[ai][0] != '-' ) {
64 switch( argv[ai][1] ) { // we only support -x so -xy must be -x -y
65 case 'd': // delay between messages (mu-sec)
66 delay = atoi( argv[ai+1] );
75 case 't': // timeout in seconds; we need to convert to ms for rmr calls
76 response_to = atoi( argv[ai+1] ) * 1000;
83 fprintf( stderr, "<XAPP> response timeout set to: %d\n", response_to );
84 fprintf( stderr, "<XAPP> listening on port: %s\n", port );
86 xfw = std::unique_ptr<Xapp>( new Xapp( port, true ) ); // new xAPP thing; wait for a route table
87 msg = xfw->Alloc_msg( 2048 );
89 for( i = 0; i < 100; i++ ) {
95 sz = msg->Get_available_size(); // we'll reuse a message if we received one back; ensure it's big enough
97 fprintf( stderr, "<SNDR> fail: message returned did not have enough size: %d [%d]\n", sz, i );
101 payload = msg->Get_payload(); // direct access to payload
102 snprintf( (char *) payload.get(), 2048, "This is message %d\n", i ); // something silly to send
104 // payload updated in place, nothing to copy from, so payload parm is nil
105 if ( ! msg->Send_msg( mtype, Message::NO_SUBID, strlen( (char *) payload.get() )+1, NULL )) {
106 fprintf( stderr, "<SNDR> send failed: %d\n", i );
109 msg = xfw->Receive( response_to );
111 rmtype = msg->Get_mtype();
112 payload = msg->Get_payload();
113 fprintf( stderr, "got: mtype=%d payload=(%s)\n", rmtype, (char *) payload.get() );
115 msg = xfw->Alloc_msg( 2048 ); // nothing back, need a new message to send