3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H
20 #define GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H
22 #include <condition_variable>
25 #include <grpc/compression.h>
26 #include <grpc/impl/codegen/atm.h>
28 #include <grpcpp/security/server_credentials.h>
29 #include <grpcpp/server.h>
30 #include <grpcpp/server_builder.h>
31 #include <grpcpp/server_context.h>
36 std::shared_ptr<ServerCredentials> CreateInteropServerCredentials();
38 class InteropServerContextInspector {
40 explicit InteropServerContextInspector(const ::grpc::ServerContext& context);
42 // Inspector methods, able to peek inside ServerContext, follow.
43 std::shared_ptr<const AuthContext> GetAuthContext() const;
44 bool IsCancelled() const;
45 grpc_compression_algorithm GetCallCompressionAlgorithm() const;
46 uint32_t GetEncodingsAcceptedByClient() const;
47 bool WasCompressed() const;
50 const ::grpc::ServerContext& context_;
55 extern gpr_atm g_got_sigint;
57 struct ServerStartedCondition {
59 std::condition_variable condition;
60 bool server_started = false;
63 /// Run gRPC interop server using port FLAGS_port.
65 /// \param creds The credentials associated with the server.
66 void RunServer(const std::shared_ptr<ServerCredentials>& creds);
68 /// Run gRPC interop server.
70 /// \param creds The credentials associated with the server.
71 /// \param port Port to use for the server.
72 /// \param server_started_condition (optional) Struct holding mutex, condition
73 /// variable, and condition used to notify when the server has started.
74 void RunServer(const std::shared_ptr<ServerCredentials>& creds, int port,
75 ServerStartedCondition* server_started_condition);
77 /// Run gRPC interop server.
79 /// \param creds The credentials associated with the server.
80 /// \param server_options List of options to set when building the server.
82 const std::shared_ptr<ServerCredentials>& creds,
83 std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
86 /// Run gRPC interop server.
88 /// \param creds The credentials associated with the server.
89 /// \param port Port to use for the server.
90 /// \param server_options List of options to set when building the server.
91 /// \param server_started_condition (optional) Struct holding mutex, condition
92 // variable, and condition used to notify when the server has started.
94 const std::shared_ptr<ServerCredentials>& creds, const int port,
95 ServerStartedCondition* server_started_condition,
96 std::unique_ptr<std::vector<std::unique_ptr<grpc::ServerBuilderOption>>>
99 } // namespace interop
100 } // namespace testing
103 #endif // GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H