transaction.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_WIRE_FORMAT_TRANSACTION_H
16 #define GRPC_CORE_EXT_TRANSPORT_BINDER_WIRE_FORMAT_TRANSACTION_H
17 
19 
20 #include <string>
21 #include <vector>
22 
23 #include "absl/strings/string_view.h"
24 
25 #include <grpc/support/log.h>
26 
27 namespace grpc_binder {
28 
29 ABSL_CONST_INIT extern const int kFlagPrefix;
30 ABSL_CONST_INIT extern const int kFlagMessageData;
31 ABSL_CONST_INIT extern const int kFlagSuffix;
32 ABSL_CONST_INIT extern const int kFlagOutOfBandClose;
37 
38 using Metadata = std::vector<std::pair<std::string, std::string>>;
39 
40 class Transaction {
41  public:
42  Transaction(int tx_code, bool is_client)
43  : tx_code_(tx_code), is_client_(is_client) {}
44  // TODO(mingcl): Consider using string_view
45  void SetPrefix(Metadata prefix_metadata) {
46  prefix_metadata_ = prefix_metadata;
47  GPR_ASSERT((flags_ & kFlagPrefix) == 0);
49  }
50  void SetMethodRef(std::string method_ref) {
52  method_ref_ = method_ref;
53  }
58  }
59  void SetSuffix(Metadata suffix_metadata) {
60  if (is_client_) GPR_ASSERT(suffix_metadata.empty());
61  suffix_metadata_ = suffix_metadata;
62  GPR_ASSERT((flags_ & kFlagSuffix) == 0);
64  }
65  void SetStatusDescription(std::string status_desc) {
68  status_desc_ = status_desc;
69  }
70  void SetStatus(int status) {
72  GPR_ASSERT((flags_ >> 16) == 0);
73  GPR_ASSERT(status < (1 << 16));
74  flags_ |= (status << 16);
75  }
76 
77  bool IsClient() const { return is_client_; }
78  bool IsServer() const { return !is_client_; }
79  int GetTxCode() const { return tx_code_; }
80  int GetFlags() const { return flags_; }
81 
83  const Metadata& GetPrefixMetadata() const { return prefix_metadata_; }
84  const Metadata& GetSuffixMetadata() const { return suffix_metadata_; }
87 
88  Transaction(const Transaction&) = delete;
89  void operator=(const Transaction&) = delete;
90 
91  private:
92  int tx_code_;
93  bool is_client_;
99 
100  int flags_ = 0;
101 };
102 
103 } // namespace grpc_binder
104 
105 #endif // GRPC_CORE_EXT_TRANSPORT_BINDER_WIRE_FORMAT_TRANSACTION_H
log.h
grpc_binder::Transaction::prefix_metadata_
Metadata prefix_metadata_
Definition: transaction.h:94
ABSL_CONST_INIT
#define ABSL_CONST_INIT
Definition: abseil-cpp/absl/base/attributes.h:716
grpc_binder::Transaction::GetSuffixMetadata
const Metadata & GetSuffixMetadata() const
Definition: transaction.h:84
grpc_binder::Transaction::Transaction
Transaction(int tx_code, bool is_client)
Definition: transaction.h:42
grpc_binder::Transaction::GetFlags
int GetFlags() const
Definition: transaction.h:80
grpc_binder::Transaction::status_desc_
std::string status_desc_
Definition: transaction.h:98
grpc_binder::Transaction::GetStatusDesc
absl::string_view GetStatusDesc() const
Definition: transaction.h:86
grpc_binder::Transaction::SetMethodRef
void SetMethodRef(std::string method_ref)
Definition: transaction.h:50
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_binder
Definition: connection_id_generator.cc:45
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_binder::Transaction::SetStatusDescription
void SetStatusDescription(std::string status_desc)
Definition: transaction.h:65
grpc_binder::kFlagMessageDataIsPartial
const int kFlagMessageDataIsPartial
Definition: transaction.cc:30
status
absl::Status status
Definition: rls.cc:251
grpc_binder::Transaction::method_ref_
std::string method_ref_
Definition: transaction.h:96
grpc_binder::Transaction::GetMessageData
absl::string_view GetMessageData() const
Definition: transaction.h:85
grpc_binder::Transaction::is_client_
bool is_client_
Definition: transaction.h:93
tx_code
int tx_code
Definition: fake_binder_test.cc:241
grpc_binder::Transaction::SetPrefix
void SetPrefix(Metadata prefix_metadata)
Definition: transaction.h:45
grpc_binder::Transaction::IsClient
bool IsClient() const
Definition: transaction.h:77
grpc_binder::Transaction::GetTxCode
int GetTxCode() const
Definition: transaction.h:79
grpc_binder::kFlagStatusDescription
const int kFlagStatusDescription
Definition: transaction.cc:28
grpc_binder::Transaction::SetSuffix
void SetSuffix(Metadata suffix_metadata)
Definition: transaction.h:59
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_binder::kFlagExpectSingleMessage
const int kFlagExpectSingleMessage
Definition: transaction.cc:27
grpc_binder::Transaction::operator=
void operator=(const Transaction &)=delete
grpc_binder::Transaction::tx_code_
int tx_code_
Definition: transaction.h:92
grpc_binder::Transaction::flags_
int flags_
Definition: transaction.h:100
message_data
void * message_data(MessageHeader *msg)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/message.c:250
grpc_binder::kFlagPrefix
const int kFlagPrefix
Definition: transaction.cc:23
grpc_binder::kFlagMessageDataIsParcelable
const int kFlagMessageDataIsParcelable
Definition: transaction.cc:29
grpc_binder::kFlagSuffix
const int kFlagSuffix
Definition: transaction.cc:25
grpc_binder::Transaction::GetPrefixMetadata
const Metadata & GetPrefixMetadata() const
Definition: transaction.h:83
grpc_binder::kFlagMessageData
const int kFlagMessageData
Definition: transaction.cc:24
grpc_binder::Transaction::SetStatus
void SetStatus(int status)
Definition: transaction.h:70
grpc_binder::kFlagOutOfBandClose
const int kFlagOutOfBandClose
Definition: transaction.cc:26
grpc_binder::Transaction::IsServer
bool IsServer() const
Definition: transaction.h:78
grpc_binder::Transaction::message_data_
std::string message_data_
Definition: transaction.h:97
grpc_binder::Transaction::GetMethodRef
absl::string_view GetMethodRef() const
Definition: transaction.h:82
grpc_binder::Transaction::suffix_metadata_
Metadata suffix_metadata_
Definition: transaction.h:95
grpc_binder::Metadata
std::vector< std::pair< std::string, std::string > > Metadata
Definition: transaction.h:38
grpc_binder::Transaction::SetData
void SetData(std::string message_data)
Definition: transaction.h:54
grpc_binder::Transaction
Definition: transaction.h:40
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:41