api: refactor vlibmemory
[vpp.git] / src / vlibmemory / socket_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_SOCKET_API_H_
19 #define SRC_VLIBMEMORY_SOCKET_API_H_
20
21 #include <vlibapi/api_common.h>
22 #include <vppinfra/file.h>
23
24 #define API_SOCKET_FILE "/run/vpp-api.sock"
25
26 typedef struct
27 {
28   clib_file_t *clib_file;
29   vl_api_registration_t *regp;
30   u8 *data;
31 } vl_socket_args_for_process_t;
32
33 typedef struct
34 {
35   /* Server port number */
36   u8 *socket_name;
37
38   /* By default, localhost... */
39   u32 bind_address;
40
41   /*
42    * (listen, server, client) registrations. Shared memory
43    * registrations are in shared memory
44    */
45   vl_api_registration_t *registration_pool;
46   /*
47    * Chain-drag variables, so message API handlers
48    * (generally) don't know whether they're talking to a socket
49    * or to a shared-memory connection.
50    */
51   vl_api_registration_t *current_rp;
52   clib_file_t *current_uf;
53   /* One input buffer, shared across all sockets */
54   i8 *input_buffer;
55
56   /* pool of process args for socket clients */
57   vl_socket_args_for_process_t *process_args;
58
59   /* Listen for API connections here */
60   clib_socket_t socksvr_listen_socket;
61 } socket_main_t;
62
63 extern socket_main_t socket_main;
64
65 void vl_socket_free_registration_index (u32 pool_index);
66 clib_error_t *vl_socket_read_ready (struct clib_file *uf);
67 void vl_socket_add_pending_output (struct clib_file *uf,
68                                    struct vl_api_registration_ *rp,
69                                    u8 * buffer, uword buffer_bytes);
70 void vl_socket_add_pending_output_no_flush (struct clib_file *uf,
71                                             struct vl_api_registration_ *rp,
72                                             u8 * buffer, uword buffer_bytes);
73 clib_error_t *vl_socket_write_ready (struct clib_file *uf);
74 void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
75 void vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp,
76                                 i8 * input_v);
77 void vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am);
78 clib_error_t *vl_sock_api_init (vlib_main_t * vm);
79
80 #endif /* SRC_VLIBMEMORY_SOCKET_API_H_ */
81
82 /*
83  * fd.io coding-style-patch-verification: ON
84  *
85  * Local Variables:
86  * eval: (c-set-style "gnu")
87  * End:
88  */