#include <string.h>
#include <stdbool.h>
#include <vppinfra/types.h>
+#include <vapi/vapi_common.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
/**
* @file vapi.h
* process). It's not recommended to mix the higher and lower level APIs. Due
* to version issues, the higher-level APIs are not part of the shared library.
*/
-
-typedef enum
-{
- VAPI_OK = 0, /**< success */
- VAPI_EINVAL, /**< invalid value encountered */
- VAPI_EAGAIN, /**< operation would block */
- VAPI_ENOTSUP, /**< operation not supported */
- VAPI_ENOMEM, /**< out of memory */
- VAPI_ENORESP, /**< no response to request */
- VAPI_EMAP_FAIL, /**< failure while mapping api */
- VAPI_ECON_FAIL, /**< failure while connecting to vpp */
- VAPI_EINCOMPATIBLE, /**< fundamental incompatibility while connecting to vpp
- (control ping/control ping reply mismatch) */
- VAPI_MUTEX_FAILURE, /**< failure manipulating internal mutex(es) */
- VAPI_EUSER, /**< user error used for breaking dispatch,
- never used by VAPI */
-} vapi_error_e;
-
-typedef enum
-{
- VAPI_MODE_BLOCKING = 1, /**< operations block until response received */
- VAPI_MODE_NONBLOCKING = 2, /**< operations never block */
-} vapi_mode_e;
-
-typedef enum
-{
- VAPI_WAIT_FOR_READ, /**< wait until a message can be read */
- VAPI_WAIT_FOR_WRITE, /**< wait until a message can be written */
- VAPI_WAIT_FOR_READ_WRITE, /**< wait until a read or write can be done */
-} vapi_wait_mode_e;
-
-typedef int vapi_msg_id_t;
-typedef struct vapi_ctx_s *vapi_ctx_t;
+ typedef struct vapi_ctx_s *vapi_ctx_t;
/**
* @brief allocate vapi message of given size
*
* @return pointer to message or NULL if out of memory
*/
-void *vapi_msg_alloc (vapi_ctx_t ctx, size_t size);
+ void *vapi_msg_alloc (vapi_ctx_t ctx, size_t size);
/**
* @brief free a vapi message
* @param ctx opaque vapi context
* @param msg message to be freed
*/
-void vapi_msg_free (vapi_ctx_t ctx, void *msg);
+ void vapi_msg_free (vapi_ctx_t ctx, void *msg);
/**
* @brief allocate vapi context
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_ctx_alloc (vapi_ctx_t * result);
+ vapi_error_e vapi_ctx_alloc (vapi_ctx_t * result);
/**
* @brief free vapi context
*/
-void vapi_ctx_free (vapi_ctx_t ctx);
+ void vapi_ctx_free (vapi_ctx_t ctx);
/**
* @brief check if message identified by it's message id is known by the vpp to
* which the connection is open
*/
-bool vapi_is_msg_available (vapi_ctx_t ctx, vapi_msg_id_t type);
+ bool vapi_is_msg_available (vapi_ctx_t ctx, vapi_msg_id_t type);
/**
* @brief connect to vpp
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_connect (vapi_ctx_t ctx, const char *name,
- const char *chroot_prefix,
- int max_outstanding_requests,
- int response_queue_size, vapi_mode_e mode);
+ vapi_error_e vapi_connect (vapi_ctx_t ctx, const char *name,
+ const char *chroot_prefix,
+ int max_outstanding_requests,
+ int response_queue_size, vapi_mode_e mode);
/**
* @brief disconnect from vpp
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_disconnect (vapi_ctx_t ctx);
+ vapi_error_e vapi_disconnect (vapi_ctx_t ctx);
/**
* @brief get event file descriptor
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_get_fd (vapi_ctx_t ctx, int *fd);
+ vapi_error_e vapi_get_fd (vapi_ctx_t ctx, int *fd);
/**
* @brief low-level api for sending messages to vpp
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_send (vapi_ctx_t ctx, void *msg);
+ vapi_error_e vapi_send (vapi_ctx_t ctx, void *msg);
/**
* @brief low-level api for atomically sending two messages to vpp - either
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_send2 (vapi_ctx_t ctx, void *msg1, void *msg2);
+ vapi_error_e vapi_send2 (vapi_ctx_t ctx, void *msg1, void *msg2);
/**
* @brief low-level api for reading messages from vpp
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_recv (vapi_ctx_t ctx, void **msg, size_t * msg_size);
+ vapi_error_e vapi_recv (vapi_ctx_t ctx, void **msg, size_t * msg_size);
/**
* @brief wait for connection to become readable or writable
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_wait (vapi_ctx_t ctx, vapi_wait_mode_e mode);
+ vapi_error_e vapi_wait (vapi_ctx_t ctx, vapi_wait_mode_e mode);
/**
* @brief pick next message sent by vpp and call the appropriate callback
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_dispatch_one (vapi_ctx_t ctx);
+ vapi_error_e vapi_dispatch_one (vapi_ctx_t ctx);
/**
* @brief loop vapi_dispatch_one until responses to all currently outstanding
*
* @return VAPI_OK on success, other error code on error
*/
-vapi_error_e vapi_dispatch (vapi_ctx_t ctx);
+ vapi_error_e vapi_dispatch (vapi_ctx_t ctx);
/** generic vapi event callback */
-typedef vapi_error_e (*vapi_event_cb) (vapi_ctx_t ctx, void *callback_ctx,
- void *payload);
+ typedef vapi_error_e (*vapi_event_cb) (vapi_ctx_t ctx, void *callback_ctx,
+ void *payload);
/**
* @brief set event callback to call when message with given id is dispatched
* @param callback callback
* @param callback_ctx context pointer stored and passed to callback
*/
-void vapi_set_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id,
- vapi_event_cb callback, void *callback_ctx);
+ void vapi_set_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id,
+ vapi_event_cb callback, void *callback_ctx);
/**
* @brief clear event callback for given message id
* @param ctx opaque vapi context
* @param id message id
*/
-void vapi_clear_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id);
+ void vapi_clear_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id);
/** generic vapi event callback */
-typedef vapi_error_e (*vapi_generic_event_cb) (vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_msg_id_t id, void *msg);
+ typedef vapi_error_e (*vapi_generic_event_cb) (vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_msg_id_t id, void *msg);
/**
* @brief set generic event callback
*
* @param callback callback
* @param callback_ctx context pointer stored and passed to callback
*/
-void vapi_set_generic_event_cb (vapi_ctx_t ctx,
- vapi_generic_event_cb callback,
- void *callback_ctx);
+ void vapi_set_generic_event_cb (vapi_ctx_t ctx,
+ vapi_generic_event_cb callback,
+ void *callback_ctx);
/**
* @brief clear generic event callback
*
* @param ctx opaque vapi context
*/
-void vapi_clear_generic_event_cb (vapi_ctx_t ctx);
+ void vapi_clear_generic_event_cb (vapi_ctx_t ctx);
+
+#ifdef __cplusplus
+}
+#endif
#endif