From 15390d7fea1b82b9cb8037ea7fd3a9cf3b00230b Mon Sep 17 00:00:00 2001 From: "E. Scott Daniels" Date: Mon, 6 May 2019 20:19:59 +0000 Subject: [PATCH] enhance(API): Add constant passthru for wrappers Change-Id: I3c417e0b74514d1f86bc1930b507f49f0b14baab Signed-off-by: E. Scott Daniels --- BUILD | 13 ++++ CMakeLists.txt | 2 +- doc/CMakeLists.txt | 1 + src/common/CMakeLists.txt | 1 + src/common/src/wrapper.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/common/src/wrapper.c diff --git a/BUILD b/BUILD index 64bd052..6f9074c 100644 --- a/BUILD +++ b/BUILD @@ -101,3 +101,16 @@ will continue to support Nanomsg for a short period of time, but new programmes should NOT use Nanomsg. +Manual Pages +By default the deb created does not include the manual pages. To +enable their creation, and subsequent inclusion in the deb, add +the following option to the cmake command: + + -DBUILD_DOC=1 + +This will cause the {X}fm text formatting package to be fetched +(github) and built at cmake time (must exist before building) +and will trigger the generation of the man pages in both postscript +and troff format. The troff pages are placed into the deb and +the postscript pages are left in the build directory for the +developer to convert to PDF, or otherwise use. diff --git a/CMakeLists.txt b/CMakeLists.txt index 365d370..73d2ebd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required( VERSION 3.5 ) set( major_version "1" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this set( minor_version "0" ) -set( patch_level "19" ) +set( patch_level "20" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) set( install_lib "lib" ) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index ddd737f..7a4c9b5 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -62,6 +62,7 @@ if( BUILD_DOC ) rmr_wh_close.3 rmr_alloc_msg.3 rmr_get_rcvfd.3 + rmr_get_meid.3 rmr_rcv_msg.3 rmr_send_msg.3 rmr_wh_open.3 diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ebccd3b..efd8480 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -22,6 +22,7 @@ add_library( common_objects OBJECT src/symtab.c src/mbuf_api.c + src/wrapper.c ) target_include_directories (common_objects PUBLIC diff --git a/src/common/src/wrapper.c b/src/common/src/wrapper.c new file mode 100644 index 0000000..b712f36 --- /dev/null +++ b/src/common/src/wrapper.c @@ -0,0 +1,155 @@ +// :vi sw=4 ts=4 noet: +/* +================================================================================== + Copyright (c) 2019 Nokia + Copyright (c) 2018-2019 AT&T Intellectual Property. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ + +/* + Mnemonic: wrapper.c + Abstract: Functions that may make life easier for wrappers written on top + of the library which don't have access to header files. + Author: E. Scott Daniels + Date: 3 May 2019 +*/ + +#include +#include +#include + +#include "../include/rmr.h" + +#define ADD_SEP 1 +#define NO_SEP 0 + +/* + Build a "name": value sequence with an optional trailing + seperator. Caller must free the buffer after use. +*/ +static char* build_ival( char* name, int val, int add_sep ) { + char wbuf[512]; + + snprintf( wbuf, sizeof( wbuf ), "\"%s\": %d%s", name, val, add_sep ? "," : "" ); + return strdup( wbuf ); +} + +/* + Builds a "name": "string" sequence with an optional trailing + separator. Caller must free resulting string. +*/ +static char* build_sval( char* name, char* val, int add_sep ) { + char wbuf[512]; + + snprintf( wbuf, sizeof( wbuf ), "\"%s\": \"%s\"%s", name, val, add_sep ? "," : "" ); + return strdup( wbuf ); +} + + +/* + Similar to strcat, bangs src onto the end of target, but UNLIKE + strcat src is freed as a convenience. Max is the max amount + that target can accept; we don't bang on if src len is + larger than max. Return is the size of src; 0 if the + target was not modified. If target is not modified, then + src is NOT released. +*/ +static int bang_on( char* target, char* src, int max ) { + int len; + int rc = 0; // return code, assume error + + if( src && target ) { + len = strlen( src ); + if( (rc = len <= max ? len : 0 ) > 0 ) { // if it fits, add it. + strcat( target, src ); + free( src ); + } + } + + return rc; +} + +/* + Returns a set of json with the constants which are set in the header. +*/ +extern char* rmr_get_consts( ) { + int remain; // bytes remaining in wbuf + int slen = 0; // length added + char wbuf[2048]; + char* phrase; + + snprintf( wbuf, sizeof( wbuf ), "{ " ); + remain = sizeof( wbuf ) - strlen( wbuf ) -10; // reserve some bytes allowing us to close the json + + phrase = build_ival( "RMR_MAX_XID", RMR_MAX_XID, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_MAX_SID", RMR_MAX_SID, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_MAX_MEID", RMR_MAX_MEID, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_MAX_SRC", RMR_MAX_SRC, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_MAX_RCV_BYTES", RMR_MAX_RCV_BYTES, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + + phrase = build_ival( "RMRFL_NONE", RMRFL_NONE, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMRFL_AUTO_ALLOC", RMRFL_AUTO_ALLOC, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + + phrase = build_ival( "RMR_DEF_SIZE", RMR_DEF_SIZE, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + + phrase = build_ival( "RMR_VOID_MSGTYPE", RMR_VOID_MSGTYPE, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_VOID_SUBID", RMR_VOID_SUBID , ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + + phrase = build_ival( "RMR_OK", RMR_OK, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_BADARG", RMR_ERR_BADARG, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_NOENDPT", RMR_ERR_NOENDPT, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_EMPTY", RMR_ERR_EMPTY, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_NOHDR", RMR_ERR_NOHDR, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_SENDFAILED", RMR_ERR_SENDFAILED, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_CALLFAILED", RMR_ERR_CALLFAILED, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_NOWHOPEN", RMR_ERR_NOWHOPEN, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_WHID", RMR_ERR_WHID, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_OVERFLOW", RMR_ERR_OVERFLOW, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_RETRY", RMR_ERR_RETRY, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_RCVFAILED", RMR_ERR_RCVFAILED, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_TIMEOUT", RMR_ERR_TIMEOUT, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_UNSET", RMR_ERR_UNSET, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_TRUNC", RMR_ERR_TRUNC, ADD_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + phrase = build_ival( "RMR_ERR_INITFAILED", RMR_ERR_INITFAILED, NO_SEP ); + remain -= bang_on( wbuf, phrase, remain ); + + strcat( wbuf, " }" ); + return strdup( wbuf ); // chop unused space and return +} -- 2.16.6