Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 1 | // : vi ts=4 sw=4 noet : |
| 2 | /* |
| 3 | ================================================================================== |
| 4 | Copyright (c) 2019 Nokia |
| 5 | Copyright (c) 2018-2019 AT&T Intellectual Property. |
| 6 | |
| 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 |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 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 | ================================================================================== |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Mnemonic: rmr.h |
| 23 | Abstract: General (public) header file for the uta message routing library |
| 24 | Author: E. Scott Daniels |
| 25 | Date: 27 November 2018 |
| 26 | */ |
| 27 | |
| 28 | #ifndef _rmr_h |
| 29 | #define _rmr_h |
| 30 | |
| 31 | #include <sys/epoll.h> // broken on mac |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | #define RMR_MAX_XID 32 // space in header reserved for user xaction id |
| 39 | #define RMR_MAX_SID 32 // spece in header reserved for sender id |
| 40 | #define RMR_MAX_MEID 32 // spece in header reserved for managed element id |
E. Scott Daniels | 68c5cf1 | 2019-04-12 15:14:40 +0000 | [diff] [blame] | 41 | #define RMR_MAX_SRC 64 // max length of hostname (which could be IPv6 addr with [...]:port so more than the 39 bytes of a plain addr |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 42 | #define RMR_MAX_RCV_BYTES 4096 // max bytes we support in a receive message |
| 43 | |
| 44 | // various flags for function calls |
| 45 | #define RMRFL_NONE 0x00 // no flags |
| 46 | #define RMRFL_AUTO_ALLOC 0x01 // send auto allocates a zerocopy buffer |
| 47 | |
| 48 | #define RMR_DEF_SIZE 0 // pass as size to have msg allocation use the default msg size |
| 49 | |
| 50 | |
| 51 | #define RMR_OK 0 // state is good |
| 52 | #define RMR_ERR_BADARG 1 // argument passd to function was unusable |
| 53 | #define RMR_ERR_NOENDPT 2 // send/call could not find an endpoint based on msg type |
| 54 | #define RMR_ERR_EMPTY 3 // msg received had no payload; attempt to send an empty message |
| 55 | #define RMR_ERR_NOHDR 4 // message didn't contain a valid header |
| 56 | #define RMR_ERR_SENDFAILED 5 // send failed; errno has nano reason |
| 57 | #define RMR_ERR_CALLFAILED 6 // unable to send call() message |
| 58 | #define RMR_ERR_NOWHOPEN 7 // no wormholes are open |
| 59 | #define RMR_ERR_WHID 8 // wormhole id was invalid |
| 60 | #define RMR_ERR_OVERFLOW 9 // operation would have busted through a buffer/field size |
| 61 | #define RMR_ERR_RETRY 10 // request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers) |
| 62 | #define RMR_ERR_RCVFAILED 11 // receive failed (hard error) |
| 63 | #define RMR_ERR_TIMEOUT 12 // message processing call timed out |
| 64 | #define RMR_ERR_UNSET 13 // the message hasn't been populated with a transport buffer |
| 65 | #define RMR_ERR_TRUNC 14 // received message likely truncated |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 66 | #define RMR_ERR_INITFAILED 15 // initialisation of something (probably message) failed |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 67 | |
| 68 | #define RMR_WH_CONNECTED(a) (a>=0) // for now whid is integer; it could be pointer at some future date |
| 69 | |
| 70 | /* |
| 71 | General message buffer. Passed to send and returned by receive. |
| 72 | |
| 73 | (All fields are exposed such that if a wrapper needs to dup the storage as it passes |
| 74 | into or out of their environment they dup it all, not just what we choose to expose.) |
| 75 | */ |
| 76 | typedef struct { |
| 77 | int state; // state of processing |
| 78 | int mtype; // message type |
| 79 | int len; // length of data in the payload (send or received) |
| 80 | unsigned char* payload; // transported data |
| 81 | unsigned char* xaction; // pointer to fixed length transaction id bytes |
| 82 | |
| 83 | // these things are off limits to the user application |
| 84 | void* tp_buf; // underlying transport allocated pointer (e.g. nng message) |
| 85 | void* header; // internal message header (whole buffer: header+payload) |
| 86 | unsigned char* id; // if we need an ID in the message separate from the xaction id |
| 87 | int flags; // various MFL_ (private) flags as needed |
| 88 | int alloc_len; // the length of the allocated space (hdr+payload) |
| 89 | } rmr_mbuf_t; |
| 90 | |
| 91 | |
| 92 | typedef int rmr_whid_t; // wormhole identifier returned by rmr_wh_open(), passed to rmr_wh_send_msg() |
| 93 | |
| 94 | |
| 95 | // ---- library message specific prototypes ------------------------------------------------------------ |
| 96 | extern rmr_mbuf_t* rmr_alloc_msg( void* vctx, int size ); |
| 97 | extern rmr_mbuf_t* rmr_call( void* vctx, rmr_mbuf_t* msg ); |
| 98 | extern void rmr_close( void* vctx ); |
| 99 | extern void* rmr_init( char* proto_port, int max_msg_size, int flags ); |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 100 | extern int rmr_init_trace( void* vctx, int size ); |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 101 | extern int rmr_payload_size( rmr_mbuf_t* msg ); |
| 102 | extern rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg ); |
| 103 | extern rmr_mbuf_t* rmr_mtosend_msg( void* vctx, rmr_mbuf_t* msg, int max_to ); |
| 104 | extern rmr_mbuf_t* rmr_rcv_msg( void* vctx, rmr_mbuf_t* old_msg ); |
| 105 | extern rmr_mbuf_t* rmr_rcv_specific( void* uctx, rmr_mbuf_t* msg, char* expect, int allow2queue ); |
| 106 | extern rmr_mbuf_t* rmr_rts_msg( void* vctx, rmr_mbuf_t* msg ); |
| 107 | extern int rmr_ready( void* vctx ); |
| 108 | extern int rmr_set_rtimeout( void* vctx, int time ); |
| 109 | extern int rmr_set_stimeout( void* vctx, int time ); |
| 110 | extern int rmr_get_rcvfd( void* vctx ); // only supported with nng |
| 111 | extern rmr_mbuf_t* rmr_torcv_msg( void* vctx, rmr_mbuf_t* old_msg, int ms_to ); |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 112 | extern rmr_mbuf_t* rmr_tralloc_msg( void* context, int msize, int trsize, unsigned const char* data ); |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 113 | extern rmr_whid_t rmr_wh_open( void* vctx, char const* target ); |
| 114 | extern rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg ); |
| 115 | extern void rmr_wh_close( void* vctx, int whid ); |
| 116 | |
| 117 | |
| 118 | // ----- msg buffer operations (no context needed) ------------------------------------------------------ |
| 119 | extern int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char const* src, int len ); |
| 120 | extern void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char const* src, int len ); |
| 121 | extern int rmr_bytes2xact( rmr_mbuf_t* mbuf, unsigned char const* src, int len ); |
| 122 | extern void rmr_free_msg( rmr_mbuf_t* mbuf ); |
| 123 | extern unsigned char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest ); |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 124 | extern rmr_mbuf_t* rmr_realloc_msg( rmr_mbuf_t* mbuf, int new_tr_size ); |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 125 | extern int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char const* str ); |
| 126 | extern void rmr_str2payload( rmr_mbuf_t* mbuf, unsigned char const* str ); |
| 127 | extern void rmr_str2payload( rmr_mbuf_t* mbuf, unsigned char const* str ); |
| 128 | extern int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char const* str ); |
| 129 | |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 130 | extern int rmr_get_trlen( rmr_mbuf_t* msg ); |
| 131 | extern int rmr_get_trace( rmr_mbuf_t* msg, unsigned char* dest, int size ); |
| 132 | extern int rmr_set_trace( rmr_mbuf_t* msg, unsigned const char* data, int size ); |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 133 | |
| 134 | extern int rmr_rcv_to( void* vctx, int time ); // DEPRECATED -- replaced with set_rtimeout |
| 135 | extern int rmr_send_to( void* vctx, int time ); // DEPRECATED -- replaced with set_stimeout |
| 136 | |
| 137 | |
| 138 | // --- uta compatability defs if needed user should define UTA_COMPAT ---------------------------------- |
| 139 | #ifdef UTA_COMPAT |
E. Scott Daniels | 68c5cf1 | 2019-04-12 15:14:40 +0000 | [diff] [blame] | 140 | #pragma message( "use of UTA_COMPAT is deprecated and soon to be removed" ) |
Ashwin Sridharan | fd9cc7a | 2019-04-03 16:47:02 -0400 | [diff] [blame] | 141 | |
| 142 | #define UTA_MAX_XID RMR_MAX_XID |
| 143 | #define UTA_MAX_SID RMR_MAX_SID |
| 144 | #define UTA_MAX_SRC RMR_MAX_SRC |
| 145 | #define UTA_MAX_RCV_BYTES RMR_MAX_RCV_BYTES |
| 146 | |
| 147 | #define UTAFL_NONE RMRFL_NONE |
| 148 | #define UTAFL_AUTO_ALLOC RMRFL_AUTO_ALLOC |
| 149 | |
| 150 | #define UTA_DEF_SIZE RMRFL_AUTO_ALLOC |
| 151 | |
| 152 | #define UTA_OK RMR_OK |
| 153 | #define UTA_ERR_BADARG RMR_ERR_BADARG |
| 154 | #define UTA_ERR_NOENDPT RMR_ERR_NOENDPT |
| 155 | #define UTA_ERR_EMPTY RMR_ERR_EMPTY |
| 156 | #define UTA_ERR_NOHDR RMR_ERR_NOHDR |
| 157 | #define UTA_ERR_SENDFAILED RMR_ERR_SENDFAILED |
| 158 | #define UTA_ERR_CALLFAILED RMR_ERR_CALLFAILED |
| 159 | |
| 160 | #define uta_mbuf_t rmr_mbuf_t |
| 161 | |
| 162 | #define uta_alloc_msg rmr_alloc_msg |
| 163 | #define uta_call rmr_call |
| 164 | #define uta_free_msg rmr_free_msg |
| 165 | #define uta_init rmr_init |
| 166 | #define uta_payload_size rmr_payload_size |
| 167 | #define uta_send_msg rmr_send_msg |
| 168 | #define uta_rcv_msg rmr_rcv_msg |
| 169 | #define uta_rcv_specific rmr_rcv_specific |
| 170 | #define uta_rcv_to rmr_rcv_to |
| 171 | #define uta_rts_msg rmr_rts_msg |
| 172 | #define uta_ready rmr_ready |
| 173 | #define uta_send_to rmr_send_to |
| 174 | #endif // uta compat |
| 175 | |
| 176 | |
| 177 | #ifdef __cplusplus |
| 178 | } |
| 179 | #endif |
| 180 | |
| 181 | #endif // dup include prevention |