blob: 6a65918241c8d821f44f2aeee875b0c1f6268409 [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <fidl/test/doccomments/llcpp/fidl.h>
#include <memory>
namespace llcpp {
namespace fidl {
namespace test {
namespace doccomments {
void ::llcpp::fidl::test::doccomments::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 {
[[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
Interface::ResultOf::Method::Method(zx_handle_t _client) {
MethodRequest::OwnedEncodedMessage _request(zx_txid_t(0));
_request.GetOutgoingMessage().Write(_client);
status_ = _request.status();
error_ = _request.error();
}
::fidl::Result Interface::ClientImpl::Method() {
if (auto _channel = ::fidl::internal::ClientBase::GetChannel()) {
auto _res = ResultOf::Method(_channel->handle());
return ::fidl::Result(_res.status(), _res.error());
}
return ::fidl::Result(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound);
}
std::optional<::fidl::UnbindInfo> Interface::ClientImpl::DispatchEvent(
fidl_incoming_msg_t* msg) {
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};
}
if (!handlers_.on_event) {
return ::fidl::UnbindInfo{::fidl::UnbindInfo::kUnexpectedMessage,
ZX_ERR_NOT_SUPPORTED};
}
handlers_.on_event();
break;
}
default:
FidlHandleInfoCloseMany(msg->handles, msg->num_handles);
return ::fidl::UnbindInfo{::fidl::UnbindInfo::kUnexpectedMessage,
ZX_ERR_NOT_SUPPORTED};
}
return {};
}
::fidl::Result Interface::EventHandler::HandleOneEvent(
::zx::unowned_channel client_end) {
zx_status_t status =
client_end->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->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);
}
}
}
namespace methods {
void InterfaceDispatchMethod(void* interface, void* bytes,
::fidl::Transaction* txn) {
Interface::Interface::MethodCompleter::Sync completer(txn);
reinterpret_cast<Interface::Interface*>(interface)->Method(completer);
}
} // namespace methods
namespace entries {
::fidl::internal::MethodEntry Interface[] = {
{kInterface_Method_Ordinal, 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));
}
::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);
}
void Interface::MethodRequest::_InitHeader(zx_txid_t _txid) {
fidl_init_txn_header(&_hdr, _txid, kInterface_Method_Ordinal);
}
void Interface::OnEventResponse::_InitHeader() {
fidl_init_txn_header(&_hdr, 0, kInterface_OnEvent_Ordinal);
}
zx_status_t Interface::EventSender::OnEvent() const {
OnEventResponse::OwnedEncodedMessage _response{};
_response.Write(server_end_.get());
return _response.status();
}
auto ::llcpp::fidl::test::doccomments::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::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