blob: 4fea6a6c36eef1628bec379d2797c1259ea8b41d [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <nullable.test.json.llcpp.h>
#include <memory>
namespace llcpp {
namespace fidl {
namespace test {
namespace nullable {
namespace {
[[maybe_unused]] constexpr uint64_t kSimpleProtocol_Add_Ordinal =
1238508415331800925lu;
extern "C" const fidl_type_t fidl_test_nullable_SimpleProtocolAddRequestTable;
extern "C" const fidl_type_t fidl_test_nullable_SimpleProtocolAddResponseTable;
} // namespace
template <>
SimpleProtocol::ResultOf::Add_Impl<SimpleProtocol::AddResponse>::Add_Impl(
::zx::unowned_channel _client_end, int32_t a, int32_t b) {
// Destructors can't be called because it will lead to handle double close
// (here and in fidl::Encode).
FIDL_ALIGNDECL uint8_t _request_buffer[sizeof(AddRequest)];
auto& _request = *new (_request_buffer) AddRequest(0, a, b);
auto _encoded = ::fidl::internal::LinearizedAndEncoded<AddRequest>(&_request);
auto& _encode_result = _encoded.result();
if (_encode_result.status != ZX_OK) {
Super::SetFailure(std::move(_encode_result));
return;
}
::fidl::EncodedMessage<AddRequest> _encoded_request =
std::move(_encode_result.message);
Super::SetResult(SimpleProtocol::InPlace::Add(std::move(_client_end),
std::move(_encoded_request),
Super::response_buffer()));
}
SimpleProtocol::ResultOf::Add SimpleProtocol::SyncClient::Add(int32_t a,
int32_t b) {
return ResultOf::Add(::zx::unowned_channel(this->channel_), a, b);
}
SimpleProtocol::ResultOf::Add SimpleProtocol::Call::Add(
::zx::unowned_channel _client_end, int32_t a, int32_t b) {
return ResultOf::Add(std::move(_client_end), a, b);
}
template <>
SimpleProtocol::UnownedResultOf::Add_Impl<
SimpleProtocol::AddResponse>::Add_Impl(::zx::unowned_channel _client_end,
::fidl::BytePart _request_buffer,
int32_t a, int32_t b,
::fidl::BytePart _response_buffer) {
if (_request_buffer.capacity() < AddRequest::PrimarySize) {
Super::SetFailure(::fidl::DecodeResult<AddResponse>(
ZX_ERR_BUFFER_TOO_SMALL, ::fidl::kErrorRequestBufferTooSmall));
return;
}
new (_request_buffer.data()) AddRequest(0, a, b);
_request_buffer.set_actual(sizeof(AddRequest));
::fidl::DecodedMessage<AddRequest> _msg(std::move(_request_buffer));
auto _encode_result = ::fidl::Encode<AddRequest>(std::move(_msg));
if (_encode_result.status != ZX_OK) {
Super::SetFailure(std::move(_encode_result));
return;
}
::fidl::EncodedMessage<AddRequest> _encoded_request =
std::move(_encode_result.message);
Super::SetResult(SimpleProtocol::InPlace::Add(std::move(_client_end),
std::move(_encoded_request),
std::move(_response_buffer)));
}
SimpleProtocol::UnownedResultOf::Add SimpleProtocol::SyncClient::Add(
::fidl::BytePart _request_buffer, int32_t a, int32_t b,
::fidl::BytePart _response_buffer) {
return UnownedResultOf::Add(::zx::unowned_channel(this->channel_),
std::move(_request_buffer), std::move(a),
std::move(b), std::move(_response_buffer));
}
SimpleProtocol::UnownedResultOf::Add SimpleProtocol::Call::Add(
::zx::unowned_channel _client_end, ::fidl::BytePart _request_buffer,
int32_t a, int32_t b, ::fidl::BytePart _response_buffer) {
return UnownedResultOf::Add(std::move(_client_end),
std::move(_request_buffer), std::move(a),
std::move(b), std::move(_response_buffer));
}
::fidl::DecodeResult<SimpleProtocol::AddResponse> SimpleProtocol::InPlace::Add(
::zx::unowned_channel _client_end,
::fidl::DecodedMessage<AddRequest> params,
::fidl::BytePart response_buffer) {
auto _encode_request_result = ::fidl::Encode(std::move(params));
if (_encode_request_result.status != ZX_OK) {
return ::fidl::DecodeResult<SimpleProtocol::AddResponse>::FromFailure(
std::move(_encode_request_result));
}
return Add(std::move(_client_end), std::move(_encode_request_result.message),
std::move(response_buffer));
}
::fidl::DecodeResult<SimpleProtocol::AddResponse> SimpleProtocol::InPlace::Add(
::zx::unowned_channel _client_end,
::fidl::EncodedMessage<AddRequest> params,
::fidl::BytePart response_buffer) {
AddRequest* request = reinterpret_cast<AddRequest*>(params.bytes().data());
fidl_init_txn_header(&request->_hdr, 0, kSimpleProtocol_Add_Ordinal);
auto _call_result = ::fidl::Call<AddRequest, AddResponse>(
std::move(_client_end), std::move(params), std::move(response_buffer));
if (_call_result.status != ZX_OK) {
return ::fidl::DecodeResult<SimpleProtocol::AddResponse>::FromFailure(
std::move(_call_result));
}
return ::fidl::Decode(std::move(_call_result.message));
}
SimpleProtocol::ResultOf::Add SimpleProtocol::ClientImpl::Add_Sync(int32_t a,
int32_t b) {
if (auto _binding = ::fidl::internal::ClientBase::GetBinding()) {
return ResultOf::Add(_binding->channel(), a, b);
}
return ::fidl::StatusAndError(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound);
}
SimpleProtocol::UnownedResultOf::Add SimpleProtocol::ClientImpl::Add_Sync(
::fidl::BytePart _request_buffer, int32_t a, int32_t b,
::fidl::BytePart _response_buffer) {
if (auto _binding = ::fidl::internal::ClientBase::GetBinding()) {
return UnownedResultOf::Add(_binding->channel(), std::move(_request_buffer),
std::move(a), std::move(b),
std::move(_response_buffer));
}
return ::fidl::StatusAndError(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound);
}
::fidl::StatusAndError SimpleProtocol::ClientImpl::Add(
int32_t a, int32_t b, ::fit::callback<void(int32_t sum)> _cb) {
class ManagedResponseContext : public AddResponseContext {
public:
ManagedResponseContext(::fit::callback<void(int32_t sum)> cb)
: cb_(std::move(cb)) {}
void OnReply(::fidl::DecodedMessage<AddResponse> msg) override {
auto message = msg.message();
cb_(std::move(message->sum));
delete this;
}
void OnError() override { delete this; }
::fit::callback<void(int32_t sum)> cb_;
};
constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<
AddRequest, ::fidl::MessageDirection::kSending>();
::fidl::internal::AlignedBuffer<_kWriteAllocSize> _write_bytes_inlined;
auto& _write_bytes_array = _write_bytes_inlined;
auto* _context = new ManagedResponseContext(std::move(_cb));
auto status_and_error =
Add(_write_bytes_array.view(), std::move(a), std::move(b), _context);
if (!status_and_error.ok()) {
delete _context;
}
return status_and_error;
}
::fidl::StatusAndError SimpleProtocol::ClientImpl::Add(
::fidl::BytePart _request_buffer, int32_t a, int32_t b,
AddResponseContext* _context) {
if (_request_buffer.capacity() < AddRequest::PrimarySize) {
return ::fidl::StatusAndError(ZX_ERR_BUFFER_TOO_SMALL,
::fidl::kErrorRequestBufferTooSmall);
}
::fidl::internal::ClientBase::PrepareAsyncTxn(_context);
new (_request_buffer.data()) AddRequest(_context->Txid(), a, b);
_request_buffer.set_actual(sizeof(AddRequest));
::fidl::DecodedMessage<AddRequest> _decoded_request(
std::move(_request_buffer));
auto _encode_request_result = ::fidl::Encode(std::move(_decoded_request));
if (_encode_request_result.status != ZX_OK) {
::fidl::internal::ClientBase::ForgetAsyncTxn(_context);
return ::fidl::DecodeResult<AddResponse>::FromFailure(
std::move(_encode_request_result));
}
if (auto _binding = ::fidl::internal::ClientBase::GetBinding()) {
zx_status_t _write_status = ::fidl::Write(
_binding->channel(), std::move(_encode_request_result.message));
if (_write_status != ZX_OK) {
::fidl::internal::ClientBase::ForgetAsyncTxn(_context);
return ::fidl::StatusAndError(_write_status, ::fidl::kErrorWriteFailed);
}
return ::fidl::StatusAndError(ZX_OK, nullptr);
}
::fidl::internal::ClientBase::ForgetAsyncTxn(_context);
return ::fidl::StatusAndError(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound);
}
zx_status_t SimpleProtocol::ClientImpl::Dispatch(
fidl_msg_t* msg, ::fidl::internal::ResponseContext* context) {
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(msg->bytes);
switch (hdr->ordinal) {
case kSimpleProtocol_Add_Ordinal: {
auto result = ::fidl::DecodeAs<AddResponse>(msg);
if (result.status != ZX_OK) {
context->OnError();
return result.status;
}
static_cast<AddResponseContext*>(context)->OnReply(
std::move(result.message));
break;
}
case kFidlOrdinalEpitaph:
if (context) return ZX_ERR_INVALID_ARGS;
::fidl::internal::ClientBase::Close(
reinterpret_cast<fidl_epitaph_t*>(hdr)->error);
break;
default:
zx_handle_close_many(msg->handles, msg->num_handles);
if (context) context->OnError();
return ZX_ERR_NOT_SUPPORTED;
}
return ZX_OK;
}
bool SimpleProtocol::TryDispatch(Interface* impl, fidl_msg_t* msg,
::fidl::Transaction* txn) {
if (msg->num_bytes < sizeof(fidl_message_header_t)) {
zx_handle_close_many(msg->handles, msg->num_handles);
txn->Close(ZX_ERR_INVALID_ARGS);
return true;
}
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(msg->bytes);
zx_status_t status = fidl_validate_txn_header(hdr);
if (status != ZX_OK) {
txn->Close(status);
return true;
}
switch (hdr->ordinal) {
case kSimpleProtocol_Add_Ordinal: {
auto result = ::fidl::DecodeAs<AddRequest>(msg);
if (result.status != ZX_OK) {
txn->Close(ZX_ERR_INVALID_ARGS);
return true;
}
auto message = result.message.message();
impl->Add(std::move(message->a), std::move(message->b),
Interface::AddCompleter::Sync(txn));
return true;
}
default: {
return false;
}
}
}
bool SimpleProtocol::Dispatch(Interface* impl, fidl_msg_t* msg,
::fidl::Transaction* txn) {
bool found = TryDispatch(impl, msg, txn);
if (!found) {
zx_handle_close_many(msg->handles, msg->num_handles);
txn->Close(ZX_ERR_NOT_SUPPORTED);
}
return found;
}
void SimpleProtocol::Interface::AddCompleterBase::Reply(int32_t sum) {
// Destructors can't be called because it will lead to handle double close
// (here and in fidl::Encode).
FIDL_ALIGNDECL uint8_t _response_buffer[sizeof(AddResponse)];
auto& _response = *new (_response_buffer) AddResponse{sum};
auto _encoded =
::fidl::internal::LinearizedAndEncoded<AddResponse>(&_response);
auto& _encode_result = _encoded.result();
if (_encode_result.status != ZX_OK) {
CompleterBase::Close(ZX_ERR_INTERNAL);
return;
}
CompleterBase::SendReply(std::move(_encode_result.message));
}
void SimpleProtocol::Interface::AddCompleterBase::Reply(
::fidl::BytePart _buffer, int32_t sum) {
if (_buffer.capacity() < AddResponse::PrimarySize) {
CompleterBase::Close(ZX_ERR_INTERNAL);
return;
}
new (_buffer.data()) AddResponse{sum};
_buffer.set_actual(sizeof(AddResponse));
CompleterBase::SendReply(
::fidl::DecodedMessage<AddResponse>(std::move(_buffer)));
}
void SimpleProtocol::Interface::AddCompleterBase::Reply(
::fidl::DecodedMessage<AddResponse> params) {
ZX_DEBUG_ASSERT(params.message()->_hdr.magic_number ==
kFidlWireFormatMagicNumberInitial);
ZX_DEBUG_ASSERT(params.message()->_hdr.ordinal ==
kSimpleProtocol_Add_Ordinal);
CompleterBase::SendReply(std::move(params));
}
void SimpleProtocol::AddRequest::_InitHeader(zx_txid_t _txid) {
fidl_init_txn_header(&_hdr, _txid, kSimpleProtocol_Add_Ordinal);
}
void SimpleProtocol::AddResponse::_InitHeader() {
fidl_init_txn_header(&_hdr, 0, kSimpleProtocol_Add_Ordinal);
}
void ::llcpp::fidl::test::nullable::SimpleUnion::
SizeAndOffsetAssertionHelper() {
static_assert(sizeof(SimpleUnion) == sizeof(fidl_xunion_t));
static_assert(offsetof(SimpleUnion, ordinal_) ==
offsetof(fidl_xunion_t, tag));
static_assert(offsetof(SimpleUnion, envelope_) ==
offsetof(fidl_xunion_t, envelope));
}
} // namespace nullable
} // namespace test
} // namespace fidl
} // namespace llcpp