grpc-interop.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 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 #include <grpcpp/grpcpp.h>
20 #include <jni.h>
21 
24 
25 std::shared_ptr<grpc::testing::InteropClient> GetClient(const char* host,
26  int port,
27  bool use_tls) {
28  const int host_port_buf_size = 1024;
29  char host_port[host_port_buf_size];
30  snprintf(host_port, host_port_buf_size, "%s:%d", host, port);
31 
32  std::shared_ptr<grpc::ChannelCredentials> credentials;
33  if (use_tls) {
35  } else {
36  credentials = grpc::InsecureChannelCredentials();
37  }
38 
39  grpc::testing::ChannelCreationFunc channel_creation_func =
40  std::bind(grpc::CreateChannel, host_port, credentials);
41  return std::shared_ptr<grpc::testing::InteropClient>(
42  new grpc::testing::InteropClient(channel_creation_func, true, false));
43 }
44 
45 extern "C" JNIEXPORT jboolean JNICALL
47  jstring host_raw,
48  jint port_raw,
49  jboolean use_tls_raw) {
50  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
51  int port = static_cast<int>(port_raw);
52  bool use_tls = static_cast<bool>(use_tls_raw);
53 
54  jboolean result = GetClient(host, port, use_tls)->DoEmpty();
55  env->ReleaseStringUTFChars(host_raw, host);
56  return result;
57 }
58 
59 extern "C" JNIEXPORT jboolean JNICALL
61  jobject obj_this,
62  jstring host_raw,
63  jint port_raw,
64  jboolean use_tls_raw) {
65  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
66  int port = static_cast<int>(port_raw);
67  bool use_tls = static_cast<bool>(use_tls_raw);
68 
69  jboolean result = GetClient(host, port, use_tls)->DoLargeUnary();
70  env->ReleaseStringUTFChars(host_raw, host);
71  return result;
72 }
73 
74 extern "C" JNIEXPORT jboolean JNICALL
76  jobject obj_this,
77  jstring host_raw,
78  jint port_raw,
79  jboolean use_tls_raw) {
80  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
81  int port = static_cast<int>(port_raw);
82  bool use_tls = static_cast<bool>(use_tls_raw);
83 
84  jboolean result = GetClient(host, port, use_tls)->DoEmptyStream();
85  env->ReleaseStringUTFChars(host_raw, host);
86  return result;
87 }
88 
89 extern "C" JNIEXPORT jboolean JNICALL
91  JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
92  jboolean use_tls_raw) {
93  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
94  int port = static_cast<int>(port_raw);
95  bool use_tls = static_cast<bool>(use_tls_raw);
96 
97  jboolean result = GetClient(host, port, use_tls)->DoRequestStreaming();
98  env->ReleaseStringUTFChars(host_raw, host);
99  return result;
100 }
101 
102 extern "C" JNIEXPORT jboolean JNICALL
104  JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
105  jboolean use_tls_raw) {
106  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
107  int port = static_cast<int>(port_raw);
108  bool use_tls = static_cast<bool>(use_tls_raw);
109 
110  jboolean result = GetClient(host, port, use_tls)->DoResponseStreaming();
111  env->ReleaseStringUTFChars(host_raw, host);
112  return result;
113 }
114 
115 extern "C" JNIEXPORT jboolean JNICALL
117  jobject obj_this,
118  jstring host_raw,
119  jint port_raw,
120  jboolean use_tls_raw) {
121  const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
122  int port = static_cast<int>(port_raw);
123  bool use_tls = static_cast<bool>(use_tls_raw);
124 
125  jboolean result = GetClient(host, port, use_tls)->DoPingPong();
126  env->ReleaseStringUTFChars(host_raw, host);
127  return result;
128 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
grpc::SslCredentials
std::shared_ptr< ChannelCredentials > SslCredentials(const SslCredentialsOptions &options)
Builds SSL Credentials given SSL specific options.
Definition: secure_credentials.cc:129
Java_io_grpc_interop_cpp_InteropActivity_doLargeUnary
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doLargeUnary(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:60
Java_io_grpc_interop_cpp_InteropActivity_doRequestStreaming
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doRequestStreaming(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:90
GetClient
std::shared_ptr< grpc::testing::InteropClient > GetClient(const char *host, int port, bool use_tls)
Definition: grpc-interop.cc:25
Java_io_grpc_interop_cpp_InteropActivity_doEmptyStream
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doEmptyStream(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:75
Java_io_grpc_interop_cpp_InteropActivity_doEmpty
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doEmpty(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:46
grpc::SslCredentialsOptions
Options used to build SslCredentials.
Definition: include/grpcpp/security/credentials.h:156
grpcpp.h
interop_client.h
Java_io_grpc_interop_cpp_InteropActivity_doPingPong
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doPingPong(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:116
grpc::CreateChannel
std::shared_ptr< Channel > CreateChannel(const grpc::string &target, const std::shared_ptr< ChannelCredentials > &creds)
grpc::testing::InteropClient
Definition: interop_client.h:40
Java_io_grpc_interop_cpp_InteropActivity_doResponseStreaming
JNIEXPORT jboolean JNICALL Java_io_grpc_interop_cpp_InteropActivity_doResponseStreaming(JNIEnv *env, jobject obj_this, jstring host_raw, jint port_raw, jboolean use_tls_raw)
Definition: grpc-interop.cc:103
ssl_utils_config.h
grpc::testing::ChannelCreationFunc
std::function< std::shared_ptr< Channel >void)> ChannelCreationFunc
Definition: interop_client.h:38
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
env
Definition: env.py:1
grpc::InsecureChannelCredentials
std::shared_ptr< ChannelCredentials > InsecureChannelCredentials()
Credentials for an unencrypted, unauthenticated channel.
Definition: cpp/client/insecure_credentials.cc:69


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:44