5b85788db8a39f3c5e7cbf8bff07495a342d98f5
[vpp.git] / src / vpp-api / vapi / vapi_internal.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef VAPI_INTERNAL_H
19 #define VAPI_INTERNAL_H
20
21 #include <string.h>
22 #include <vppinfra/types.h>
23
24 /**
25  * @file vapi_internal.h
26  *
27  * internal vpp api C declarations
28  *
29  * This file contains internal vpp api C declarations. It's not intended to be
30  * used by the client programmer and the API defined here might change at any
31  * time..
32  */
33
34 struct vapi_ctx_s;
35
36 typedef struct __attribute__ ((__packed__))
37 {
38   u16 _vl_msg_id;
39   u32 context;
40 } vapi_type_msg_header1_t;
41
42 typedef struct __attribute__ ((__packed__))
43 {
44   u16 _vl_msg_id;
45   u32 client_index;
46   u32 context;
47 } vapi_type_msg_header2_t;
48
49 static inline void
50 vapi_type_msg_header1_t_hton (vapi_type_msg_header1_t * h)
51 {
52   h->_vl_msg_id = htobe16 (h->_vl_msg_id);
53 }
54
55 static inline void
56 vapi_type_msg_header1_t_ntoh (vapi_type_msg_header1_t * h)
57 {
58   h->_vl_msg_id = be16toh (h->_vl_msg_id);
59 }
60
61 static inline void
62 vapi_type_msg_header2_t_hton (vapi_type_msg_header2_t * h)
63 {
64   h->_vl_msg_id = htobe16 (h->_vl_msg_id);
65 }
66
67 static inline void
68 vapi_type_msg_header2_t_ntoh (vapi_type_msg_header2_t * h)
69 {
70   h->_vl_msg_id = be16toh (h->_vl_msg_id);
71 }
72
73
74 #include <vapi.h>
75
76 typedef vapi_error_e (*vapi_cb_t) (struct vapi_ctx_s *, void *, vapi_error_e,
77                                    bool, void *);
78
79 typedef void (*generic_swap_fn_t) (void *payload);
80
81 typedef struct
82 {
83   const char *name;
84   size_t name_len;
85   const char *name_with_crc;
86   size_t name_with_crc_len;
87   bool has_context;
88   size_t context_offset;
89   size_t payload_offset;
90   size_t size;
91   generic_swap_fn_t swap_to_be;
92   generic_swap_fn_t swap_to_host;
93   vapi_msg_id_t id;             /* assigned at run-time */
94 } vapi_message_desc_t;
95
96 typedef struct
97 {
98   const char *name;
99   int payload_offset;
100   size_t size;
101   void (*swap_to_be) (void *payload);
102   void (*swap_to_host) (void *payload);
103 } vapi_event_desc_t;
104
105 extern bool *__vapi_msg_is_with_context;
106
107 vapi_msg_id_t vapi_register_msg (vapi_message_desc_t * msg);
108 u16 vapi_lookup_vl_msg_id (vapi_ctx_t ctx, vapi_msg_id_t id);
109 int vapi_get_client_index (vapi_ctx_t ctx);
110 bool vapi_is_nonblocking (vapi_ctx_t ctx);
111 bool vapi_requests_full (vapi_ctx_t ctx);
112 size_t vapi_get_request_count (vapi_ctx_t ctx);
113 size_t vapi_get_max_request_count (vapi_ctx_t ctx);
114 u32 vapi_gen_req_context (vapi_ctx_t ctx);
115 void vapi_store_request (vapi_ctx_t ctx, u32 context, bool is_dump,
116                          vapi_cb_t callback, void *callback_ctx);
117 int vapi_get_payload_offset (vapi_msg_id_t id);
118 void (*vapi_get_swap_to_host_func (vapi_msg_id_t id)) (void *payload);
119 void (*vapi_get_swap_to_be_func (vapi_msg_id_t id)) (void *payload);
120 size_t vapi_get_message_size (vapi_msg_id_t id);
121 size_t vapi_get_context_offset (vapi_msg_id_t id);
122
123 vapi_error_e vapi_producer_lock (vapi_ctx_t ctx);
124 vapi_error_e vapi_producer_unlock (vapi_ctx_t ctx);
125
126 #endif