blob: 6ae685a3608683e347c9d24db4bed1eaa876830d [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#pragma once
#include <lib/fidl/internal.h>
#include <lib/fidl/llcpp/array.h>
#include <lib/fidl/llcpp/buffer_allocator.h>
#include <lib/fidl/llcpp/buffer_then_heap_allocator.h>
#include <lib/fidl/llcpp/coding.h>
#include <lib/fidl/llcpp/envelope.h>
#include <lib/fidl/llcpp/errors.h>
#include <lib/fidl/llcpp/memory.h>
#include <lib/fidl/llcpp/message.h>
#include <lib/fidl/llcpp/message_storage.h>
#include <lib/fidl/llcpp/string_view.h>
#include <lib/fidl/llcpp/tracking_ptr.h>
#include <lib/fidl/llcpp/traits.h>
#include <lib/fidl/llcpp/vector_view.h>
#include <lib/fit/function.h>
#include <lib/fit/optional.h>
#include <variant>
#ifdef __Fuchsia__
#include <lib/fidl/llcpp/client.h>
#include <lib/fidl/llcpp/connect_service.h>
#include <lib/fidl/llcpp/result.h>
#include <lib/fidl/llcpp/server.h>
#include <lib/fidl/llcpp/service_handler_interface.h>
#include <lib/fidl/llcpp/sync_call.h>
#include <lib/fidl/llcpp/transaction.h>
#include <lib/fidl/txn_header.h>
#include <lib/zx/channel.h>
#endif // __Fuchsia__
#include <zircon/fidl.h>
namespace llcpp {
namespace fidl {
namespace test {
namespace inheritance {
class super;
class sub;
extern "C" const fidl_type_t fidl_test_inheritance_superfooRequestTable;
extern "C" const fidl_type_t fidl_test_inheritance_superfooResponseTable;
class super final {
super() = delete;
public:
struct fooResponse final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
int64_t y;
explicit fooResponse(int64_t y) : y(y) { _InitHeader(); }
fooResponse() { _InitHeader(); }
static constexpr const fidl_type_t* Type =
&fidl_test_inheritance_superfooResponseTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 24;
static constexpr uint32_t MaxOutOfLine = 0;
static constexpr bool HasFlexibleEnvelope = false;
static constexpr bool HasPointer = false;
static constexpr ::fidl::internal::TransactionalMessageKind MessageKind =
::fidl::internal::TransactionalMessageKind::kResponse;
class UnownedEncodedMessage final {
public:
UnownedEncodedMessage(uint8_t* _bytes, uint32_t _byte_size, int64_t y)
: message_(_bytes, _byte_size, sizeof(fooResponse), nullptr, 0, 0) {
FIDL_ALIGNDECL fooResponse _response{y};
message_.LinearizeAndEncode<fooResponse>(&_response);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
fooResponse* response)
: message_(bytes, byte_size, sizeof(fooResponse), nullptr, 0, 0) {
message_.LinearizeAndEncode<fooResponse>(response);
}
UnownedEncodedMessage(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage(UnownedEncodedMessage&&) = delete;
UnownedEncodedMessage* operator=(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage* operator=(UnownedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.status() == ZX_OK; }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() { return message_; }
void Write(zx_handle_t client) { message_.Write(client); }
private:
fooResponse& Message() {
return *reinterpret_cast<fooResponse*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(int64_t y)
: message_(bytes_, sizeof(bytes_), y) {}
explicit OwnedEncodedMessage(fooResponse* response)
: message_(bytes_, sizeof(bytes_), response) {}
OwnedEncodedMessage(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage(OwnedEncodedMessage&&) = delete;
OwnedEncodedMessage* operator=(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage* operator=(OwnedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.ok(); }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() {
return message_.GetOutgoingMessage();
}
void Write(zx_handle_t client) { message_.Write(client); }
private:
FIDL_ALIGNDECL
uint8_t bytes_[PrimarySize + MaxOutOfLine];
UnownedEncodedMessage message_;
};
class DecodedMessage final : public ::fidl::internal::IncomingMessage {
public:
DecodedMessage(uint8_t* bytes, uint32_t byte_actual,
zx_handle_info_t* handles = nullptr,
uint32_t handle_actual = 0)
: ::fidl::internal::IncomingMessage(bytes, byte_actual, handles,
handle_actual) {
Decode<fooResponse>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<fooResponse>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
fooResponse* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes());
}
// Release the ownership of the decoded message. That means that the
// handles won't be closed When the object is destroyed. After calling
// this method, the DecodedMessage object should not be used anymore.
void ReleasePrimaryObject() { ResetBytes(); }
// These methods should only be used for testing purpose.
// They create an DecodedMessage using the bytes of an outgoing message
// and copying the handles.
static DecodedMessage FromOutgoingWithRawHandleCopy(
UnownedEncodedMessage* outgoing_message) {
return DecodedMessage(outgoing_message->GetOutgoingMessage());
}
static DecodedMessage FromOutgoingWithRawHandleCopy(
OwnedEncodedMessage* outgoing_message) {
return DecodedMessage(outgoing_message->GetOutgoingMessage());
}
private:
DecodedMessage(::fidl::OutgoingMessage& outgoing_message) {
Init(outgoing_message, nullptr, 0);
if (ok()) {
Decode<fooResponse>();
}
}
};
private:
void _InitHeader();
};
struct fooRequest final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
::fidl::StringView s;
explicit fooRequest(zx_txid_t _txid, const ::fidl::StringView& s)
: s(::fidl::unowned_ptr_t<const char>(s.data()), s.size()) {
_InitHeader(_txid);
}
explicit fooRequest(zx_txid_t _txid) { _InitHeader(_txid); }
static constexpr const fidl_type_t* Type =
&fidl_test_inheritance_superfooRequestTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 32;
static constexpr uint32_t MaxOutOfLine = 4294967295;
static constexpr uint32_t AltPrimarySize = 32;
static constexpr uint32_t AltMaxOutOfLine = 4294967295;
static constexpr bool HasFlexibleEnvelope = false;
static constexpr bool HasPointer = true;
static constexpr ::fidl::internal::TransactionalMessageKind MessageKind =
::fidl::internal::TransactionalMessageKind::kRequest;
using ResponseType = fooResponse;
class UnownedEncodedMessage final {
public:
UnownedEncodedMessage(uint8_t* _bytes, uint32_t _byte_size,
zx_txid_t _txid, const ::fidl::StringView& s)
: message_(_bytes, _byte_size, sizeof(fooRequest), nullptr, 0, 0) {
FIDL_ALIGNDECL fooRequest _request(_txid, s);
message_.LinearizeAndEncode<fooRequest>(&_request);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
fooRequest* request)
: message_(bytes, byte_size, sizeof(fooRequest), nullptr, 0, 0) {
message_.LinearizeAndEncode<fooRequest>(request);
}
UnownedEncodedMessage(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage(UnownedEncodedMessage&&) = delete;
UnownedEncodedMessage* operator=(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage* operator=(UnownedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.status() == ZX_OK; }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() { return message_; }
void Write(zx_handle_t client) { message_.Write(client); }
private:
fooRequest& Message() {
return *reinterpret_cast<fooRequest*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(zx_txid_t _txid, const ::fidl::StringView& s)
: bytes_(std::make_unique<::fidl::internal::AlignedBuffer<
ZX_CHANNEL_MAX_MSG_BYTES>>()),
message_(bytes_->data(), ZX_CHANNEL_MAX_MSG_BYTES, _txid, s) {}
explicit OwnedEncodedMessage(fooRequest* request)
: bytes_(std::make_unique<::fidl::internal::AlignedBuffer<
ZX_CHANNEL_MAX_MSG_BYTES>>()),
message_(bytes_->data(), ZX_CHANNEL_MAX_MSG_BYTES, request) {}
OwnedEncodedMessage(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage(OwnedEncodedMessage&&) = delete;
OwnedEncodedMessage* operator=(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage* operator=(OwnedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.ok(); }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() {
return message_.GetOutgoingMessage();
}
void Write(zx_handle_t client) { message_.Write(client); }
private:
std::unique_ptr<::fidl::internal::AlignedBuffer<ZX_CHANNEL_MAX_MSG_BYTES>>
bytes_;
UnownedEncodedMessage message_;
};
class DecodedMessage final : public ::fidl::internal::IncomingMessage {
public:
DecodedMessage(uint8_t* bytes, uint32_t byte_actual,
zx_handle_info_t* handles = nullptr,
uint32_t handle_actual = 0)
: ::fidl::internal::IncomingMessage(bytes, byte_actual, handles,
handle_actual) {
Decode<fooRequest>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<fooRequest>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
fooRequest* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooRequest*>(bytes());
}
// Release the ownership of the decoded message. That means that the
// handles won't be closed When the object is destroyed. After calling
// this method, the DecodedMessage object should not be used anymore.
void ReleasePrimaryObject() { ResetBytes(); }
// These methods should only be used for testing purpose.
// They create an DecodedMessage using the bytes of an outgoing message
// and copying the handles.
static DecodedMessage FromOutgoingWithRawHandleCopy(
UnownedEncodedMessage* encoded_message) {
return DecodedMessage(encoded_message->GetOutgoingMessage());
}
static DecodedMessage FromOutgoingWithRawHandleCopy(
OwnedEncodedMessage* encoded_message) {
return DecodedMessage(encoded_message->GetOutgoingMessage());
}
private:
DecodedMessage(::fidl::OutgoingMessage& outgoing_message) {
Init(outgoing_message, nullptr, 0);
if (ok()) {
Decode<fooRequest>();
}
}
};
private:
void _InitHeader(zx_txid_t _txid);
};
// Collection of return types of FIDL calls in this protocol.
class ResultOf final {
ResultOf() = delete;
public:
class foo final : public ::fidl::Result {
public:
explicit foo(zx_handle_t _client, const ::fidl::StringView& s);
foo(zx_handle_t _client, const ::fidl::StringView& s,
zx_time_t _deadline);
explicit foo(const ::fidl::Result& result) : ::fidl::Result(result) {}
foo(foo&&) = delete;
foo(const foo&) = delete;
foo* operator=(foo&&) = delete;
foo* operator=(const foo&) = delete;
~foo() = default;
fooResponse* Unwrap() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes_);
}
const fooResponse* Unwrap() const {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<const fooResponse*>(bytes_);
}
fooResponse& value() { return *Unwrap(); }
const fooResponse& value() const { return *Unwrap(); }
fooResponse* operator->() { return &value(); }
const fooResponse* operator->() const { return &value(); }
fooResponse& operator*() { return value(); }
const fooResponse& operator*() const { return value(); }
private:
FIDL_ALIGNDECL
uint8_t bytes_[fooResponse::PrimarySize + fooResponse::MaxOutOfLine];
};
};
// Collection of return types of FIDL calls in this protocol,
// when the caller-allocate flavor or in-place call is used.
class UnownedResultOf final {
UnownedResultOf() = delete;
public:
class foo final : public ::fidl::Result {
public:
explicit foo(zx_handle_t _client, uint8_t* _request_bytes,
uint32_t _request_byte_capacity, const ::fidl::StringView& s,
uint8_t* _response_bytes, uint32_t _response_byte_capacity);
explicit foo(const ::fidl::Result& result) : ::fidl::Result(result) {}
foo(foo&&) = delete;
foo(const foo&) = delete;
foo* operator=(foo&&) = delete;
foo* operator=(const foo&) = delete;
~foo() = default;
fooResponse* Unwrap() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes_);
}
const fooResponse* Unwrap() const {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<const fooResponse*>(bytes_);
}
fooResponse& value() { return *Unwrap(); }
const fooResponse& value() const { return *Unwrap(); }
fooResponse* operator->() { return &value(); }
const fooResponse* operator->() const { return &value(); }
fooResponse& operator*() { return value(); }
const fooResponse& operator*() const { return value(); }
private:
uint8_t* bytes_;
};
};
// Methods to make a sync FIDL call directly on an unowned channel, avoiding
// setting up a client.
class Call final {
Call() = delete;
public:
// Allocates 24 bytes of response buffer on the stack. Request is
// heap-allocated.
static ResultOf::foo foo(::zx::unowned_channel _client_end,
::fidl::StringView s) {
return ResultOf::foo(_client_end->get(), s);
}
// Caller provides the backing storage for FIDL message via request and
// response buffers.
static UnownedResultOf::foo foo(::zx::unowned_channel _client_end,
::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer) {
return UnownedResultOf::foo(
_client_end->get(), _request_buffer.data, _request_buffer.capacity, s,
_response_buffer.data, _response_buffer.capacity);
}
};
class SyncClient final {
public:
SyncClient() = default;
explicit SyncClient(::zx::channel channel) : channel_(std::move(channel)) {}
~SyncClient() = default;
SyncClient(SyncClient&&) = default;
SyncClient& operator=(SyncClient&&) = default;
const ::zx::channel& channel() const { return channel_; }
::zx::channel* mutable_channel() { return &channel_; }
// Allocates 24 bytes of response buffer on the stack. Request is
// heap-allocated.
ResultOf::foo foo(::fidl::StringView s) {
return ResultOf::foo(this->channel().get(), s);
}
// Caller provides the backing storage for FIDL message via request and
// response buffers.
UnownedResultOf::foo foo(::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer) {
return UnownedResultOf::foo(
this->channel().get(), _request_buffer.data, _request_buffer.capacity,
s, _response_buffer.data, _response_buffer.capacity);
}
private:
::zx::channel channel_;
};
struct AsyncEventHandlers;
class fooResponseContext;
class ClientImpl;
// Pure-virtual interface to be implemented by a server.
class Interface : public ::fidl::internal::IncomingMessageDispatcher {
public:
Interface() = default;
virtual ~Interface() = default;
// The marker protocol type within which this |Interface| class is defined.
using _EnclosingProtocol = super;
class fooCompleterBase : public ::fidl::CompleterBase {
public:
// In the following methods, the return value indicates internal errors
// during the reply, such as encoding or writing to the transport. Note
// that any error will automatically lead to the destruction of the
// binding, after which the |on_unbound| callback will be triggered with a
// detailed reason.
//
// See //zircon/system/ulib/fidl/include/lib/fidl/llcpp/server.h.
//
// Because the reply status is identical to the unbinding status, it can
// be safely ignored.
::fidl::Result Reply(int64_t y);
::fidl::Result Reply(::fidl::BufferSpan _buffer, int64_t y);
protected:
using ::fidl::CompleterBase::CompleterBase;
};
using fooCompleter = ::fidl::Completer<fooCompleterBase>;
virtual void foo(::fidl::StringView s, fooCompleter::Sync& _completer) = 0;
private:
::fidl::DispatchResult dispatch_message(fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) final;
};
// Attempts to dispatch the incoming message to a handler function in the
// server implementation. If there is no matching handler, it returns false,
// leaving the message and transaction intact. In all other cases, it consumes
// the message and returns true. It is possible to chain multiple TryDispatch
// functions in this manner.
static ::fidl::DispatchResult TryDispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn);
// Dispatches the incoming message to one of the handlers functions in the
// protocol. If there is no matching handler, it closes all the handles in
// |msg| and closes the channel with a |ZX_ERR_NOT_SUPPORTED| epitaph, before
// returning false. The message should then be discarded.
static ::fidl::DispatchResult Dispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn);
// Same as |Dispatch|, but takes a |void*| instead of |Interface*|.
// Only used with |fidl::BindServer| to reduce template expansion.
// Do not call this method manually. Use |Dispatch| instead.
static ::fidl::DispatchResult TypeErasedDispatch(void* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) {
return Dispatch(static_cast<Interface*>(impl), msg, txn);
}
class EventSender;
class WeakEventSender;
};
extern "C" const fidl_type_t fidl_test_inheritance_subfooRequestTable;
extern "C" const fidl_type_t fidl_test_inheritance_subfooResponseTable;
class sub final {
sub() = delete;
public:
struct fooResponse final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
int64_t y;
explicit fooResponse(int64_t y) : y(y) { _InitHeader(); }
fooResponse() { _InitHeader(); }
static constexpr const fidl_type_t* Type =
&fidl_test_inheritance_subfooResponseTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 24;
static constexpr uint32_t MaxOutOfLine = 0;
static constexpr bool HasFlexibleEnvelope = false;
static constexpr bool HasPointer = false;
static constexpr ::fidl::internal::TransactionalMessageKind MessageKind =
::fidl::internal::TransactionalMessageKind::kResponse;
class UnownedEncodedMessage final {
public:
UnownedEncodedMessage(uint8_t* _bytes, uint32_t _byte_size, int64_t y)
: message_(_bytes, _byte_size, sizeof(fooResponse), nullptr, 0, 0) {
FIDL_ALIGNDECL fooResponse _response{y};
message_.LinearizeAndEncode<fooResponse>(&_response);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
fooResponse* response)
: message_(bytes, byte_size, sizeof(fooResponse), nullptr, 0, 0) {
message_.LinearizeAndEncode<fooResponse>(response);
}
UnownedEncodedMessage(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage(UnownedEncodedMessage&&) = delete;
UnownedEncodedMessage* operator=(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage* operator=(UnownedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.status() == ZX_OK; }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() { return message_; }
void Write(zx_handle_t client) { message_.Write(client); }
private:
fooResponse& Message() {
return *reinterpret_cast<fooResponse*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(int64_t y)
: message_(bytes_, sizeof(bytes_), y) {}
explicit OwnedEncodedMessage(fooResponse* response)
: message_(bytes_, sizeof(bytes_), response) {}
OwnedEncodedMessage(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage(OwnedEncodedMessage&&) = delete;
OwnedEncodedMessage* operator=(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage* operator=(OwnedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.ok(); }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() {
return message_.GetOutgoingMessage();
}
void Write(zx_handle_t client) { message_.Write(client); }
private:
FIDL_ALIGNDECL
uint8_t bytes_[PrimarySize + MaxOutOfLine];
UnownedEncodedMessage message_;
};
class DecodedMessage final : public ::fidl::internal::IncomingMessage {
public:
DecodedMessage(uint8_t* bytes, uint32_t byte_actual,
zx_handle_info_t* handles = nullptr,
uint32_t handle_actual = 0)
: ::fidl::internal::IncomingMessage(bytes, byte_actual, handles,
handle_actual) {
Decode<fooResponse>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<fooResponse>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
fooResponse* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes());
}
// Release the ownership of the decoded message. That means that the
// handles won't be closed When the object is destroyed. After calling
// this method, the DecodedMessage object should not be used anymore.
void ReleasePrimaryObject() { ResetBytes(); }
// These methods should only be used for testing purpose.
// They create an DecodedMessage using the bytes of an outgoing message
// and copying the handles.
static DecodedMessage FromOutgoingWithRawHandleCopy(
UnownedEncodedMessage* outgoing_message) {
return DecodedMessage(outgoing_message->GetOutgoingMessage());
}
static DecodedMessage FromOutgoingWithRawHandleCopy(
OwnedEncodedMessage* outgoing_message) {
return DecodedMessage(outgoing_message->GetOutgoingMessage());
}
private:
DecodedMessage(::fidl::OutgoingMessage& outgoing_message) {
Init(outgoing_message, nullptr, 0);
if (ok()) {
Decode<fooResponse>();
}
}
};
private:
void _InitHeader();
};
struct fooRequest final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
::fidl::StringView s;
explicit fooRequest(zx_txid_t _txid, const ::fidl::StringView& s)
: s(::fidl::unowned_ptr_t<const char>(s.data()), s.size()) {
_InitHeader(_txid);
}
explicit fooRequest(zx_txid_t _txid) { _InitHeader(_txid); }
static constexpr const fidl_type_t* Type =
&fidl_test_inheritance_subfooRequestTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 32;
static constexpr uint32_t MaxOutOfLine = 4294967295;
static constexpr uint32_t AltPrimarySize = 32;
static constexpr uint32_t AltMaxOutOfLine = 4294967295;
static constexpr bool HasFlexibleEnvelope = false;
static constexpr bool HasPointer = true;
static constexpr ::fidl::internal::TransactionalMessageKind MessageKind =
::fidl::internal::TransactionalMessageKind::kRequest;
using ResponseType = fooResponse;
class UnownedEncodedMessage final {
public:
UnownedEncodedMessage(uint8_t* _bytes, uint32_t _byte_size,
zx_txid_t _txid, const ::fidl::StringView& s)
: message_(_bytes, _byte_size, sizeof(fooRequest), nullptr, 0, 0) {
FIDL_ALIGNDECL fooRequest _request(_txid, s);
message_.LinearizeAndEncode<fooRequest>(&_request);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
fooRequest* request)
: message_(bytes, byte_size, sizeof(fooRequest), nullptr, 0, 0) {
message_.LinearizeAndEncode<fooRequest>(request);
}
UnownedEncodedMessage(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage(UnownedEncodedMessage&&) = delete;
UnownedEncodedMessage* operator=(const UnownedEncodedMessage&) = delete;
UnownedEncodedMessage* operator=(UnownedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.status() == ZX_OK; }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() { return message_; }
void Write(zx_handle_t client) { message_.Write(client); }
private:
fooRequest& Message() {
return *reinterpret_cast<fooRequest*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(zx_txid_t _txid, const ::fidl::StringView& s)
: bytes_(std::make_unique<::fidl::internal::AlignedBuffer<
ZX_CHANNEL_MAX_MSG_BYTES>>()),
message_(bytes_->data(), ZX_CHANNEL_MAX_MSG_BYTES, _txid, s) {}
explicit OwnedEncodedMessage(fooRequest* request)
: bytes_(std::make_unique<::fidl::internal::AlignedBuffer<
ZX_CHANNEL_MAX_MSG_BYTES>>()),
message_(bytes_->data(), ZX_CHANNEL_MAX_MSG_BYTES, request) {}
OwnedEncodedMessage(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage(OwnedEncodedMessage&&) = delete;
OwnedEncodedMessage* operator=(const OwnedEncodedMessage&) = delete;
OwnedEncodedMessage* operator=(OwnedEncodedMessage&&) = delete;
zx_status_t status() const { return message_.status(); }
#ifdef __Fuchsia__
const char* status_string() const { return message_.status_string(); }
#endif
bool ok() const { return message_.ok(); }
const char* error() const { return message_.error(); }
::fidl::OutgoingMessage& GetOutgoingMessage() {
return message_.GetOutgoingMessage();
}
void Write(zx_handle_t client) { message_.Write(client); }
private:
std::unique_ptr<::fidl::internal::AlignedBuffer<ZX_CHANNEL_MAX_MSG_BYTES>>
bytes_;
UnownedEncodedMessage message_;
};
class DecodedMessage final : public ::fidl::internal::IncomingMessage {
public:
DecodedMessage(uint8_t* bytes, uint32_t byte_actual,
zx_handle_info_t* handles = nullptr,
uint32_t handle_actual = 0)
: ::fidl::internal::IncomingMessage(bytes, byte_actual, handles,
handle_actual) {
Decode<fooRequest>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<fooRequest>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
fooRequest* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooRequest*>(bytes());
}
// Release the ownership of the decoded message. That means that the
// handles won't be closed When the object is destroyed. After calling
// this method, the DecodedMessage object should not be used anymore.
void ReleasePrimaryObject() { ResetBytes(); }
// These methods should only be used for testing purpose.
// They create an DecodedMessage using the bytes of an outgoing message
// and copying the handles.
static DecodedMessage FromOutgoingWithRawHandleCopy(
UnownedEncodedMessage* encoded_message) {
return DecodedMessage(encoded_message->GetOutgoingMessage());
}
static DecodedMessage FromOutgoingWithRawHandleCopy(
OwnedEncodedMessage* encoded_message) {
return DecodedMessage(encoded_message->GetOutgoingMessage());
}
private:
DecodedMessage(::fidl::OutgoingMessage& outgoing_message) {
Init(outgoing_message, nullptr, 0);
if (ok()) {
Decode<fooRequest>();
}
}
};
private:
void _InitHeader(zx_txid_t _txid);
};
// Collection of return types of FIDL calls in this protocol.
class ResultOf final {
ResultOf() = delete;
public:
class foo final : public ::fidl::Result {
public:
explicit foo(zx_handle_t _client, const ::fidl::StringView& s);
foo(zx_handle_t _client, const ::fidl::StringView& s,
zx_time_t _deadline);
explicit foo(const ::fidl::Result& result) : ::fidl::Result(result) {}
foo(foo&&) = delete;
foo(const foo&) = delete;
foo* operator=(foo&&) = delete;
foo* operator=(const foo&) = delete;
~foo() = default;
fooResponse* Unwrap() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes_);
}
const fooResponse* Unwrap() const {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<const fooResponse*>(bytes_);
}
fooResponse& value() { return *Unwrap(); }
const fooResponse& value() const { return *Unwrap(); }
fooResponse* operator->() { return &value(); }
const fooResponse* operator->() const { return &value(); }
fooResponse& operator*() { return value(); }
const fooResponse& operator*() const { return value(); }
private:
FIDL_ALIGNDECL
uint8_t bytes_[fooResponse::PrimarySize + fooResponse::MaxOutOfLine];
};
};
// Collection of return types of FIDL calls in this protocol,
// when the caller-allocate flavor or in-place call is used.
class UnownedResultOf final {
UnownedResultOf() = delete;
public:
class foo final : public ::fidl::Result {
public:
explicit foo(zx_handle_t _client, uint8_t* _request_bytes,
uint32_t _request_byte_capacity, const ::fidl::StringView& s,
uint8_t* _response_bytes, uint32_t _response_byte_capacity);
explicit foo(const ::fidl::Result& result) : ::fidl::Result(result) {}
foo(foo&&) = delete;
foo(const foo&) = delete;
foo* operator=(foo&&) = delete;
foo* operator=(const foo&) = delete;
~foo() = default;
fooResponse* Unwrap() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<fooResponse*>(bytes_);
}
const fooResponse* Unwrap() const {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<const fooResponse*>(bytes_);
}
fooResponse& value() { return *Unwrap(); }
const fooResponse& value() const { return *Unwrap(); }
fooResponse* operator->() { return &value(); }
const fooResponse* operator->() const { return &value(); }
fooResponse& operator*() { return value(); }
const fooResponse& operator*() const { return value(); }
private:
uint8_t* bytes_;
};
};
// Methods to make a sync FIDL call directly on an unowned channel, avoiding
// setting up a client.
class Call final {
Call() = delete;
public:
// Allocates 24 bytes of response buffer on the stack. Request is
// heap-allocated.
static ResultOf::foo foo(::zx::unowned_channel _client_end,
::fidl::StringView s) {
return ResultOf::foo(_client_end->get(), s);
}
// Caller provides the backing storage for FIDL message via request and
// response buffers.
static UnownedResultOf::foo foo(::zx::unowned_channel _client_end,
::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer) {
return UnownedResultOf::foo(
_client_end->get(), _request_buffer.data, _request_buffer.capacity, s,
_response_buffer.data, _response_buffer.capacity);
}
};
class SyncClient final {
public:
SyncClient() = default;
explicit SyncClient(::zx::channel channel) : channel_(std::move(channel)) {}
~SyncClient() = default;
SyncClient(SyncClient&&) = default;
SyncClient& operator=(SyncClient&&) = default;
const ::zx::channel& channel() const { return channel_; }
::zx::channel* mutable_channel() { return &channel_; }
// Allocates 24 bytes of response buffer on the stack. Request is
// heap-allocated.
ResultOf::foo foo(::fidl::StringView s) {
return ResultOf::foo(this->channel().get(), s);
}
// Caller provides the backing storage for FIDL message via request and
// response buffers.
UnownedResultOf::foo foo(::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer) {
return UnownedResultOf::foo(
this->channel().get(), _request_buffer.data, _request_buffer.capacity,
s, _response_buffer.data, _response_buffer.capacity);
}
private:
::zx::channel channel_;
};
struct AsyncEventHandlers;
class fooResponseContext;
class ClientImpl;
// Pure-virtual interface to be implemented by a server.
class Interface : public ::fidl::internal::IncomingMessageDispatcher {
public:
Interface() = default;
virtual ~Interface() = default;
// The marker protocol type within which this |Interface| class is defined.
using _EnclosingProtocol = sub;
class fooCompleterBase : public ::fidl::CompleterBase {
public:
// In the following methods, the return value indicates internal errors
// during the reply, such as encoding or writing to the transport. Note
// that any error will automatically lead to the destruction of the
// binding, after which the |on_unbound| callback will be triggered with a
// detailed reason.
//
// See //zircon/system/ulib/fidl/include/lib/fidl/llcpp/server.h.
//
// Because the reply status is identical to the unbinding status, it can
// be safely ignored.
::fidl::Result Reply(int64_t y);
::fidl::Result Reply(::fidl::BufferSpan _buffer, int64_t y);
protected:
using ::fidl::CompleterBase::CompleterBase;
};
using fooCompleter = ::fidl::Completer<fooCompleterBase>;
virtual void foo(::fidl::StringView s, fooCompleter::Sync& _completer) = 0;
private:
::fidl::DispatchResult dispatch_message(fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) final;
};
// Attempts to dispatch the incoming message to a handler function in the
// server implementation. If there is no matching handler, it returns false,
// leaving the message and transaction intact. In all other cases, it consumes
// the message and returns true. It is possible to chain multiple TryDispatch
// functions in this manner.
static ::fidl::DispatchResult TryDispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn);
// Dispatches the incoming message to one of the handlers functions in the
// protocol. If there is no matching handler, it closes all the handles in
// |msg| and closes the channel with a |ZX_ERR_NOT_SUPPORTED| epitaph, before
// returning false. The message should then be discarded.
static ::fidl::DispatchResult Dispatch(Interface* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn);
// Same as |Dispatch|, but takes a |void*| instead of |Interface*|.
// Only used with |fidl::BindServer| to reduce template expansion.
// Do not call this method manually. Use |Dispatch| instead.
static ::fidl::DispatchResult TypeErasedDispatch(void* impl,
fidl_incoming_msg_t* msg,
::fidl::Transaction* txn) {
return Dispatch(static_cast<Interface*>(impl), msg, txn);
}
class EventSender;
class WeakEventSender;
};
} // namespace inheritance
} // namespace test
} // namespace fidl
} // namespace llcpp
namespace fidl {
template <>
struct IsFidlType<::llcpp::fidl::test::inheritance::super::fooRequest>
: public std::true_type {};
template <>
struct IsFidlMessage<::llcpp::fidl::test::inheritance::super::fooRequest>
: public std::true_type {};
static_assert(sizeof(::llcpp::fidl::test::inheritance::super::fooRequest) ==
::llcpp::fidl::test::inheritance::super::fooRequest::PrimarySize);
static_assert(offsetof(::llcpp::fidl::test::inheritance::super::fooRequest,
s) == 16);
template <>
struct IsFidlType<::llcpp::fidl::test::inheritance::super::fooResponse>
: public std::true_type {};
template <>
struct IsFidlMessage<::llcpp::fidl::test::inheritance::super::fooResponse>
: public std::true_type {};
static_assert(
sizeof(::llcpp::fidl::test::inheritance::super::fooResponse) ==
::llcpp::fidl::test::inheritance::super::fooResponse::PrimarySize);
static_assert(offsetof(::llcpp::fidl::test::inheritance::super::fooResponse,
y) == 16);
template <>
struct IsFidlType<::llcpp::fidl::test::inheritance::sub::fooRequest>
: public std::true_type {};
template <>
struct IsFidlMessage<::llcpp::fidl::test::inheritance::sub::fooRequest>
: public std::true_type {};
static_assert(sizeof(::llcpp::fidl::test::inheritance::sub::fooRequest) ==
::llcpp::fidl::test::inheritance::sub::fooRequest::PrimarySize);
static_assert(offsetof(::llcpp::fidl::test::inheritance::sub::fooRequest, s) ==
16);
template <>
struct IsFidlType<::llcpp::fidl::test::inheritance::sub::fooResponse>
: public std::true_type {};
template <>
struct IsFidlMessage<::llcpp::fidl::test::inheritance::sub::fooResponse>
: public std::true_type {};
static_assert(sizeof(::llcpp::fidl::test::inheritance::sub::fooResponse) ==
::llcpp::fidl::test::inheritance::sub::fooResponse::PrimarySize);
static_assert(offsetof(::llcpp::fidl::test::inheritance::sub::fooResponse, y) ==
16);
} // namespace fidl
namespace llcpp {
namespace fidl {
namespace test {
namespace inheritance {
struct super::AsyncEventHandlers {};
class super::fooResponseContext : public ::fidl::internal::ResponseContext {
public:
fooResponseContext();
virtual void OnReply(super::fooResponse* message) = 0;
private:
void OnReply(uint8_t* reply) override;
};
class super::ClientImpl final : private ::fidl::internal::ClientBase {
public:
// Asynchronous variant of |super.foo()|. The request and callback are
// allocated on the heap.
::fidl::Result foo(::fidl::StringView s,
::fit::callback<void(fooResponse* response)> _cb);
// Asynchronous variant of |super.foo()|. Caller provides the backing storage
// for FIDL message via request buffer. Ownership of _context is given
// unsafely to the binding until OnError() or OnReply() are called on it.
::fidl::Result foo(::fidl::BufferSpan _request_buffer, ::fidl::StringView s,
fooResponseContext* _context);
// Synchronous variant of |super.foo()|. Allocates 24 bytes of response buffer
// on the stack. Request is heap-allocated.
ResultOf::foo foo_Sync(::fidl::StringView s);
// Synchronous variant of |super.foo()|. Caller provides the backing storage
// for FIDL message via request and response buffers.
UnownedResultOf::foo foo_Sync(::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer);
private:
friend class ::fidl::Client<super>;
explicit ClientImpl(AsyncEventHandlers handlers)
: handlers_(std::move(handlers)) {}
std::optional<::fidl::UnbindInfo> DispatchEvent(
fidl_incoming_msg_t* msg) override;
AsyncEventHandlers handlers_;
};
// |EventSender| owns a server endpoint of a channel speaking
// the super protocol, and can send events in that protocol.
class super::EventSender {
public:
// Constructs an event sender with an invalid channel.
EventSender() = default;
// TODO(fxbug.dev/65212): EventSender should take a ::fidl::ServerEnd.
explicit EventSender(::zx::channel server_end)
: server_end_(std::move(server_end)) {}
// The underlying server channel endpoint, which may be replaced at run-time.
const ::zx::channel& channel() const { return server_end_; }
::zx::channel& channel() { return server_end_; }
// Whether the underlying channel is valid.
bool is_valid() const { return server_end_.is_valid(); }
private:
::zx::channel server_end_;
};
class super::WeakEventSender {
public:
private:
friend class ::fidl::ServerBindingRef<super>;
explicit WeakEventSender(
std::weak_ptr<::fidl::internal::AsyncServerBinding<super>> binding)
: binding_(std::move(binding)) {}
std::weak_ptr<::fidl::internal::AsyncServerBinding<super>> binding_;
};
struct sub::AsyncEventHandlers {};
class sub::fooResponseContext : public ::fidl::internal::ResponseContext {
public:
fooResponseContext();
virtual void OnReply(sub::fooResponse* message) = 0;
private:
void OnReply(uint8_t* reply) override;
};
class sub::ClientImpl final : private ::fidl::internal::ClientBase {
public:
// Asynchronous variant of |sub.foo()|. The request and callback are allocated
// on the heap.
::fidl::Result foo(::fidl::StringView s,
::fit::callback<void(fooResponse* response)> _cb);
// Asynchronous variant of |sub.foo()|. Caller provides the backing storage
// for FIDL message via request buffer. Ownership of _context is given
// unsafely to the binding until OnError() or OnReply() are called on it.
::fidl::Result foo(::fidl::BufferSpan _request_buffer, ::fidl::StringView s,
fooResponseContext* _context);
// Synchronous variant of |sub.foo()|. Allocates 24 bytes of response buffer
// on the stack. Request is heap-allocated.
ResultOf::foo foo_Sync(::fidl::StringView s);
// Synchronous variant of |sub.foo()|. Caller provides the backing storage for
// FIDL message via request and response buffers.
UnownedResultOf::foo foo_Sync(::fidl::BufferSpan _request_buffer,
::fidl::StringView s,
::fidl::BufferSpan _response_buffer);
private:
friend class ::fidl::Client<sub>;
explicit ClientImpl(AsyncEventHandlers handlers)
: handlers_(std::move(handlers)) {}
std::optional<::fidl::UnbindInfo> DispatchEvent(
fidl_incoming_msg_t* msg) override;
AsyncEventHandlers handlers_;
};
// |EventSender| owns a server endpoint of a channel speaking
// the sub protocol, and can send events in that protocol.
class sub::EventSender {
public:
// Constructs an event sender with an invalid channel.
EventSender() = default;
// TODO(fxbug.dev/65212): EventSender should take a ::fidl::ServerEnd.
explicit EventSender(::zx::channel server_end)
: server_end_(std::move(server_end)) {}
// The underlying server channel endpoint, which may be replaced at run-time.
const ::zx::channel& channel() const { return server_end_; }
::zx::channel& channel() { return server_end_; }
// Whether the underlying channel is valid.
bool is_valid() const { return server_end_.is_valid(); }
private:
::zx::channel server_end_;
};
class sub::WeakEventSender {
public:
private:
friend class ::fidl::ServerBindingRef<sub>;
explicit WeakEventSender(
std::weak_ptr<::fidl::internal::AsyncServerBinding<sub>> binding)
: binding_(std::move(binding)) {}
std::weak_ptr<::fidl::internal::AsyncServerBinding<sub>> binding_;
};
} // namespace inheritance
} // namespace test
} // namespace fidl
} // namespace llcpp