diff options
author | Ole Troan <ot@cisco.com> | 2019-09-25 18:20:20 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2019-09-27 12:29:05 +0000 |
commit | 51e70b6f19a66351bff7fe2e22a8dfce82b64ecd (patch) | |
tree | a257d77ee8e323222035d995b51f63e2ad75948e /src/plugins/builtinurl/builtinurl.c | |
parent | 1bc96680c45237e6ed519e4be36738139a94af2d (diff) |
builtinurl: remove api boilerplate
Type: refactor
Change-Id: Iaf728642e489acfd63e1da88aa8daa44ceca21e9
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/plugins/builtinurl/builtinurl.c')
-rw-r--r-- | src/plugins/builtinurl/builtinurl.c | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/src/plugins/builtinurl/builtinurl.c b/src/plugins/builtinurl/builtinurl.c index 796035ebce5..8782906a8d2 100644 --- a/src/plugins/builtinurl/builtinurl.c +++ b/src/plugins/builtinurl/builtinurl.c @@ -25,39 +25,14 @@ #include <stdbool.h> /* define message IDs */ -#include <builtinurl/builtinurl_msg_enum.h> - -/* define message structures */ -#define vl_typedefs -#include <builtinurl/builtinurl_all_api_h.h> -#undef vl_typedefs - -/* define generated endian-swappers */ -#define vl_endianfun -#include <builtinurl/builtinurl_all_api_h.h> -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include <builtinurl/builtinurl_all_api_h.h> -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include <builtinurl/builtinurl_all_api_h.h> -#undef vl_api_version +#include <builtinurl/builtinurl.api_enum.h> +#include <builtinurl/builtinurl.api_types.h> #define REPLY_MSG_ID_BASE bmp->msg_id_base #include <vlibapi/api_helper_macros.h> builtinurl_main_t builtinurl_main; -/* List of message types that this plugin understands */ - -#define foreach_builtinurl_plugin_api_msg \ -_(BUILTINURL_ENABLE, builtinurl_enable) - /* Action function shared between message handler and debug CLI */ int @@ -132,61 +107,19 @@ static void vl_api_builtinurl_enable_t_handler REPLY_MACRO (VL_API_BUILTINURL_ENABLE_REPLY); } -/* Set up the API message handling tables */ -static clib_error_t * -builtinurl_plugin_api_hookup (vlib_main_t * vm) -{ - builtinurl_main_t *bmp = &builtinurl_main; -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + bmp->msg_id_base), \ - #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_builtinurl_plugin_api_msg; -#undef _ - - return 0; -} - -#define vl_msg_name_crc_list -#include <builtinurl/builtinurl_all_api_h.h> -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (builtinurl_main_t * bmp, api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + bmp->msg_id_base); - foreach_vl_msg_name_crc_builtinurl; -#undef _ -} - +#include <builtinurl/builtinurl.api.c> static clib_error_t * builtinurl_init (vlib_main_t * vm) { builtinurl_main_t *bmp = &builtinurl_main; - clib_error_t *error = 0; - u8 *name; bmp->vlib_main = vm; bmp->vnet_main = vnet_get_main (); - name = format (0, "builtinurl_%08x%c", api_version, 0); - /* Ask for a correctly-sized block of API message decode slots */ - bmp->msg_id_base = vl_msg_api_get_msg_ids - ((char *) name, VL_MSG_FIRST_AVAILABLE); - - error = builtinurl_plugin_api_hookup (vm); - - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (bmp, &api_main); + bmp->msg_id_base = setup_message_id_table (); - vec_free (name); - - return error; + return 0; } VLIB_INIT_FUNCTION (builtinurl_init); |