Skip to content

Commit 2cfac96

Browse files
author
kharcheva
committed
Support Android build for gRPC
commit_hash:273b353454e6490ebf71ed39743b7059c188690b
1 parent 11097c2 commit 2cfac96

File tree

9 files changed

+85
-9
lines changed

9 files changed

+85
-9
lines changed

contrib/libs/grpc/include/grpcpp/create_channel_binder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#ifdef GPR_ANDROID
2121

22-
#error #include <jni.h>
22+
#include <jni.h>
2323

2424
#include <memory>
2525

contrib/libs/grpc/include/grpcpp/security/binder_security_policy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#ifdef GPR_ANDROID
2121

22-
#error #include <jni.h>
22+
#include <jni.h>
2323

2424
#endif
2525

contrib/libs/grpc/src/core/ext/transport/binder/client/endpoint_binder_pool.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
2424

25-
#error #include <jni.h>
25+
#include <jni.h>
2626

2727
#include "src/core/ext/transport/binder/wire_format/binder_android.h"
2828

contrib/libs/grpc/src/core/ext/transport/binder/client/jni_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <grpc/support/port_platform.h>
2121

22-
#error #include <jni.h>
22+
#include <jni.h>
2323

2424
#include <functional>
2525
#include <util/generic/string.h>

contrib/libs/grpc/src/core/ext/transport/binder/security_policy/binder_security_policy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#ifdef GPR_ANDROID
2222

23-
#error #include <jni.h>
23+
#include <jni.h>
2424
#include <unistd.h>
2525

2626
#include <grpc/support/log.h>

contrib/libs/grpc/src/core/ext/transport/binder/server/binder_server.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
3838

39-
#error #include <jni.h>
39+
#include <jni.h>
4040

4141
extern "C" {
4242

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H
16+
#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H
17+
18+
#include <grpc/support/port_platform.h>
19+
20+
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
21+
22+
#include "src/core/ext/transport/binder/utils/ndk_binder.h"
23+
24+
namespace grpc_binder {
25+
namespace ndk_util {
26+
27+
///
28+
/// Represents one strong pointer to an AIBinder object.
29+
/// Copied from binder/ndk/include_cpp/android/binder_auto_utils.h
30+
///
31+
class SpAIBinder {
32+
public:
33+
SpAIBinder() : mBinder(nullptr) {}
34+
explicit SpAIBinder(AIBinder* binder) : mBinder(binder) {}
35+
SpAIBinder(std::nullptr_t)
36+
: SpAIBinder() {} // NOLINT(google-explicit-constructor)
37+
SpAIBinder(const SpAIBinder& other) { *this = other; }
38+
39+
~SpAIBinder() { set(nullptr); }
40+
SpAIBinder& operator=(const SpAIBinder& other) {
41+
if (this == &other) {
42+
return *this;
43+
}
44+
AIBinder_incStrong(other.mBinder);
45+
set(other.mBinder);
46+
return *this;
47+
}
48+
49+
void set(AIBinder* binder) {
50+
AIBinder* old = *const_cast<AIBinder* volatile*>(&mBinder);
51+
if (old != nullptr) AIBinder_decStrong(old);
52+
if (old != *const_cast<AIBinder* volatile*>(&mBinder)) {
53+
__assert(__FILE__, __LINE__, "Race detected.");
54+
}
55+
mBinder = binder;
56+
}
57+
58+
AIBinder* get() const { return mBinder; }
59+
AIBinder** getR() { return &mBinder; }
60+
61+
bool operator!=(const SpAIBinder& rhs) const { return get() != rhs.get(); }
62+
bool operator<(const SpAIBinder& rhs) const { return get() < rhs.get(); }
63+
bool operator<=(const SpAIBinder& rhs) const { return get() <= rhs.get(); }
64+
bool operator==(const SpAIBinder& rhs) const { return get() == rhs.get(); }
65+
bool operator>(const SpAIBinder& rhs) const { return get() > rhs.get(); }
66+
bool operator>=(const SpAIBinder& rhs) const { return get() >= rhs.get(); }
67+
68+
private:
69+
AIBinder* mBinder = nullptr;
70+
};
71+
} // namespace ndk_util
72+
} // namespace grpc_binder
73+
74+
#endif
75+
76+
#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H

contrib/libs/grpc/src/core/ext/transport/binder/utils/ndk_binder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
2121

2222
#include <assert.h>
23-
#error #include <jni.h>
23+
#include <jni.h>
2424

2525
#include <memory>
2626

contrib/libs/grpc/src/core/ext/transport/binder/wire_format/binder_android.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
2121

22-
#error #include <jni.h>
22+
#include <jni.h>
2323

2424
#include <memory>
2525

2626
#include "y_absl/memory/memory.h"
2727

28-
#error #include "src/core/ext/transport/binder/utils/binder_auto_utils.h"
28+
#include "src/core/ext/transport/binder/utils/binder_auto_utils.h"
2929
#include "src/core/ext/transport/binder/utils/ndk_binder.h"
3030
#include "src/core/ext/transport/binder/wire_format/binder.h"
3131
#include "src/core/ext/transport/binder/wire_format/wire_reader.h"

0 commit comments

Comments
 (0)