api: deprecate vl_msg_api_set_handlers 88/36188/9
authorDamjan Marion <damarion@cisco.com>
Fri, 20 May 2022 18:06:01 +0000 (20:06 +0200)
committerOle Tr�an <otroan@employees.org>
Thu, 29 Sep 2022 15:36:00 +0000 (15:36 +0000)
Type: refactor

Change-Id: I7b7ca9ec62cb70243c5b7e87968eab1338d67ec8
Signed-off-by: Damjan Marion <damarion@cisco.com>
12 files changed:
src/plugins/hs_apps/sapi/vpp_echo_bapi.c
src/plugins/tracedump/tracedump_test.c
src/tools/vppapigen/vppapigen_c.py
src/vat/api_format.c
src/vcl/vcl_bapi.c
src/vlibapi/api_common.h
src/vlibapi/api_shared.c
src/vlibmemory/memclnt_api.c
src/vlibmemory/memory_client.c
src/vlibmemory/socket_api.c
src/vlibmemory/socket_client.c
src/vnet/srmpls/sr_mpls_api.c

index 0652b86..868cc3a 100644 (file)
@@ -585,11 +585,18 @@ echo_api_hookup (echo_main_t * em)
     return;
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
-                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
-                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
-                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
-                          vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = REPLY_MSG_ID_BASE + VL_API_##N,                                     \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 1,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_quic_echo_msg;
 #undef _
 }
index f2bb63e..1a2c818 100644 (file)
@@ -248,12 +248,18 @@ api_trace_clear_capture (vat_main_t * vam)
 void
 manual_setup_message_id_table (vat_main_t * vam)
 {
-  vl_msg_api_set_handlers (
-    VL_API_TRACE_DETAILS + tracedump_test_main.msg_id_base, "trace_details",
-    vl_api_trace_details_t_handler, vl_api_trace_details_t_endian,
-    vl_api_trace_details_t_format, sizeof (vl_api_trace_details_t), 1,
-    vl_api_trace_details_t_tojson, vl_api_trace_details_t_fromjson,
-    vl_api_trace_details_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){
+    .id = VL_API_TRACE_DETAILS + tracedump_test_main.msg_id_base,
+    .name = "trace_details",
+    .handler = vl_api_trace_details_t_handler,
+    .endian = vl_api_trace_details_t_endian,
+    .format_fn = vl_api_trace_details_t_format,
+    .size = sizeof (vl_api_trace_details_t),
+    .traced = 1,
+    .tojson = vl_api_trace_details_t_tojson,
+    .fromjson = vl_api_trace_details_t_fromjson,
+    .calc_size = vl_api_trace_details_t_calc_size,
+  });
 }
 
 #define VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE manual_setup_message_id_table
