3 * Copyright 2018 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 #include <grpcpp/grpcpp.h>
22 #include "src/core/lib/security/security_connector/ssl_utils_config.h"
23 #include "test/cpp/interop/interop_client.h"
25 std::shared_ptr<grpc::testing::InteropClient> GetClient(const char* host,
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);
32 std::shared_ptr<grpc::ChannelCredentials> credentials;
34 credentials = grpc::SslCredentials(grpc::SslCredentialsOptions());
36 credentials = grpc::InsecureChannelCredentials();
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));
45 extern "C" JNIEXPORT jboolean JNICALL
46 Java_io_grpc_interop_cpp_InteropActivity_doEmpty(JNIEnv* env, jobject obj_this,
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);
54 return GetClient(host, port, use_tls)->DoEmpty();
57 extern "C" JNIEXPORT jboolean JNICALL
58 Java_io_grpc_interop_cpp_InteropActivity_doLargeUnary(JNIEnv* env,
62 jboolean use_tls_raw) {
63 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
64 int port = static_cast<int>(port_raw);
65 bool use_tls = static_cast<bool>(use_tls_raw);
67 return GetClient(host, port, use_tls)->DoLargeUnary();
70 extern "C" JNIEXPORT jboolean JNICALL
71 Java_io_grpc_interop_cpp_InteropActivity_doEmptyStream(JNIEnv* env,
75 jboolean use_tls_raw) {
76 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
77 int port = static_cast<int>(port_raw);
78 bool use_tls = static_cast<bool>(use_tls_raw);
80 return GetClient(host, port, use_tls)->DoEmptyStream();
83 extern "C" JNIEXPORT jboolean JNICALL
84 Java_io_grpc_interop_cpp_InteropActivity_doRequestStreaming(
85 JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
86 jboolean use_tls_raw) {
87 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
88 int port = static_cast<int>(port_raw);
89 bool use_tls = static_cast<bool>(use_tls_raw);
91 return GetClient(host, port, use_tls)->DoRequestStreaming();
94 extern "C" JNIEXPORT jboolean JNICALL
95 Java_io_grpc_interop_cpp_InteropActivity_doResponseStreaming(
96 JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
97 jboolean use_tls_raw) {
98 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
99 int port = static_cast<int>(port_raw);
100 bool use_tls = static_cast<bool>(use_tls_raw);
102 return GetClient(host, port, use_tls)->DoResponseStreaming();
105 extern "C" JNIEXPORT jboolean JNICALL
106 Java_io_grpc_interop_cpp_InteropActivity_doPingPong(JNIEnv* env,
110 jboolean use_tls_raw) {
111 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
112 int port = static_cast<int>(port_raw);
113 bool use_tls = static_cast<bool>(use_tls_raw);
115 return GetClient(host, port, use_tls)->DoPingPong();