2 *------------------------------------------------------------------
3 * vat_helper_macros.h - collect api client helper macros in one place
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
19 #ifndef __vat_helper_macros_h__
20 #define __vat_helper_macros_h__
22 /* M: construct, but don't yet send a message */
26 vam->result_ready = 0; \
27 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
28 memset (mp, 0, sizeof (*mp)); \
29 mp->_vl_msg_id = ntohs (VL_API_##T); \
30 mp->client_index = vam->my_client_index; \
35 vam->result_ready = 0; \
36 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)+(n)); \
37 memset (mp, 0, sizeof (*mp)); \
38 mp->_vl_msg_id = ntohs (VL_API_##T); \
39 mp->client_index = vam->my_client_index; \
43 /* S: send a message */
44 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
46 /* W: wait for results, with timeout */
49 timeout = vat_time_now (vam) + 1.0; \
51 while (vat_time_now (vam) < timeout) { \
52 if (vam->result_ready == 1) { \
53 return (vam->retval); \
55 vat_suspend (vam->vlib_main, 1e-5); \
60 /* W2: wait for results, with timeout */
63 timeout = vat_time_now (vam) + 1.0; \
65 while (vat_time_now (vam) < timeout) { \
66 if (vam->result_ready == 1) { \
68 return (vam->retval); \
70 vat_suspend (vam->vlib_main, 1e-5); \
76 #endif /* __vat_helper_macros_h__ */