blob: b91fd7374f37372d59e88729f052c96b8b00dad8 [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <doc_comments.test.json.llcpp.h>
#include <memory>
namespace llcpp {
namespace test {
namespace name {
void ::llcpp::test::name::Union::SizeAndOffsetAssertionHelper() {
static_assert(sizeof(Union) == sizeof(fidl_xunion_t));
static_assert(offsetof(Union, ordinal_) == offsetof(fidl_xunion_t, tag));
static_assert(offsetof(Union, envelope_) ==
offsetof(fidl_xunion_t, envelope));
}
namespace {
[[maybe_unused]] constexpr uint64_t kInterface_Method_Ordinal =
0x3f43684c00000000lu;
[[maybe_unused]] constexpr uint64_t kInterface_Method_GenOrdinal =
0x60e700e002995ef8lu;
extern "C" const fidl_type_t v1_test_name_InterfaceMethodRequestTable;
extern "C" const fidl_type_t v1_test_name_InterfaceMethodResponseTable;
[[maybe_unused]] constexpr uint64_t kInterface_OnEvent_Ordinal =
0x136d200d00000000lu;
[[maybe_unused]] constexpr uint64_t kInterface_OnEvent_GenOrdinal =
0x914c226136244edlu;
extern "C" const fidl_type_t v1_test_name_InterfaceOnEventRequestTable;
extern "C" const fidl_type_t v1_test_name_InterfaceOnEventEventTable;
} // namespace
Interface::ResultOf::Method_Impl::Method_Impl(
::zx::unowned_channel _client_end) {
constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<
MethodRequest, ::fidl::MessageDirection::kSending>();
::fidl::internal::AlignedBuffer<_kWriteAllocSize> _write_bytes_inlined;
auto& _write_bytes_array = _write_bytes_inlined;
uint8_t* _write_bytes = _write_bytes_array.view().data();
memset(_write_bytes, 0, MethodRequest::PrimarySize);
::fidl::BytePart _request_bytes(_write_bytes, _kWriteAllocSize,
sizeof(MethodRequest));
::fidl::DecodedMessage<MethodRequest> _decoded_request(
std::move(_request_bytes));
Super::operator=(Interface::InPlace::Method(std::move(_client_end)));
}
Interface::ResultOf::Method Interface::SyncClient::Method() {
return ResultOf::Method(::zx::unowned_channel(this->channel_));
}
Interface::ResultOf::Method Interface::Call::Method(
::zx::unowned_channel _client_end) {
return ResultOf::Method(std::move(_client_end));
}
::fidl::internal::StatusAndError Interface::InPlace::Method(
::zx::unowned_channel _client_end) {
constexpr uint32_t _write_num_bytes = sizeof(MethodRequest);
::fidl::internal::AlignedBuffer<_write_num_bytes> _write_bytes;
::fidl::BytePart _request_buffer = _write_bytes.view();
_request_buffer.set_actual(_write_num_bytes);
::fidl::DecodedMessage<MethodRequest> params(std::move(_request_buffer));
Interface::SetTransactionHeaderFor::MethodRequest(params);
auto _encode_request_result = ::fidl::Encode(std::move(params));
if (_encode_request_result.status != ZX_OK) {
return ::fidl::internal::StatusAndError::FromFailure(
std::move(_encode_request_result));
}
zx_status_t _write_status = ::fidl::Write(
std::move(_client_end), std::move(_encode_request_result.message));
if (_write_status != ZX_OK) {
return ::fidl::internal::StatusAndError(
_write_status, ::fidl::internal::kErrorWriteFailed);
} else {
return ::fidl::internal::StatusAndError(ZX_OK, nullptr);
}
}
zx_status_t Interface::SyncClient::HandleEvents(
Interface::EventHandlers handlers) {
return Interface::Call::HandleEvents(::zx::unowned_channel(channel_),
std::move(handlers));
}
zx_status_t Interface::Call::HandleEvents(::zx::unowned_channel client_end,
Interface::EventHandlers handlers) {
zx_status_t status =
client_end->wait_one(ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED,
::zx::time::infinite(), nullptr);
if (status != ZX_OK) {
return status;
}
constexpr uint32_t kReadAllocSize = ([]() constexpr {
uint32_t x = 0;
if (::fidl::internal::ClampedMessageSize<
OnEventResponse, ::fidl::MessageDirection::kReceiving>() >= x) {
x = ::fidl::internal::ClampedMessageSize<
OnEventResponse, ::fidl::MessageDirection::kReceiving>();
}
return x;
})();
constexpr uint32_t kHandleAllocSize = ([]() constexpr {
uint32_t x = 0;
if (OnEventResponse::MaxNumHandles >= x) {
x = OnEventResponse::MaxNumHandles;
}
if (x > ZX_CHANNEL_MAX_MSG_HANDLES) {
x = ZX_CHANNEL_MAX_MSG_HANDLES;
}
return x;
})();
::fidl::internal::ByteStorage<kReadAllocSize> read_storage;
uint8_t* read_bytes = read_storage.buffer().data();
zx_handle_t read_handles[kHandleAllocSize];
uint32_t actual_bytes;
uint32_t actual_handles;
status = client_end->read(ZX_CHANNEL_READ_MAY_DISCARD, read_bytes,
read_handles, kReadAllocSize, kHandleAllocSize,
&actual_bytes, &actual_handles);
if (status == ZX_ERR_BUFFER_TOO_SMALL) {
// Message size is unexpectedly larger than calculated.
// This can only be due to a newer version of the protocol defining a new
// event, whose size exceeds the maximum of known events in the current
// protocol.
return handlers.unknown();
}
if (status != ZX_OK) {
return status;
}
if (actual_bytes < sizeof(fidl_message_header_t)) {
zx_handle_close_many(read_handles, actual_handles);
return ZX_ERR_INVALID_ARGS;
}
auto msg = fidl_msg_t{.bytes = read_bytes,
.handles = read_handles,
.num_bytes = actual_bytes,
.num_handles = actual_handles};
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(msg.bytes);
status = fidl_validate_txn_header(hdr);
if (status != ZX_OK) {
return status;
}
switch (hdr->ordinal) {
case kInterface_OnEvent_Ordinal:
case kInterface_OnEvent_GenOrdinal: {
auto result = ::fidl::DecodeAs<OnEventResponse>(&msg);
if (result.status != ZX_OK) {
return result.status;
}
return handlers.on_event();
}
default:
zx_handle_close_many(read_handles, actual_handles);
return handlers.unknown();
}
}
bool Interface::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 kInterface_Method_Ordinal:
case kInterface_Method_GenOrdinal: {
auto result = ::fidl::DecodeAs<MethodRequest>(msg);
if (result.status != ZX_OK) {
txn->Close(ZX_ERR_INVALID_ARGS);
return true;
}
impl->Method(Interface::MethodCompleter::Sync(txn));
return true;
}
default: {
return false;
}
}
}
bool Interface::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;
}
zx_status_t Interface::SendOnEventEvent(::zx::unowned_channel _chan) {
constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize<
OnEventResponse, ::fidl::MessageDirection::kSending>();
FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {};
auto& _response = *reinterpret_cast<OnEventResponse*>(_write_bytes);
Interface::SetTransactionHeaderFor::OnEventResponse(
::fidl::DecodedMessage<OnEventResponse>(::fidl::BytePart(
reinterpret_cast<uint8_t*>(&_response), OnEventResponse::PrimarySize,
OnEventResponse::PrimarySize)));
::fidl::BytePart _response_bytes(_write_bytes, _kWriteAllocSize,
sizeof(OnEventResponse));
return ::fidl::Write(
::zx::unowned_channel(_chan),
::fidl::DecodedMessage<OnEventResponse>(std::move(_response_bytes)));
}
void Interface::SetTransactionHeaderFor::MethodRequest(
const ::fidl::DecodedMessage<Interface::MethodRequest>& _msg) {
fidl_init_txn_header(&_msg.message()->_hdr, 0, kInterface_Method_GenOrdinal);
_msg.message()->_hdr.flags[0] |= FIDL_TXN_HEADER_UNION_FROM_XUNION_FLAG;
}
void Interface::SetTransactionHeaderFor::OnEventResponse(
const ::fidl::DecodedMessage<Interface::OnEventResponse>& _msg) {
fidl_init_txn_header(&_msg.message()->_hdr, 0, kInterface_OnEvent_GenOrdinal);
_msg.message()->_hdr.flags[0] |= FIDL_TXN_HEADER_UNION_FROM_XUNION_FLAG;
}
} // namespace name
} // namespace test
} // namespace llcpp