diff options
author | Mauro Sardara <msardara@cisco.com> | 2019-01-19 01:29:33 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2019-01-21 12:03:48 +0100 |
commit | 9e5f41ed6ebe64a789916794626485460078c420 (patch) | |
tree | d2ac3090026ec8929558e88eca533f8787a6ff0b /libtransport/src/hicn/transport/core/vpp_binary_api.c | |
parent | d13d37534d9449dd54277af664310d5f957dc44a (diff) |
- Code style fix
- Improved vpp binary api interface
- Correction in object pool destructor
- Fix error in Memif Connector
Change-Id: Id1dd9219fc1ac0b3717ae019ebff17373bebc635
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/core/vpp_binary_api.c')
-rw-r--r--[-rwxr-xr-x] | libtransport/src/hicn/transport/core/vpp_binary_api.c | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.c b/libtransport/src/hicn/transport/core/vpp_binary_api.c index ab23d3cf5..09ffb2ec6 100755..100644 --- a/libtransport/src/hicn/transport/core/vpp_binary_api.c +++ b/libtransport/src/hicn/transport/core/vpp_binary_api.c @@ -53,13 +53,22 @@ #include <vpp/api/vpe_all_api_h.h> #undef vl_msg_name_crc_list -// #define vl_api_version(n,v) static u32 vpe_api_version = (v); -// #include <vpp/api/vpe.api.h> -// #undef vl_api_version - -#define POINTER_MAP_SIZE 32 -static void *global_pointers_map[POINTER_MAP_SIZE]; -static uint8_t global_pointers_map_index = 0; +#include <semaphore.h> + +struct vpp_binary_api { + api_main_t *api_main; + u32 my_client_index; + unix_shared_memory_queue_t *vl_input_queue; + vlib_main_t *vlib_main; + sem_t *semaphore; + u32 ping_id; + int ret_val; + void *user_param; +}; + +static context_store_t context_store = { + .global_pointers_map_index = 0, +}; /* * Table of message reply handlers, must include boilerplate handlers @@ -91,7 +100,8 @@ typedef struct __attribute__((packed)) vl_generic_reply_s { static void vl_api_control_ping_reply_t_handler( vl_api_control_ping_reply_t *mp) { // Just unblock main thread - vpp_binary_api_t *binary_api = global_pointers_map[mp->context]; + vpp_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); binary_api->ret_val = ntohl(mp->retval); vpp_binary_api_unlock_waiting_thread(binary_api); } @@ -99,7 +109,8 @@ static void vl_api_control_ping_reply_t_handler( static void vl_api_sw_interface_set_flags_reply_t_handler( vl_api_control_ping_reply_t *mp) { // Unblock main thread setting reply message status code - vpp_binary_api_t *binary_api = global_pointers_map[mp->context]; + vpp_binary_api_t *binary_api; + CONTEXT_GET(context_store, mp, binary_api); binary_api->ret_val = ntohl(mp->retval); vpp_binary_api_unlock_waiting_thread(binary_api); } @@ -160,9 +171,7 @@ void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api) { vl_msg_api_get_msg_index((u8 *)(VL_API_CONTROL_PING_CRC))); mp_ping->client_index = api->my_client_index; - global_pointers_map[global_pointers_map_index] = api; - mp_ping->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp_ping); TRANSPORT_LOGI("Sending ping id %u", mp_ping->_vl_msg_id); @@ -191,9 +200,7 @@ int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index, mp->sw_if_index = clib_host_to_net_u32(sw_index); mp->admin_up_down = (u8)state; - global_pointers_map[global_pointers_map_index] = api; - mp->context = global_pointers_map_index++; - global_pointers_map_index %= POINTER_MAP_SIZE; + CONTEXT_SAVE(context_store, api, mp); TRANSPORT_LOGI("Sending set int flags id %u", mp->_vl_msg_id); @@ -209,6 +216,29 @@ void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request) { S(api, req); } +int vpp_binary_api_get_ret_value(vpp_binary_api_t *api) { return api->ret_val; } + +void vpp_binary_api_set_ret_value(vpp_binary_api_t *api, int ret_val) { + api->ret_val = ret_val; +} + +void *vpp_binary_api_get_user_param(vpp_binary_api_t *api) { + return api->user_param; +} + +void vpp_binary_api_set_user_param(vpp_binary_api_t *api, void *user_param) { + api->user_param = user_param; +} + +uint32_t vpp_binary_api_get_client_index(vpp_binary_api_t *api) { + return api->my_client_index; +} + +void vpp_binary_api_set_client_index(vpp_binary_api_t *api, + uint32_t client_index) { + api->my_client_index = client_index; +} + int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t *api, void *request) { vpp_binary_api_send_request(api, request); |