api: refactor vlibmemory
[vpp.git] / src / vlibmemory / memory_api.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 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 SRC_VLIBMEMORY_MEMORY_API_H_
19 #define SRC_VLIBMEMORY_MEMORY_API_H_
20
21 #include <svm/svm.h>
22 #include <svm/queue.h>
23 #include <vlib/vlib.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/memory_shared.h>
26
27 svm_queue_t *vl_api_client_index_to_input_queue (u32 index);
28 int vl_mem_api_init (const char *region_name);
29 void vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm,
30                                   f64 now);
31 int vl_mem_api_handle_msg_main (vlib_main_t * vm, vlib_node_runtime_t * node);
32 int vl_mem_api_handle_msg_private (vlib_main_t * vm,
33                                    vlib_node_runtime_t * node, u32 reg_index);
34 vl_api_registration_t *vl_mem_api_client_index_to_registration (u32 handle);
35 void vl_mem_api_enable_disable (vlib_main_t * vm, int yesno);
36 u32 vl_api_memclnt_create_internal (char *, svm_queue_t *);
37
38 static inline u32
39 vl_msg_api_handle_get_epoch (u32 index)
40 {
41   return (index & VL_API_EPOCH_MASK);
42 }
43
44 static inline u32
45 vl_msg_api_handle_get_index (u32 index)
46 {
47   return (index >> VL_API_EPOCH_SHIFT);
48 }
49
50 static inline u32
51 vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
52 {
53   u32 handle;
54   ASSERT (index < 0x00FFFFFF);
55
56   handle = (index << VL_API_EPOCH_SHIFT) | (epoch & VL_API_EPOCH_MASK);
57   return handle;
58 }
59
60 #define VL_MEM_API_LOG_Q_LEN(fmt,qlen)                  \
61 if (TRACE_VLIB_MEMORY_QUEUE)                            \
62   do {                                                  \
63       ELOG_TYPE_DECLARE (e) = {                         \
64         .format = fmt,                                  \
65         .format_args = "i4",                            \
66       };                                                        \
67       struct { u32 len; } *ed;                          \
68       ed = ELOG_DATA (&vm->elog_main, e);               \
69       ed->len = qlen;                                   \
70   } while (0)
71
72 #endif /* SRC_VLIBMEMORY_MEMORY_API_H_ */
73
74 /*
75  * fd.io coding-style-patch-verification: ON
76  *
77  * Local Variables:
78  * eval: (c-set-style "gnu")
79  * End:
80  */