From 7ff64fb97541c769ba423e53166d80b9eef25279 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Wed, 2 Oct 2019 17:00:30 +0200 Subject: oddbuf: remove api boilerplate Type: refactor Change-Id: Ic4922da46bf941249dd74b1a8bc6a98c62c099b7 Signed-off-by: Ole Troan --- src/plugins/oddbuf/oddbuf.c | 74 +++------------------------------------------ 1 file changed, 4 insertions(+), 70 deletions(-) (limited to 'src/plugins/oddbuf/oddbuf.c') diff --git a/src/plugins/oddbuf/oddbuf.c b/src/plugins/oddbuf/oddbuf.c index 9b95fcc8a85..8277836aeb8 100644 --- a/src/plugins/oddbuf/oddbuf.c +++ b/src/plugins/oddbuf/oddbuf.c @@ -25,39 +25,14 @@ #include /* define message IDs */ -#include - -/* define message structures */ -#define vl_typedefs -#include -#undef vl_typedefs - -/* define generated endian-swappers */ -#define vl_endianfun -#include -#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 -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version +#include +#include #define REPLY_MSG_ID_BASE omp->msg_id_base #include oddbuf_main_t oddbuf_main; -/* List of message types that this plugin understands */ - -#define foreach_oddbuf_plugin_api_msg \ -_(ODDBUF_ENABLE_DISABLE, oddbuf_enable_disable) - /* Action function shared between message handler and debug CLI */ int @@ -159,65 +134,24 @@ static void vl_api_oddbuf_enable_disable_t_handler REPLY_MACRO (VL_API_ODDBUF_ENABLE_DISABLE_REPLY); } -/* Set up the API message handling tables */ -static clib_error_t * -oddbuf_plugin_api_hookup (vlib_main_t * vm) -{ - oddbuf_main_t *omp = &oddbuf_main; -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + omp->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_oddbuf_plugin_api_msg; -#undef _ - - return 0; -} - -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (oddbuf_main_t * omp, api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + omp->msg_id_base); - foreach_vl_msg_name_crc_oddbuf; -#undef _ -} - +#include static clib_error_t * oddbuf_init (vlib_main_t * vm) { oddbuf_main_t *om = &oddbuf_main; clib_error_t *error = 0; - u8 *name; om->vlib_main = vm; om->vnet_main = vnet_get_main (); - name = format (0, "oddbuf_%08x%c", api_version, 0); - /* Ask for a correctly-sized block of API message decode slots */ - om->msg_id_base = vl_msg_api_get_msg_ids - ((char *) name, VL_MSG_FIRST_AVAILABLE); - - error = oddbuf_plugin_api_hookup (vm); - - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (om, &api_main); + om->msg_id_base = setup_message_id_table (); /* Basic setup */ om->n_to_copy = 1; om->second_chunk_offset = 1; om->first_chunk_offset = 0; - vec_free (name); - return error; } -- cgit 1.2.3-korg