Add macro for sending large data structures to API clients 08/3408/1
authorFlorin Coras <fcoras@cisco.com>
Thu, 13 Oct 2016 14:19:40 +0000 (16:19 +0200)
committerFlorin Coras <fcoras@cisco.com>
Thu, 13 Oct 2016 22:33:59 +0000 (00:33 +0200)
Change-Id: I1c4ec4dd02ce5a16e33aa0908a606496ad0d64cc
Signed-off-by: Florin Coras <fcoras@cisco.com>
vpp/vpp-api/api.c

index 3840b82..ca56ab2 100644 (file)
@@ -170,13 +170,29 @@ do {                                                            \
 #define REPLY_MACRO3(t, n, body)                               \
 do {                                                            \
     unix_shared_memory_queue_t * q;                             \
-    u8 is_error = 0;                                            \
     rv = vl_msg_api_pd_handler (mp, rv);                        \
     q = vl_api_client_index_to_input_queue (mp->client_index);  \
     if (!q)                                                     \
         return;                                                 \
                                                                 \
     rmp = vl_msg_api_alloc (sizeof (*rmp) + n);                 \
+    rmp->_vl_msg_id = ntohs((t));                               \
+    rmp->context = mp->context;                                 \
+    rmp->retval = ntohl(rv);                                    \
+    do {body;} while (0);                                       \
+    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
+} while(0);
+
+#define REPLY_MACRO4(t, n, body)                                \
+do {                                                            \
+    unix_shared_memory_queue_t * q;                             \
+    u8 is_error = 0;                                            \
+    rv = vl_msg_api_pd_handler (mp, rv);                        \
+    q = vl_api_client_index_to_input_queue (mp->client_index);  \
+    if (!q)                                                     \
+        return;                                                 \
+                                                                \
+    rmp = vl_msg_api_alloc_or_null (sizeof (*rmp) + n);         \
     if (!rmp)                                                   \
       {                                                         \
         /* if there isn't enough memory, try to allocate */     \
@@ -189,7 +205,6 @@ do {                                                            \
         rv = VNET_API_ERROR_TABLE_TOO_BIG;                      \
         is_error = 1;                                           \
       }                                                         \
-                                                                \
     rmp->_vl_msg_id = ntohs((t));                               \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
@@ -6093,7 +6108,7 @@ vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
   size = vec_len (adjs) * sizeof (a);
 
   /* *INDENT-OFF* */
-  REPLY_MACRO3 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
+  REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
   {
     rmp->count = clib_host_to_net_u32 (vec_len (adjs));
     lisp_adjacency_copy (rmp->adjacencies, adjs);