2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
20 #ifndef XAPP_RMR_XAPP_RMR_H_
21 #define XAPP_RMR_XAPP_RMR_H_
25 #define likely(x) __builtin_expect((x), 1)
26 #define unlikely(x) __builtin_expect((x), 0)
29 #define unlikely(x) (x)
42 #include <sys/epoll.h>
44 #include <rmr/RIC_message_types.h>
45 #include <mdclog/mdclog.h>
52 int32_t payload_length;
53 unsigned char xid[RMR_MAX_XID]; //space for user transaction id.
54 unsigned char sid[RMR_MAX_SID]; //sender ID for return to sender needs.(ACKS required)
55 unsigned char src[RMR_MAX_SRC]; //name of the sender (source)
61 std::string _xapp_name;
62 std::string _proto_port;
66 rmr_mbuf_t* _xapp_send_buff; // send buffer
67 rmr_mbuf_t* _xapp_received_buff; // received buffer
72 XappRmr(std::string, std::string, int rmrattempts=10);
74 void xapp_rmr_init(void);
76 template <class MessageProcessor>
77 void xapp_rmr_receive(MessageProcessor&&, XappRmr *parent);
78 bool xapp_rmr_send(xapp_rmr_header*, void*);
84 template <class MessageProcessor>
85 void XappRmr::xapp_rmr_receive(MessageProcessor&& msgproc, XappRmr *parent){
88 if( (listen_port = getenv( "RMR_RCV_PORT" )) == NULL ) {
89 mdclog_write(MDCLOG_ERR,"No Listening port assigned, file= %s, line=%d",__FILE__,__LINE__);
93 mdclog_write( MDCLOG_ERR, "RMR Shows Not Ready in RECEIVER, file= %s, line=%d ",__FILE__,__LINE__);
98 parent->_xapp_received_buff = rmr_rcv_msg( parent->_xapp_rmr_ctx, parent->_xapp_received_buff ); // block until one arrives
99 if( parent->_xapp_received_buff->mtype < 0 || parent->_xapp_received_buff->state != RMR_OK ) {
100 mdclog_write(MDCLOG_ERR, "bad msg: state=%d errno=%d, file= %s, line=%d", parent->_xapp_received_buff->state, errno, __FILE__,__LINE__ );
103 std::cout << "The Message Received is:" << (char*)parent->_xapp_received_buff->payload <<std::endl;
104 std::cout << "The Message Received Type is:" << _xapp_received_buff->mtype <<std::endl;
105 _xapp_send_buff = msgproc(_xapp_received_buff);
106 if(_xapp_send_buff !=NULL)
109 //_xapp_received_buff = NULL;
117 #endif /* XAPP_RMR_XAPP_RMR_H_ */