api: autogenerate api trace print/endian
[vpp.git] / src / vlibapi / api_shared.c
index 18eb83b..1e7f5c4 100644 (file)
@@ -189,6 +189,29 @@ vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which)
   return 0;
 }
 
+u8 *
+vl_api_serialize_message_table (api_main_t * am, u8 * vector)
+{
+  serialize_main_t _sm, *sm = &_sm;
+  hash_pair_t *hp;
+  u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
+
+  serialize_open_vector (sm, vector);
+
+  /* serialize the count */
+  serialize_integer (sm, nmsg, sizeof (u32));
+
+  /* *INDENT-OFF* */
+  hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
+  ({
+    serialize_likely_small_unsigned_integer (sm, hp->value[0]);
+    serialize_cstring (sm, (char *) hp->key);
+  }));
+  /* *INDENT-ON* */
+
+  return serialize_close_vector (sm);
+}
+
 int
 vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
 {
@@ -223,15 +246,23 @@ vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
     }
 
   /* Write the file header */
-  fh.nitems = vec_len (tp->traces);
-  fh.endian = tp->endian;
   fh.wrapped = tp->wrapped;
+  fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces));
+  u8 *m = vl_api_serialize_message_table (am, 0);
+  fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m));
 
   if (fwrite (&fh, sizeof (fh), 1, fp) != 1)
     {
       return (-10);
     }
 
+  /* Write the message table */
+  if (fwrite (m, vec_len (m), 1, fp) != 1)
+    {
+      return (-14);
+    }
+  vec_free (m);
+
   /* No-wrap case */
   if (tp->wrapped == 0)
     {
@@ -480,10 +511,15 @@ msg_handler_internal (api_main_t * am,
       } *ed;
       ed = ELOG_DATA (am->elog_main, e);
       if (id < vec_len (am->msg_names))
-       ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
+       {
+         ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
+         ed->barrier = !am->is_mp_safe[id];
+       }
       else
-       ed->c = elog_string (am->elog_main, "BOGUS");
-      ed->barrier = !am->is_mp_safe[id];
+       {
+         ed->c = elog_string (am->elog_main, "BOGUS");
+         ed->barrier = 0;
+       }
     }
 }
 
@@ -1022,7 +1058,8 @@ vl_msg_pop_heap (void *oldheap)
 int
 vl_api_to_api_string (u32 len, const char *buf, vl_api_string_t * str)
 {
-  clib_memcpy_fast (str->buf, buf, len);
+  if (len)
+    clib_memcpy_fast (str->buf, buf, len);
   str->length = htonl (len);
   return len + sizeof (u32);
 }
@@ -1049,6 +1086,14 @@ vl_api_string_len (vl_api_string_t * astr)
   return clib_net_to_host_u32 (astr->length);
 }
 
+u8 *
+vl_api_format_string (u8 * s, va_list * args)
+{
+  vl_api_string_t *a = va_arg (*args, vl_api_string_t *);
+  vec_add (s, a->buf, clib_net_to_host_u32 (a->length));
+  return s;
+}
+
 /*
  * Returns a new vector. Remember to free it after use.
  */