blob: 0a32061d6c6724713dd4fef574815dead49b919d [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <fidl/test/nullable/llcpp/fidl.h>
#include <memory>
namespace llcpp {
namespace fidl {
namespace test {
namespace nullable {
#ifdef __Fuchsia__
void StructWithNullableRequest::_CloseHandles() { val.reset(); }
#endif // __Fuchsia__
#ifdef __Fuchsia__
void StructWithNullableProtocol::_CloseHandles() { val.reset(); }
#endif // __Fuchsia__
#ifdef __Fuchsia__
void StructWithNullableHandle::_CloseHandles() { val.reset(); }
#endif // __Fuchsia__
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
SimpleProtocol::ResultOf::Add::Add(zx_handle_t _client, int32_t a, int32_t b) {
AddRequest::OwnedEncodedMessage _request(zx_txid_t(0), a, b);
_request.GetOutgoingMessage().Call<AddResponse>(
_client, bytes_, AddResponse::PrimarySize + AddResponse::MaxOutOfLine);
status_ = _request.status();
error_ = _request.error();
}
SimpleProtocol::ResultOf::Add::Add(zx_handle_t _client, int32_t a, int32_t b,
zx_time_t _deadline) {
AddRequest::OwnedEncodedMessage _request(zx_txid_t(0), a, b);
_request.GetOutgoingMessage().Call<AddResponse>(
_client, bytes_, AddResponse::PrimarySize + AddResponse::MaxOutOfLine,
_deadline);
status_ = _request.status();
error_ = _request.error();
}
SimpleProtocol::UnownedResultOf::Add::Add(zx_handle_t _client,
uint8_t* _request_bytes,
uint32_t _request_byte_capacity,
int32_t a, int32_t b,
uint8_t* _response_bytes,
uint32_t _response_byte_capacity)
: bytes_(_response_bytes) {
AddRequest::UnownedEncodedMessage _request(_request_bytes,
_request_byte_capacity, 0, a, b);
_request.GetOutgoingMessage().Call<AddResponse>(_client, _response_bytes,
_response_byte_capacity);
status_ = _request.status();
error_ = _request.error();
}
SimpleProtocol::ResultOf::Add SimpleProtocol::ClientImpl::Add_Sync(int32_t a,
int32_t b) {
if (auto _channel = ::fidl::internal::ClientBase::GetChannel()) {
return ResultOf::Add(_channel->handle(), a, b);
}
return SimpleProtocol::ResultOf::Add(
::fidl::Result(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound));
}
SimpleProtocol::UnownedResultOf::Add SimpleProtocol::ClientImpl::Add_Sync(
::fidl::BufferSpan _request_buffer, int32_t a, int32_t b,
::fidl::BufferSpan _response_buffer) {
if (auto _channel = ::fidl::internal::ClientBase::GetChannel()) {
return UnownedResultOf::Add(
_channel->handle(), _request_buffer.data, _request_buffer.capacity, a,
b, _response_buffer.data, _response_buffer.capacity);
}
return SimpleProtocol::UnownedResultOf::Add(
::fidl::Result(ZX_ERR_CANCELED, ::fidl::kErrorChannelUnbound));
}
SimpleProtocol::AddResponseContext::AddResponseContext()
: ::fidl::internal::ResponseContext(AddResponse::Type,
kSimpleProtocol_Add_Ordinal) {}
void SimpleProtocol::AddResponseContext::OnReply(uint8_t* reply) {
OnReply(reinterpret_cast<AddResponse*>(reply));
}
::fidl::Result SimpleProtocol::ClientImpl::Add(
int32_t a, int32_t b, ::fit::callback<void(AddResponse* response)> _cb) {
class ResponseContext final : public AddResponseContext {
public:
ResponseContext(::fit::callback<void(AddResponse* response)> cb)
: cb_(std::move(cb)) {}
void OnReply(AddResponse* response) override {
cb_(response);
delete this;
}
void OnError() override { delete this; }
private:
::fit::callback<void(AddResponse* response)> cb_;
};
auto* _context = new ResponseContext(std::move(_cb));
::fidl::internal::ClientBase::PrepareAsyncTxn(_context);
AddRequest::OwnedEncodedMessage _request(_context->Txid(), a, b);
return _request.GetOutgoingMessage().Write(this, _context);
}
::fidl::Result SimpleProtocol::ClientImpl::Add(
::fidl::BufferSpan _request_buffer, int32_t a, int32_t b,
AddResponseContext* _context) {
::fidl::internal::ClientBase::PrepareAsyncTxn(_context);
AddRequest::UnownedEncodedMessage _request(
_request_buffer.data, _request_buffer.capacity, _context->Txid(), a, b);
return _request.GetOutgoingMessage().Write(this, _context);
}
std::optional<::fidl::UnbindInfo> SimpleProtocol::ClientImpl::DispatchEvent(
fidl_incoming_msg_t* msg) {
fidl_message_header_t* hdr =
reinterpret_cast<fidl_message_header_t*>(msg->bytes);
switch (hdr->ordinal) {
default:
FidlHandleInfoCloseMany(msg->handles, msg->num_handles);
return ::fidl::UnbindInfo{::fidl::UnbindInfo::kUnexpectedMessage,
ZX_ERR_NOT_SUPPORTED};
}
return {};
}
namespace methods {
void SimpleProtocolDispatchAdd(void* interface, void* bytes,
::fidl::Transaction* txn) {
auto message = reinterpret_cast<SimpleProtocol::AddRequest*>(bytes);
SimpleProtocol::Interface::AddCompleter::Sync completer(txn);
reinterpret_cast<SimpleProtocol::Interface*>(interface)->Add(
std::move(message->a), std::move(message->b), completer);
}
} // namespace methods
namespace entries {
::fidl::internal::MethodEntry SimpleProtocol[] = {
{kSimpleProtocol_Add_Ordinal, SimpleProtocol::AddRequest::Type,
methods::SimpleProtocolDispatchAdd},
};
} // namespace entries
::fidl::DispatchResult SimpleProtocol::TryDispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) {
return ::fidl::internal::TryDispatch(
impl, msg, txn, entries::SimpleProtocol,
entries::SimpleProtocol + sizeof(entries::SimpleProtocol) /
sizeof(::fidl::internal::MethodEntry));
}
::fidl::DispatchResult SimpleProtocol::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 SimpleProtocol::Interface::dispatch_message(
fidl_incoming_msg_t* msg, ::fidl::Transaction* txn) {
return SimpleProtocol::Dispatch(this, msg, txn);
}
::fidl::Result SimpleProtocol::Interface::AddCompleterBase::Reply(int32_t sum) {
AddResponse::OwnedEncodedMessage _response{sum};
return CompleterBase::SendReply(&_response.GetOutgoingMessage());
}
::fidl::Result SimpleProtocol::Interface::AddCompleterBase::Reply(
::fidl::BufferSpan _buffer, int32_t sum) {
AddResponse::UnownedEncodedMessage _response(_buffer.data, _buffer.capacity,
sum);
return CompleterBase::SendReply(&_response.GetOutgoingMessage());
}
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