api: refactor api data storage
[vpp.git] / src / vlibapi / api_common.h
index 491ecb8..66a547f 100644 (file)
@@ -81,14 +81,6 @@ typedef struct vl_api_registration_
 
 #define VL_API_INVALID_FI ((u32)~0)
 
-/** Trace configuration for a single message */
-typedef struct
-{
-  int size;                    /**< for sanity checking */
-  int trace_enable;            /**< trace this message  */
-  int replay_enable;           /**< This message can be replayed  */
-} trace_cfg_t;
-
 /**
  * API trace state
  */
@@ -136,11 +128,11 @@ typedef struct
   void *fromjson;              /**< JSON to binary convert function */
   void *calc_size;             /**< message size calculation */
   int size;                    /**< message size  */
-  int traced;                  /**< is this message to be traced?  */
-  int replay;                  /**< is this message to be replayed?  */
-  int message_bounce;          /**< do not free message after processing */
-  int is_mp_safe;              /**< worker thread barrier required?  */
-  int is_autoendian;           /**< endian conversion required?  */
+  int traced : 1;              /**< is this message to be traced?  */
+  int replay : 1;              /**< is this message to be replayed?  */
+  int message_bounce : 1;      /**< do not free message after processing */
+  int is_mp_safe : 1;          /**< worker thread barrier required?  */
+  int is_autoendian : 1;       /**< endian conversion required?  */
 } vl_msg_api_msg_config_t;
 
 /** Message header structure */
@@ -231,47 +223,54 @@ typedef struct
   char name[64];
 } api_version_t;
 
-/** API main structure, used by both vpp and binary API clients */
-typedef struct api_main_t
+typedef struct
 {
   /** Message handler vector  */
-  void (**msg_handlers) (void *);
+  void (*handler) (void *);
 
   /** non-default message cleanup handler vector */
-  void (**msg_cleanup_handlers) (void *);
+  void (*cleanup_handler) (void *);
+
+  /** Message name vector */
+  const char *name;
+
+  /** Message convert function vector */
+  cJSON *(*tojson_handler) (void *);
+
+  /** Message convert function vector */
+  void *(*fromjson_handler) (cJSON *, int *);
 
   /** Message endian handler vector */
-  void (**msg_endian_handlers) (void *);
+  void (*endian_handler) (void *);
 
   /** Message print function vector */
-  void (**msg_print_handlers) (void *, void *);
+  void (*print_handler) (void *, void *);
 
   /** Message print function vector in JSON */
-  void (**msg_print_json_handlers) (void *, void *);
-
-  /** Message convert function vector */
-  cJSON *(**msg_tojson_handlers) (void *);
-
-  /** Message convert function vector */
-  void *(**msg_fromjson_handlers) (cJSON *, int *);
+  void (*print_json_handler) (void *, void *);
 
   /** Message calc size function vector */
-  uword (**msg_calc_size_funcs) (void *);
+  uword (*calc_size_func) (void *);
 
-  /** Message name vector */
-  const char **msg_names;
+  /** trace size for sanity checking */
+  int trace_size;
 
-  /** API message ID by name hash table */
-  uword *msg_id_by_name;
+  /** Flags */
+  u8 bounce : 1;        /**> Don't automatically free message buffer vetor */
+  u8 is_mp_safe : 1;    /**< Message is mp safe vector */
+  u8 is_autoendian : 1;         /**< Message requires us to do endian conversion */
+  u8 trace_enable : 1;  /**< trace this message  */
+  u8 replay_allowed : 1; /**< This message can be replayed  */
 
-  /** Don't automatically free message buffer vetor */
-  u8 *message_bounce;
+} vl_api_msg_data_t;
 
-  /** Message is mp safe vector */
-  u8 *is_mp_safe;
+/** API main structure, used by both vpp and binary API clients */
+typedef struct api_main_t
+{
+  vl_api_msg_data_t *msg_data;
 
-  /** Message requires us to do endian conversion */
-  u8 *is_autoendian;
+  /** API message ID by name hash table */
+  uword *msg_id_by_name;
 
   /** Allocator ring vectors (in shared memory) */
   struct ring_alloc_ *arings;
@@ -294,9 +293,6 @@ typedef struct api_main_t
   /** Print every received message */
   int msg_print_flag;
 
-  /** Current trace configuration */
-  trace_cfg_t *api_trace_cfg;
-
   /** Current process PID */
   int our_pid;
 
@@ -411,6 +407,14 @@ vlibapi_get_main (void)
   return my_api_main;
 }
 
+always_inline vl_api_msg_data_t *
+vl_api_get_msg_data (api_main_t *am, u32 msg_id)
+{
+  if (msg_id >= vec_len (am->msg_data))
+    return 0;
+  return am->msg_data + msg_id;
+}
+
 always_inline void
 vlibapi_set_main (api_main_t * am)
 {