#include <vpp-api/vapi/vapi.h>
#include <vpp-api/vapi/vapi_internal.h>
#include <vppinfra/types.h>
+#include <vppinfra/pool.h>
+#include <vlib/vlib.h>
#include <vlibapi/api_common.h>
-#include <vlibmemory/api_common.h>
+#include <vlibmemory/memory_client.h>
/* we need to use control pings for some stuff and because we're forced to put
* the code in headers, we need a way to be able to grab the ids of these
return (ctx->requests_count == ctx->requests_size);
}
-static bool
+bool
vapi_requests_empty (vapi_ctx_t ctx)
{
return (0 == ctx->requests_count);
vl_msg_api_free (msg);
}
+vapi_msg_id_t
+vapi_lookup_vapi_msg_id_t (vapi_ctx_t ctx, u16 vl_msg_id)
+{
+ if (vl_msg_id <= ctx->vl_msg_id_max)
+ {
+ return ctx->vl_msg_id_to_vapi_msg_t[vl_msg_id];
+ }
+ return INVALID_MSG_ID;
+}
+
vapi_error_e
vapi_ctx_alloc (vapi_ctx_t * result)
{
}
ctx->requests = tmp;
memset (ctx->requests, 0, size);
+ /* coverity[MISSING_LOCK] - 177211 requests_mutex is not needed here */
ctx->requests_start = ctx->requests_count = 0;
if (chroot_prefix)
{
vapi_message_desc_t *m = __vapi_metadata.msgs[i];
u8 scratch[m->name_with_crc_len + 1];
memcpy (scratch, m->name_with_crc, m->name_with_crc_len + 1);
- u32 id = vl_api_get_msg_index (scratch);
- if (~0 != id)
+ u32 id = vl_msg_api_get_msg_index (scratch);
+ if (INVALID_MSG_ID != id)
{
if (id > UINT16_MAX)
{
goto out;
}
int tmp;
- unix_shared_memory_queue_t *q = api_main.shmem_hdr->vl_input_queue;
+ svm_queue_t *q = api_main.shmem_hdr->vl_input_queue;
#if VAPI_DEBUG
unsigned msgid = be16toh (*(u16 *) msg);
if (msgid <= ctx->vl_msg_id_max)
vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid];
if (id < __vapi_metadata.count)
{
- VAPI_DBG ("send msg %u[%s]", msgid, __vapi_metadata.msgs[id]->name);
+ VAPI_DBG ("send msg@%p:%u[%s]", msg, msgid,
+ __vapi_metadata.msgs[id]->name);
}
else
{
- VAPI_DBG ("send msg %u[UNKNOWN]", msgid);
+ VAPI_DBG ("send msg@%p:%u[UNKNOWN]", msg, msgid);
}
}
else
{
- VAPI_DBG ("send msg %u[UNKNOWN]", msgid);
+ VAPI_DBG ("send msg@%p:%u[UNKNOWN]", msg, msgid);
}
#endif
- tmp = unix_shared_memory_queue_add (q, (u8 *) & msg,
- VAPI_MODE_BLOCKING ==
- ctx->mode ? 0 : 1);
+ tmp = svm_queue_add (q, (u8 *) & msg,
+ VAPI_MODE_BLOCKING == ctx->mode ? 0 : 1);
if (tmp < 0)
{
rv = VAPI_EAGAIN;
rv = VAPI_EINVAL;
goto out;
}
- unix_shared_memory_queue_t *q = api_main.shmem_hdr->vl_input_queue;
+ svm_queue_t *q = api_main.shmem_hdr->vl_input_queue;
#if VAPI_DEBUG
unsigned msgid1 = be16toh (*(u16 *) msg1);
unsigned msgid2 = be16toh (*(u16 *) msg2);
}
VAPI_DBG ("send two: %u[%s], %u[%s]", msgid1, name1, msgid2, name2);
#endif
- int tmp = unix_shared_memory_queue_add2 (q, (u8 *) & msg1, (u8 *) & msg2,
- VAPI_MODE_BLOCKING ==
- ctx->mode ? 0 : 1);
+ int tmp = svm_queue_add2 (q, (u8 *) & msg1, (u8 *) & msg2,
+ VAPI_MODE_BLOCKING == ctx->mode ? 0 : 1);
if (tmp < 0)
{
rv = VAPI_EAGAIN;
}
vapi_error_e
-vapi_recv (vapi_ctx_t ctx, void **msg, size_t * msg_size)
+vapi_recv (vapi_ctx_t ctx, void **msg, size_t * msg_size,
+ svm_q_conditional_wait_t cond, u32 time)
{
if (!ctx || !ctx->connected || !msg || !msg_size)
{
return VAPI_EINVAL;
}
- unix_shared_memory_queue_t *q = am->vl_input_queue;
+ svm_queue_t *q = am->vl_input_queue;
VAPI_DBG ("doing shm queue sub");
- int tmp = unix_shared_memory_queue_sub (q, (u8 *) & data, 0);
+
+ int tmp = svm_queue_sub (q, (u8 *) & data, cond, time);
+
if (tmp == 0)
{
#if VAPI_DEBUG_ALLOC
}
*msg = (u8 *) data;
*msg_size = ntohl (msgbuf->data_len);
- VAPI_DBG ("recv msg %p", *msg);
+#if VAPI_DEBUG
+ unsigned msgid = be16toh (*(u16 *) * msg);
+ if (msgid <= ctx->vl_msg_id_max)
+ {
+ vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid];
+ if (id < __vapi_metadata.count)
+ {
+ VAPI_DBG ("recv msg@%p:%u[%s]", *msg, msgid,
+ __vapi_metadata.msgs[id]->name);
+ }
+ else
+ {
+ VAPI_DBG ("recv msg@%p:%u[UNKNOWN]", *msg, msgid);
+ }
+ }
+ else
+ {
+ VAPI_DBG ("recv msg@%p:%u[UNKNOWN]", *msg, msgid);
+ }
+#endif
}
else
{
vapi_error_e
vapi_wait (vapi_ctx_t ctx, vapi_wait_mode_e mode)
{
- /* FIXME */
return VAPI_ENOTSUP;
}
return VAPI_OK;
}
-static bool
+bool
vapi_msg_is_with_context (vapi_msg_id_t id)
{
assert (id <= __vapi_metadata.count);
VAPI_DBG ("vapi_dispatch_one()");
void *msg;
size_t size;
- vapi_error_e rv = vapi_recv (ctx, &msg, &size);
+ vapi_error_e rv = vapi_recv (ctx, &msg, &size, SVM_Q_WAIT, 0);
if (VAPI_OK != rv)
{
VAPI_DBG ("vapi_recv failed with rv=%d", rv);
vapi_msg_free (ctx, msg);
return VAPI_EINVAL;
}
- if (~0 == (unsigned) ctx->vl_msg_id_to_vapi_msg_t[vpp_id])
+ if (INVALID_MSG_ID == (unsigned) ctx->vl_msg_id_to_vapi_msg_t[vpp_id])
{
VAPI_ERR ("Unknown msg ID received, id `%u' marked as not supported",
(unsigned) vpp_id);
return (VAPI_MODE_NONBLOCKING == ctx->mode);
}
-bool vapi_requests_full (vapi_ctx_t ctx);
-
-size_t vapi_get_request_count (vapi_ctx_t ctx);
-
size_t
vapi_get_max_request_count (vapi_ctx_t ctx)
{
return VAPI_OK;
}
+size_t
+vapi_get_message_count ()
+{
+ return __vapi_metadata.count;
+}
+
+const char *
+vapi_get_msg_name (vapi_msg_id_t id)
+{
+ return __vapi_metadata.msgs[id]->name;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*