* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
-#include <vpp/api/vpe_msg_enum.h>
+#include <vlibmemory/memclnt.api_enum.h>
+#include <vlibmemory/memclnt.api_types.h>
#include "vppapiclient.h"
* vac_read() -> resumes RX thread
*/
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-
-vlib_main_t vlib_global_main;
-vlib_main_t **vlib_mains;
-
typedef struct {
u8 connected_to_vlib;
pthread_t rx_thread_handle;
bool rx_is_running = false;
bool timeout_thread_cancelled = false;
-/* Set to true to enable memory tracing */
-bool mem_trace = false;
-
-__attribute__((constructor))
-static void
-vac_client_constructor (void)
-{
- clib_mem_init (0, 1 << 30);
-#if USE_DLMALLOC == 0
- {
- u8 *heap;
- mheap_t *h;
-
- heap = clib_mem_get_per_cpu_heap ();
- h = mheap_header (heap);
- /* make the main heap thread-safe */
- h->flags |= MHEAP_FLAG_THREAD_SAFE;
- }
-#endif
- if (mem_trace)
- clib_mem_trace (1);
-}
-
-__attribute__((destructor))
-static void
-vac_client_destructor (void)
-{
- if (mem_trace)
- fformat(stderr, "TRACE: %s",
- format (0, "%U\n",
- format_mheap, clib_mem_get_heap (), 1));
-}
-
+/* Only ever allocate one heap */
+bool mem_initialized = false;
static void
init (void)
clib_memset(pm, 0, sizeof(*pm));
}
-/*
- * Satisfy external references when -lvlib is not available.
- */
-void vlib_cli_output (struct vlib_main_t * vm, char * fmt, ...)
-{
- clib_warning ("vlib_cli_output called...");
-}
-
void
vac_free (void * msg)
{
int
vac_connect (char * name, char * chroot_prefix, vac_callback_t cb,
- int rx_qlen)
+ int rx_qlen)
{
rx_thread_done = false;
int rv = 0;
vac_main_t *pm = &vac_main;
+ assert (clib_mem_get_heap ());
init();
if (chroot_prefix != NULL)
vl_set_memory_root_path (chroot_prefix);
vl_client_disconnect();
vl_client_api_unmap();
- vac_callback = 0;
+ //vac_callback = 0;
cleanup();
vl_shmem_hdr_t *shmem_hdr;
/* svm_queue_sub(below) returns {-1, -2} */
- if (!pm->connected_to_vlib) return -3;
+ if (!pm->connected_to_vlib)
+ return VAC_NOT_CONNECTED;
*l = 0;
/* svm_queue_sub(below) returns {-1, -2} */
- if (am->our_pid == 0) return (-4);
+ if (am->our_pid == 0)
+ return (VAC_SHM_NOT_READY);
/* Poke timeout thread */
if (timeout)
vl_msg_api_free((void *) msg);
/* Client might forget to resume RX thread on failure */
vac_rx_resume ();
- return -1;
+ return VAC_TIMEOUT;
}
/*
* XXX: Makes the assumption that client_index is the first member
*/
-typedef VL_API_PACKED(struct _vl_api_header {
+typedef struct _vl_api_header
+{
u16 _vl_msg_id;
u32 client_index;
-}) vl_api_header_t;
+} __attribute__ ((packed)) vl_api_header_t;
static u32
vac_client_index (void)
svm_queue_t *q;
vac_main_t *pm = &vac_main;
- if (!pm->connected_to_vlib) return -1;
+ if (!pm->connected_to_vlib)
+ return VAC_NOT_CONNECTED;
if (!mp) return (-1);
memcpy(mp, p, l);
}
int
-vac_get_msg_index (unsigned char * name)
+vac_get_msg_index (char * name)
{
- return vl_msg_api_get_msg_index (name);
+ return vl_msg_api_get_msg_index ((u8 *)name);
}
int
void
vac_set_error_handler (vac_error_callback_t cb)
{
+ assert (clib_mem_get_heap ());
if (cb) clib_error_register_handler (cb, 0);
}
+
+/*
+ * Required if application doesn't use a VPP heap.
+ */
+void
+vac_mem_init (size_t size)
+{
+ if (mem_initialized)
+ return;
+ if (size == 0)
+ clib_mem_init (0, 1 << 30); // default
+ else
+ clib_mem_init (0, size);
+ mem_initialized = true;
+}