If you want to pinch code from vpp_api_test, please read and understand it:
/* W: wait for results, with timeout */
#define W(ret) \
do { \
f64 timeout = vat_time_now (vam) + 1.0; \
socket_client_main_t *scm = vam->socket_client_main; \
ret = -99; \
\
if (scm && scm->socket_enable) \
vl_socket_client_read (5); \
while (vat_time_now (vam) < timeout) { \
if (vam->result_ready == 1) { \
ret = vam->retval; \
break; \
} \
vat_suspend (vam->vlib_main, 1e-5); \
} \
} while(0);
So what does the “W” macro do? It causes the vpp_api_test main thread to block
until vpp answers and the vpp_api_test rx pthread processes the reply, or a
timeout occurs.
You’ll need to declare and initialize a clib_time_t, a vat_main_t, then supply
the missing routines:
f64
vat_time_now (vat_main_t * vam)
{
return clib_time_now (&vam->clib_time);
}
void
vat_suspend (vlib_main_t * vm, f64 interval)
{
/* do nothing to busy-wait, or call usleep, or call CLIB_PAUSE */
}
Given that you’re not using vpp_api_test, you might decide to use
vat_helper_macros.h as a guide and fabricate something which seems more at home
in your application.
HTH... Dave
From: Chinmaya Aggarwal <[email protected]>
Sent: Friday, June 26, 2020 7:59 AM
To: Dave Barach (dbarach) <[email protected]>
Subject: Private: Re: [vpp-dev] VPP C API application compilation issue on
using S and W functions
Hi Dave,
We have our application (using VPP C API) running outside of VPP. We linked
vpp libs in our application (vatplugin, vppinfra, vlibmemoryclient, svm,
vppapiclient). Attaching file vpp_connect_test.c that creates connection with
VPP and calls VPP C API to modify a sr policy. We have used function S to send
the message and W to wait for its reply. On compiling this C file we are
getting the following error : -
root@ggnlabvm-hnsnfvsdn03:~/vpp_api_test# make
gcc -Wall -g -c -o vpp_connect_test.o vpp_connect_test.c
gcc -Wall -g -I/usr/include/vpp_plugins -I/usr/include/ -o api_exec
vpp_connect_test.o -Wl,--start-group -lvatplugin -lvppinfra -lvlibmemoryclient
-lsvm -lvppapiclient -Wl,--end-group -lpthread -lm -lrt -ldl
vpp_connect_test.o: In function `del_sl_pol2_index6':
/root/vpp_api_test/vpp_connect_test.c:97: undefined reference to `vat_time_now'
/root/vpp_api_test/vpp_connect_test.c:97: undefined reference to `vat_suspend'
/root/vpp_api_test/vpp_connect_test.c:97: undefined reference to `vat_time_now'
collect2: error: ld returned 1 exit status
Makefile:35: recipe for target 'api_exec' failed
make: *** [api_exec] Error 1
Is there any library that needs to be linked and we have missed it? If not, can
we use S and W function in an external C application, in a way similar to how
VPP uses it?
Thanks and Regards,
Chinmaya Agarwal.
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16834): https://lists.fd.io/g/vpp-dev/message/16834
Mute This Topic: https://lists.fd.io/mt/75126256/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-