1 // vim: ts=4 sw=4 noet :
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: RMR emulation for testing
26 Author: E. Scott Daniels
35 CAUTION: this is a copy of what is in RMR and it is needed as some of the framework
36 functions access the 'public' fields like state and mtype.
39 int state; // state of processing
40 int mtype; // message type
41 int len; // length of data in the payload (send or received)
42 unsigned char* payload; // transported data
43 unsigned char* xaction; // pointer to fixed length transaction id bytes
44 int sub_id; // subscription id
45 int tp_state; // transport state (errno) valid only if state != RMR_OK, and even then may not be valid
47 // these things are off limits to the user application
48 void* tp_buf; // underlying transport allocated pointer (e.g. nng message)
49 void* header; // internal message header (whole buffer: header+payload)
50 unsigned char* id; // if we need an ID in the message separate from the xaction id
51 int flags; // various MFL_ (private) flags as needed
52 int alloc_len; // the length of the allocated space (hdr+payload)
54 void* ring; // ring this buffer should be queued back to
55 int rts_fd; // SI fd for return to sender
57 int cookie; // cookie to detect user misuse of free'd msg
66 void* rmr_init( char* port, int flags ) {
67 return malloc( sizeof( char ) * 100 );
70 rmr_mbuf_t* rmr_alloc_msg( void* mrc, int payload_len ) {
72 char* p; // the tp buffer; also the payload
76 len = (sizeof( char ) * payload_len) + sizeof( header_t );
77 p = (char *) malloc( len );
84 mbuf = (rmr_mbuf_t *) malloc( sizeof( rmr_mbuf_t ) );
89 memset( mbuf, 0, sizeof( rmr_mbuf_t ) );
92 mbuf->payload = (char *)p + sizeof( header_t );
96 mbuf->alloc_len = payload_len;
97 mbuf->payload = (void *) p;
98 strncpy( h->src, "host:ip", 8 );
99 strncpy( h->meid, "EniMeini", 9 );
104 void rmr_free_msg( rmr_mbuf_t* mbuf ) {
107 free( mbuf->tp_buf );
113 char* rmr_get_meid( rmr_mbuf_t* mbuf, char* m ) {
118 m = (char *) malloc( sizeof( char ) * 32 );
120 h = (header_t *) mbuf->tp_buf;
121 memcpy( m, h->meid, 32 );
127 int rmr_payload_size( rmr_mbuf_t* mbuf ) {
130 return mbuf->alloc_len;
136 char *rmr_get_src( rmr_mbuf_t* mbuf, char *m ) {
141 m = (char *) malloc( sizeof( char ) * 32 );
143 h = (header_t *) mbuf->tp_buf;
144 memcpy( m, h->src, 32 );
150 int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char* s ) {
158 if( strlen( s ) > 31 ) {
162 h = (header_t *) mbuf->tp_buf;
163 strncpy( h->meid, s, 32 );
170 rmr_mbuf_t* rmr_send_msg( void* mrc, rmr_mbuf_t* mbuf ) {
179 rmr_mbuf_t* rmr_rts_msg( void* mrc, rmr_mbuf_t* mbuf ) {
188 rmr_mbuf_t* rmr_realloc_payload( rmr_mbuf_t* mbuf, int payload_len, int copy, int clone ) { // ensure message is large enough
190 unsigned char* payload;
196 nmb = rmr_alloc_msg( NULL, payload_len );
198 memcpy( nmb->payload, mbuf->payload, mbuf->len );
199 nmb->len = mbuf->len;
203 nmb->state = mbuf->state;
211 void rmr_close( void* mrc ) {
215 rmr_mbuf_t* rmr_torcv_msg( void* mrc, rmr_mbuf_t* mbuf, int timeout ) {
216 static int max2receive = 500;
217 static int mtype = 0;
220 mbuf = rmr_alloc_msg( NULL, 2048 );
223 if( max2receive <= 0 ) {
245 int rmr_ready( void* mrc ) {
246 static int state = 0;
256 // ----------------------- wormhole dummies ---------------------------------------------
258 typedef int rmr_whid_t;
260 extern rmr_whid_t rmr_wh_open( void* vctx, char const* target ) {
269 //extern rmr_mbuf_t* rmr_wh_call( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg, int call_id, int max_wait );
271 extern rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t whid, rmr_mbuf_t* mbuf ) {
283 extern int rmr_wh_state( void* vctx, rmr_whid_t whid ) {
287 extern void rmr_wh_close( void* vctx, int whid ){