Debian Codegraph @

test/cpp/interop/server_helper.h

raw
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_TEST_CPP_INTEROP_SERVER_HELPER_H
20 #define GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H
21
22 #include <condition_variable>
23 #include <memory>
24
25 #include <grpc/compression.h>
26 #include <grpc/impl/codegen/atm.h>
27 #include <grpcpp/security/server_credentials.h>
28 #include <grpcpp/server.h>
29 #include <grpcpp/server_builder.h>
30 #include <grpcpp/server_context.h>
31
32 namespace grpc {
33 namespace testing {
34
35 std::shared_ptr<ServerCredentials> CreateInteropServerCredentials();
36
37 class InteropServerContextInspector {
38 public:
39 explicit InteropServerContextInspector(const grpc::ServerContext& context);
40
41 // Inspector methods, able to peek inside ServerContext, follow.
42 std::shared_ptr<const AuthContext> GetAuthContext() const;
43 bool IsCancelled() const;
44 grpc_compression_algorithm GetCallCompressionAlgorithm() const;
45 uint32_t GetEncodingsAcceptedByClient() const;
46 bool WasCompressed() const;
47
48 private:
49 const grpc::ServerContext& context_;
50 };
51
52 namespace interop {
53
54 extern gpr_atm g_got_sigint;
55
56 struct ServerStartedCondition {
57 std::mutex mutex;
58 std::condition_variable condition;
59 bool server_started = false;
60 };
61
62 /// Run gRPC interop server using port FLAGS_port.
63 ///
64 /// \param creds The credentials associated with the server.
65 void RunServer(const std::shared_ptr<ServerCredentials>& creds);
66
67 /// Run gRPC interop server.
68 ///
69 /// \param creds The credentials associated with the server.
70 /// \param port Port to use for the server.
71 /// \param server_started_condition (optional) Struct holding mutex, condition
72 /// variable, and condition used to notify when the server has started.
73 void RunServer(const std::shared_ptr<ServerCredentials>& creds, int port,
74 ServerStartedCondition* server_started_condition);
75
76 /// Run gRPC interop server.
77 ///
78 /// \param creds The credentials associated with the server.
79 /// \param server_options List of options to set when building the server.
80 void RunServer(
81 const std::shared_ptr<ServerCredentials>& creds,
82 std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
83 server_options);
84
85 /// Run gRPC interop server.
86 ///
87 /// \param creds The credentials associated with the server.
88 /// \param port Port to use for the server.
89 /// \param server_options List of options to set when building the server.
90 /// \param server_started_condition (optional) Struct holding mutex, condition
91 // variable, and condition used to notify when the server has started.
92 void RunServer(
93 const std::shared_ptr<ServerCredentials>& creds, const int port,
94 ServerStartedCondition* server_started_condition,
95 std::unique_ptr<std::vector<std::unique_ptr<grpc::ServerBuilderOption>>>
96 server_options);
97
98 } // namespace interop
99 } // namespace testing
100 } // namespace grpc
101
102 #endif // GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H