index b9f9e07..5ca2ed5 100644 (file)
@@ -1669,17 +1669,18 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
     write("setup_message_id_table (vat_main_t * vam, u16 msg_id_base) {\n")
     for s in services:
         write(
-            "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
-            '                           "{n}",\n'
-            "                           vl_api_{n}_t_handler, "
-            "                           vl_api_{n}_t_endian, "
-            "                           vl_api_{n}_t_format,\n"
-            "                           sizeof(vl_api_{n}_t), 1,\n"
-            "                           vl_api_{n}_t_tojson,\n"
-            "                           vl_api_{n}_t_fromjson,\n"
-            "                           vl_api_{n}_t_calc_size);\n".format(
-                n=s.reply, ID=s.reply.upper()
-            )
+            "   vl_msg_api_config (&(vl_msg_api_msg_config_t){{\n"
+            "    .id = VL_API_{ID} + msg_id_base,\n"
+            '    .name = "{n}",\n'
+            "    .handler = vl_api_{n}_t_handler,\n"
+            "    .endian = vl_api_{n}_t_endian,\n"
+            "    .format_fn = vl_api_{n}_t_format,\n"
+            "    .size = sizeof(vl_api_{n}_t),\n"
+            "    .traced = 1,\n"
+            "    .tojson = vl_api_{n}_t_tojson,\n"
+            "    .fromjson = vl_api_{n}_t_fromjson,\n"
+            "    .calc_size = vl_api_{n}_t_calc_size,\n"
+            "   }});".format(n=s.reply, ID=s.reply.upper())
         )
         write(
             '   hash_set_mem (vam->function_by_name, "{n}", api_{n});\n'.format(
@@ -1698,17 +1699,18 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
         # Events
         for e in s.events:
             write(
-                "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
-                '                          "{n}",\n'
-                "                           vl_api_{n}_t_handler, "
-                "                           vl_api_{n}_t_endian, "
-                "                           vl_api_{n}_t_format,\n"
-                "                           sizeof(vl_api_{n}_t), 1,\n"
-                "                           vl_api_{n}_t_tojson,\n"
-                "                           vl_api_{n}_t_fromjson,\n"
-                "                           vl_api_{n}_t_calc_size);\n".format(
-                    n=e, ID=e.upper()
-                )
+                "   vl_msg_api_config (&(vl_msg_api_msg_config_t){{\n"
+                "    .id = VL_API_{ID} + msg_id_base,\n"
+                '    .name = "{n}",\n'
+                "    .handler = vl_api_{n}_t_handler,\n"
+                "    .endian = vl_api_{n}_t_endian,\n"
+                "    .format_fn = vl_api_{n}_t_format,\n"
+                "    .size = sizeof(vl_api_{n}_t),\n"
+                "    .traced = 1,\n"
+                "    .tojson = vl_api_{n}_t_tojson,\n"
+                "    .fromjson = vl_api_{n}_t_fromjson,\n"
+                "    .calc_size = vl_api_{n}_t_calc_size,\n"
+                "   }});".format(n=e, ID=e.upper())
             )
 
     write("}\n")
index 72ce34f..45ba025 100644 (file)
@@ -2733,10 +2733,18 @@ void
 vat_api_hookup (vat_main_t * vam)
 {
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N + 1, #n, vl_api_##n##_t_handler_uni, vl_api_##n##_t_endian,    \
-    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_tojson, \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N + 1,                                                     \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler_uni,                                    \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 1,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_vpe_api_reply_msg;
 #if VPP_API_TEST_BUILTIN == 0
   foreach_standalone_reply_msg;
index 7e5203d..afe8824 100644 (file)
@@ -302,11 +302,18 @@ vcl_bapi_hookup (void)
     return;
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
-                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
-                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
-                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
-                          vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = REPLY_MSG_ID_BASE + VL_API_##N,                                     \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 1,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_sock_msg;
 #undef _
 }
index 37ffb58..d644d93 100644 (file)
@@ -171,10 +171,6 @@ void vl_msg_api_trace_only (void *the_msg, uword msg_len);
 void vl_msg_api_cleanup_handler (void *the_msg);
 void vl_msg_api_replay_handler (void *the_msg);
 void vl_msg_api_socket_handler (void *the_msg, uword msg_len);
-void vl_msg_api_set_handlers (int msg_id, char *msg_name, void *handler,
-                             void *endian, format_function_t *format,
-                             int msg_size, int traced, void *tojson,
-                             void *fromjson, void *validate_size);
 void vl_msg_api_clean_handlers (int msg_id);
 void vl_msg_api_config (vl_msg_api_msg_config_t *);
 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
index 0a98348..bf03751 100644 (file)
@@ -784,36 +784,6 @@ vl_msg_api_config (vl_msg_api_msg_config_t * c)
   hash_set_mem (am->msg_id_by_name, c->name, c->id);
 }
 
-/*
- * vl_msg_api_set_handlers
- * preserve the old API for a while
- */
-void
-vl_msg_api_set_handlers (int id, char *name, void *handler, void *endian,
-                        format_function_t *format, int size, int traced,
-                        void *tojson, void *fromjson, void *calc_size)
-{
-  vl_msg_api_msg_config_t cfg;
-  vl_msg_api_msg_config_t *c = &cfg;
-
-  clib_memset (c, 0, sizeof (*c));
-
-  c->id = id;
-  c->name = name;
-  c->handler = handler;
-  c->endian = endian;
-  c->format_fn = format;
-  c->traced = traced;
-  c->replay = 1;
-  c->message_bounce = 0;
-  c->is_mp_safe = 0;
-  c->is_autoendian = 0;
-  c->tojson = tojson;
-  c->fromjson = fromjson;
-  c->calc_size = calc_size;
-  vl_msg_api_config (c);
-}
-
 void
 vl_msg_api_clean_handlers (int msg_id)
 {
index 0717d81..29858dd 100644 (file)
@@ -707,22 +707,36 @@ rpc_api_hookup (vlib_main_t *vm)
 {
   api_main_t *am = vlibapi_get_main ();
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, 0, vl_api_##n##_t_format,         \
-    sizeof (vl_api_##n##_t), 0 /* do not trace */, vl_api_##n##_t_tojson,     \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 0,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_rpc_api_msg;
 #undef _
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, 0, vl_api_##n##_t_format,         \
-    sizeof (vl_api_##n##_t), 1 /* do trace */, vl_api_##n##_t_tojson,         \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
-  foreach_plugin_trace_msg;
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 1,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
+  foreach_plugin_trace_msg
 #undef _
 
-  vl_api_allow_msg_replay (am, VL_API_TRACE_PLUGIN_MSG_IDS, 0);
+    vl_api_allow_msg_replay (am, VL_API_TRACE_PLUGIN_MSG_IDS, 0);
 
   /* No reason to halt the parade to create a trace record... */
   vl_api_set_msg_thread_safe (am, VL_API_TRACE_PLUGIN_MSG_IDS, 1);
index 738c4e5..d2323de 100644 (file)
@@ -366,10 +366,18 @@ vl_client_install_client_message_handlers (void)
 {
   api_main_t *am = vlibapi_get_main ();
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
-    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 0, vl_api_##n##_t_tojson, \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);                       \
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 0,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });                                                                         \
   am->msg_data[VL_API_##N].replay_allowed = 0;
   foreach_api_msg;
 #undef _
index 106fcb2..6559f73 100644 (file)
@@ -796,10 +796,18 @@ vl_sock_api_init (vlib_main_t * vm)
     return 0;
 
 #define _(N, n, t)                                                            \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
-    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), t, vl_api_##n##_t_tojson, \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);                       \
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = t,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });                                                                         \
   am->msg_data[VL_API_##N].replay_allowed = 0;
   foreach_vlib_api_msg;
 #undef _
index 1eccb73..82c6bfe 100644 (file)
@@ -431,10 +431,18 @@ vl_sock_client_install_message_handlers (void)
 {
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
-    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 0, vl_api_##n##_t_tojson, \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 0,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_sock_client_api_msg;
 #undef _
 }
index 8642db9..920856a 100644 (file)
@@ -193,11 +193,18 @@ sr_mpls_api_hookup (vlib_main_t * vm)
   vec_free (name);
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
-                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
-                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
-                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
-                          vl_api_##n##_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = REPLY_MSG_ID_BASE + VL_API_##N,                                     \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = 1,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });
   foreach_vpe_api_msg;
 #undef _
 
@@ -205,23 +212,34 @@ sr_mpls_api_hookup (vlib_main_t * vm)
    * Manually register the sr policy add msg, so we trace enough bytes
    * to capture a typical segment list
    */
-  vl_msg_api_set_handlers (
-    REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_ADD, "sr_mpls_policy_add",
-    vl_api_sr_mpls_policy_add_t_handler, vl_api_sr_mpls_policy_add_t_endian,
-    vl_api_sr_mpls_policy_add_t_format, 256, 1,
-    vl_api_sr_mpls_policy_add_t_tojson, vl_api_sr_mpls_policy_add_t_fromjson,
-    vl_api_sr_mpls_policy_add_t_calc_size);
-
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){
+    .id = REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_ADD,
+    .name = "sr_mpls_policy_add",
+    .handler = vl_api_sr_mpls_policy_add_t_handler,
+    .endian = vl_api_sr_mpls_policy_add_t_endian,
+    .format_fn = vl_api_sr_mpls_policy_add_t_format,
+    .size = 256,
+    .traced = 1,
+    .tojson = vl_api_sr_mpls_policy_add_t_tojson,
+    .fromjson = vl_api_sr_mpls_policy_add_t_fromjson,
+    .calc_size = vl_api_sr_mpls_policy_add_t_calc_size,
+  });
   /*
    * Manually register the sr policy mod msg, so we trace enough bytes
    * to capture a typical segment list
    */
-  vl_msg_api_set_handlers (
-    REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_MOD, "sr_mpls_policy_mod",
-    vl_api_sr_mpls_policy_mod_t_handler, vl_api_sr_mpls_policy_mod_t_endian,
-    vl_api_sr_mpls_policy_mod_t_format, 256, 1,
-    vl_api_sr_mpls_policy_mod_t_tojson, vl_api_sr_mpls_policy_mod_t_fromjson,
-    vl_api_sr_mpls_policy_mod_t_calc_size);
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){
+    .id = REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_MOD,
+    .name = "sr_mpls_policy_mod",
+    .handler = vl_api_sr_mpls_policy_mod_t_handler,
+    .endian = vl_api_sr_mpls_policy_mod_t_endian,
+    .format_fn = vl_api_sr_mpls_policy_mod_t_format,
+    .size = 256,
+    .traced = 1,
+    .tojson = vl_api_sr_mpls_policy_mod_t_tojson,
+    .fromjson = vl_api_sr_mpls_policy_mod_t_fromjson,
+    .calc_size = vl_api_sr_mpls_policy_mod_t_calc_size,
+  });
 
   /*
    * Set up the (msg_name, crc, message-id) table