binder_auto_utils.h
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 #ifndef GRPC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H
16 #define GRPC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H
17 
19 
20 #ifdef GPR_SUPPORT_BINDER_TRANSPORT
21 
23 
24 namespace grpc_binder {
25 namespace ndk_util {
26 
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_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H
ndk_binder.h
grpc_event_engine::experimental::slice_detail::operator==
bool operator==(const BaseSlice &a, const BaseSlice &b)
Definition: include/grpc/event_engine/slice.h:117
get
absl::string_view get(const Cont &c)
Definition: abseil-cpp/absl/strings/str_replace_test.cc:185
grpc_binder
Definition: connection_id_generator.cc:45
grpc::operator>=
bool operator>=(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:143
grpc::operator<
bool operator<(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:140
grpc::operator<=
bool operator<=(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:141
grpc::operator>
bool operator>(string_ref x, string_ref y)
Definition: grpcpp/impl/codegen/string_ref.h:142
operator!=
bool operator!=(const Bytes &a, const Bytes &b)
Definition: boringssl-with-bazel/src/crypto/test/test_util.h:58
cpp.gmock_class.set
set
Definition: bloaty/third_party/googletest/googlemock/scripts/generator/cpp/gmock_class.py:44
binary_size.old
string old
Definition: binary_size.py:128
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:38