1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_SURFACE_SERVER_H
20 #define GRPC_CORE_LIB_SURFACE_SERVER_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <grpc/grpc.h>
25 #include "src/core/lib/channel/channel_stack.h"
26 #include "src/core/lib/channel/channelz.h"
27 #include "src/core/lib/debug/trace.h"
28 #include "src/core/lib/transport/transport.h"
29 
30 extern const grpc_channel_filter grpc_server_top_filter;
31 
32 /** Lightweight tracing of server channel state */
33 extern grpc_core::TraceFlag grpc_server_channel_trace;
34 
35 /* Add a listener to the server: when the server starts, it will call start,
36    and when it shuts down, it will call destroy */
37 void grpc_server_add_listener(grpc_server* server, void* listener,
38                               void (*start)(grpc_server* server, void* arg,
39                                             grpc_pollset** pollsets,
40                                             size_t npollsets),
41                               void (*destroy)(grpc_server* server, void* arg,
42                                               grpc_closure* on_done),
43                               intptr_t socket_uuid);
44 
45 /* Setup a transport - creates a channel stack, binds the transport to the
46    server */
47 void grpc_server_setup_transport(
48     grpc_server* server, grpc_transport* transport,
49     grpc_pollset* accepting_pollset, const grpc_channel_args* args,
50     const grpc_core::RefCountedPtr<grpc_core::channelz::SocketNode>&
51         socket_node,
52     grpc_resource_user* resource_user = nullptr);
53 
54 /* fills in the uuids of all listen sockets on this server */
55 void grpc_server_populate_listen_sockets(
56     grpc_server* server, grpc_core::channelz::ChildRefsList* listen_sockets);
57 
58 grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
59     grpc_server* server);
60 
61 const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server);
62 
63 grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server);
64 
65 int grpc_server_has_open_connections(grpc_server* server);
66 
67 /* Do not call this before grpc_server_start. Returns the pollsets and the
68  * number of pollsets via 'pollsets' and 'pollset_count'. */
69 void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets,
70                               size_t* pollset_count);
71 
72 #endif /* GRPC_CORE_LIB_SURFACE_SERVER_H */
73