blob: f090b00cd702dcf16122fb5ebdf3bffc9cce04e7 [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <fidl/test/doccomments/llcpp/fidl.h>
#include <memory>
void ::llcpp::fidl::test::doccomments::wire::StrictUnion::
SizeAndOffsetAssertionHelper() {
static_assert(sizeof(StrictUnion) == sizeof(fidl_xunion_t));
static_assert(offsetof(StrictUnion, ordinal_) ==
offsetof(fidl_xunion_t, tag));
static_assert(offsetof(StrictUnion, envelope_) ==
offsetof(fidl_xunion_t, envelope));
}
namespace llcpp {
namespace fidl {
namespace test {
namespace doccomments {
namespace {
[[maybe_unused]] constexpr uint64_t kInterface_Method_Ordinal =
6649887292072346213lu;
extern "C" const fidl_type_t fidl_test_doccomments_InterfaceMethodRequestTable;
extern "C" const fidl_type_t fidl_test_doccomments_InterfaceMethodResponseTable;
[[maybe_unused]] constexpr uint64_t kInterface_OnEvent_Ordinal =
3999525675942213370lu;
extern "C" const fidl_type_t fidl_test_doccomments_InterfaceOnEventRequestTable;
extern "C" const fidl_type_t fidl_test_doccomments_InterfaceOnEventEventTable;
} // namespace
#ifdef __Fuchsia__
::llcpp::fidl::test::doccomments::Interface::ResultOf::Method::Method(
::fidl::UnownedClientEnd<::llcpp::fidl::test::doccomments::Interface>
_client) {
::fidl::internal::EncodedMessageTypes<MethodRequest>::OwnedByte _request(
zx_txid_t(0));
_request.GetOutgoingMessage().Write(_client);
status_ = _request.status();
error_ = _request.error();
}
#endif
#ifdef __Fuchsia__
::fidl::Result Interface::ClientImpl::Method() {
if (auto _channel = ::fidl::internal::ClientBase::GetChannel()) {
auto _res = ResultOf::Method(
::fidl::UnownedClientEnd<::llcpp::fidl::test::doccomments::Interface>(
_channel->handle()));
return ::fidl::Result(_res.status(), _res.error());
}
return ::fidl::Result(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound);
}
#endif
#ifdef __Fuchsia__
std::optional<::fidl::UnbindInfo> Interface::ClientImpl::DispatchEvent(
fidl_incoming_msg_t* msg) {
if (event_handler_ != nullptr) {
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(msg->bytes);
switch (hdr->ordinal) {
case kInterface_OnEvent_Ordinal: {
const char* error_message;
zx_status_t status =
fidl_decode_etc(OnEventResponse::Type, msg->bytes, msg->num_bytes,
msg->handles, msg->num_handles, &error_message);
if (status != ZX_OK) {
return ::fidl::UnbindInfo{::fidl::UnbindInfo::kDecodeError, status};
}
event_handler_->OnEvent(reinterpret_cast<OnEventResponse*>(msg->bytes));
return std::nullopt;
}
default:
break;
}
}
FidlHandleInfoCloseMany(msg->handles, msg->num_handles);
return ::fidl::UnbindInfo{::fidl::UnbindInfo::kUnexpectedMessage,
ZX_ERR_NOT_SUPPORTED};
}
#endif
::fidl::Result Interface::SyncEventHandler::HandleOneEvent(
::fidl::UnownedClientEnd<::llcpp::fidl::test::doccomments::Interface>
client_end) {
zx_status_t status = client_end.channel()->wait_one(
ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED, ::zx::time::infinite(),
nullptr);
if (status != ZX_OK) {
return ::fidl::Result(status, ::fidl::kErrorWaitOneFailed);
}
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.data();
zx_handle_info_t read_handles[kHandleAllocSize];
uint32_t actual_bytes;
uint32_t actual_handles;
status = client_end.channel()->read_etc(
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 ::fidl::Result(Unknown(), nullptr);
}
if (status != ZX_OK) {
return ::fidl::Result(status, ::fidl::kErrorReadFailed);
}
if (actual_bytes < sizeof(fidl_message_header_t)) {
FidlHandleInfoCloseMany(read_handles, actual_handles);
return ::fidl::Result(ZX_ERR_INVALID_ARGS, ::fidl::kErrorInvalidHeader);
}
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(read_bytes);
status = fidl_validate_txn_header(hdr);
if (status != ZX_OK) {
FidlHandleInfoCloseMany(read_handles, actual_handles);
return ::fidl::Result(status, ::fidl::kErrorInvalidHeader);
}
switch (hdr->ordinal) {
case kInterface_OnEvent_Ordinal: {
const char* error_message;
zx_status_t status =
fidl_decode_etc(OnEventResponse::Type, read_bytes, actual_bytes,
read_handles, actual_handles, &error_message);
if (status != ZX_OK) {
return ::fidl::Result(status, error_message);
}
OnEvent(reinterpret_cast<OnEventResponse*>(read_bytes));
return ::fidl::Result(ZX_OK, nullptr);
}
default: {
FidlHandleInfoCloseMany(read_handles, actual_handles);
return ::fidl::Result(Unknown(), nullptr);
}
}
}
#ifdef __Fuchsia__
namespace methods {
void InterfaceDispatchMethod(void* interface, void* bytes,
::fidl::Transaction* txn) {
::llcpp::fidl::test::doccomments::Interface::Interface::MethodCompleter::Sync
completer(txn);
reinterpret_cast<::llcpp::fidl::test::doccomments::Interface::Interface*>(
interface)
->Method(completer);
}
} // namespace methods
namespace entries {
::fidl::internal::MethodEntry Interface[] = {
{kInterface_Method_Ordinal,
::llcpp::fidl::test::doccomments::Interface::MethodRequest::Type,
methods::InterfaceDispatchMethod},
};
} // namespace entries
::fidl::DispatchResult Interface::TryDispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) {
return ::fidl::internal::TryDispatch(
impl, msg, txn, entries::Interface,
entries::Interface +
sizeof(entries::Interface) / sizeof(::fidl::internal::MethodEntry));
}
#endif
#ifdef __Fuchsia__
::fidl::DispatchResult Interface::Dispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) {
::fidl::DispatchResult dispatch_result = TryDispatch(impl, msg, txn);
if (dispatch_result == ::fidl::DispatchResult::kNotFound) {
FidlHandleInfoCloseMany(msg->handles, msg->num_handles);
txn->InternalError(
{::fidl::UnbindInfo::kUnexpectedMessage, ZX_ERR_NOT_SUPPORTED});
}
return dispatch_result;
}
::fidl::DispatchResult Interface::Interface::dispatch_message(
fidl_incoming_msg_t* msg, ::fidl::Transaction* txn) {
return Interface::Dispatch(this, msg, txn);
}
#endif
void ::llcpp::fidl::test::doccomments::Interface::MethodRequest::_InitHeader(
zx_txid_t _txid) {
fidl_init_txn_header(&_hdr, _txid, kInterface_Method_Ordinal);
}
void ::llcpp::fidl::test::doccomments::Interface::OnEventResponse::
_InitHeader() {
fidl_init_txn_header(&_hdr, 0, kInterface_OnEvent_Ordinal);
}
#ifdef __Fuchsia__
zx_status_t Interface::EventSender::OnEvent() const {
::fidl::internal::EncodedMessageTypes<OnEventResponse>::OwnedByte _response{};
_response.Write(server_end_);
return _response.status();
}
#endif
auto ::llcpp::fidl::test::doccomments::wire::FlexibleUnion::which() const
-> Tag {
ZX_ASSERT(!has_invalid_tag());
switch (ordinal_) {
case Ordinal::kField:
return static_cast<Tag>(ordinal_);
default:
return Tag::kUnknown;
}
}
void ::llcpp::fidl::test::doccomments::wire::FlexibleUnion::
SizeAndOffsetAssertionHelper() {
static_assert(sizeof(FlexibleUnion) == sizeof(fidl_xunion_t));
static_assert(offsetof(FlexibleUnion, ordinal_) ==
offsetof(fidl_xunion_t, tag));
static_assert(offsetof(FlexibleUnion, envelope_) ==
offsetof(fidl_xunion_t, envelope));
}
} // namespace doccomments
} // namespace test
} // namespace fidl
} // namespace llcpp