exampleclient/native.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <android/log.h>
16 #include <jni.h>
17 
18 #include "examples/protos/helloworld.grpc.pb.h"
19 #include "examples/protos/helloworld.pb.h"
20 
23 
24 extern "C" JNIEXPORT jstring JNICALL
26  JNIEnv* env, jobject /*this*/, jobject application) {
27  // Lower the gRPC logging level, here it is just for demo and debugging
28  // purpose.
29  setenv("GRPC_VERBOSITY", "INFO", true);
30  if (grpc::experimental::InitializeBinderChannelJavaClass(env)) {
31  __android_log_print(ANDROID_LOG_INFO, "DemoClient",
32  "InitializeBinderChannelJavaClass succeed");
33  } else {
34  __android_log_print(ANDROID_LOG_INFO, "DemoClient",
35  "InitializeBinderChannelJavaClass failed");
36  }
37  static bool first = true;
38  static std::shared_ptr<grpc::Channel> channel;
39  if (first) {
40  first = false;
41  JavaVM* jvm;
42  {
43  jint result = env->GetJavaVM(&jvm);
44  assert(result == 0);
45  }
46  grpc::ChannelArguments ch_args;
47  // This is not required since "grpc.io.action.BIND" is already the default.
48  ch_args.SetString("grpc.binder.custom_android_intent_action_name",
49  "grpc.io.action.BIND");
50  channel = grpc::experimental::CreateCustomBinderChannel(
51  env, application, "io.grpc.binder.cpp.exampleserver",
52  "io.grpc.binder.cpp.exampleserver.ExportedEndpointService",
53  std::make_shared<
54  grpc::experimental::binder::SameSignatureSecurityPolicy>(
55  jvm, application),
56  ch_args);
57  return env->NewStringUTF("Clicked 1 time, channel created");
58  } else {
59  auto stub = helloworld::Greeter::NewStub(channel);
63  request.set_name("BinderTransportClient");
65  if (status.ok()) {
66  return env->NewStringUTF(response.message().c_str());
67  }
68  return env->NewStringUTF(
69  std::string("Clicked more than 1 time. Status not ok " +
70  std::to_string(status.error_code()))
71  .c_str());
72  }
73 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
benchmark.request
request
Definition: benchmark.py:77
grpc::ChannelArguments::SetString
void SetString(const std::string &key, const std::string &value)
Set a textual argument value under key.
Definition: channel_arguments.cc:203
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
hellostreamingworld_pb2.HelloRequest
HelloRequest
Definition: hellostreamingworld_pb2.py:102
status
absl::Status status
Definition: rls.cc:251
async_greeter_client.stub
stub
Definition: hellostreamingworld/async_greeter_client.py:26
binder_security_policy.h
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
Java_io_grpc_binder_cpp_exampleclient_ButtonPressHandler_native_1entry
JNIEXPORT jstring JNICALL Java_io_grpc_binder_cpp_exampleclient_ButtonPressHandler_native_1entry(JNIEnv *env, jobject, jobject application)
Definition: exampleclient/native.cc:25
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
hellostreamingworld_pb2.HelloReply
HelloReply
Definition: hellostreamingworld_pb2.py:109
grpc::ChannelArguments
Definition: grpcpp/support/channel_arguments.h:39
asyncio_get_stats.response
response
Definition: asyncio_get_stats.py:28
first
StrT first
Definition: cxa_demangle.cpp:4884
env
Definition: env.py:1
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
absl::Status::ok
ABSL_MUST_USE_RESULT bool ok() const
Definition: third_party/abseil-cpp/absl/status/status.h:802
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
to_string
static bool to_string(zval *from)
Definition: protobuf/php/ext/google/protobuf/convert.c:333
create_channel_binder.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:42