blob: 5636d5801e0cfe58bdbea2e98bc5b8daf6b6df25 [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/coding.h>
#include <lib/fidl/llcpp/connect_service.h>
#include <lib/fidl/llcpp/envelope.h>
#include <lib/fidl/llcpp/memory.h>
#include <lib/fidl/llcpp/service_handler_interface.h>
#include <lib/fidl/llcpp/string_view.h>
#include <lib/fidl/llcpp/sync_call.h>
#include <lib/fidl/llcpp/tracking_ptr.h>
#include <lib/fidl/llcpp/traits.h>
#include <lib/fidl/llcpp/transaction.h>
#include <lib/fidl/llcpp/vector_view.h>
#include <lib/fidl/txn_header.h>
#include <lib/fit/function.h>
#include <lib/zx/channel.h>
#include <zircon/fidl.h>
namespace llcpp {
namespace test {
namespace name {
class Union;
class Table;
struct Struct;
class Interface;
class Service;
enum class MyEnum : uint32_t {
FOO = 1u,
BAR = 2u,
};
class MyBits final {
public:
constexpr MyBits() : value_(0u) {}
explicit constexpr MyBits(uint32_t value) : value_(value) {}
const static MyBits MY_FIRST_BIT;
const static MyBits MY_OTHER_BIT;
const static MyBits mask;
explicit constexpr inline operator uint32_t() const { return value_; }
explicit constexpr inline operator bool() const {
return static_cast<bool>(value_);
}
constexpr inline bool operator==(const MyBits& other) const {
return value_ == other.value_;
}
constexpr inline bool operator!=(const MyBits& other) const {
return value_ != other.value_;
}
constexpr inline MyBits operator~() const;
constexpr inline MyBits operator|(const MyBits& other) const;
constexpr inline MyBits operator&(const MyBits& other) const;
constexpr inline MyBits operator^(const MyBits& other) const;
constexpr inline void operator|=(const MyBits& other);
constexpr inline void operator&=(const MyBits& other);
constexpr inline void operator^=(const MyBits& other);
private:
uint32_t value_;
};
constexpr const ::llcpp::test::name::MyBits MyBits::MY_FIRST_BIT =
::llcpp::test::name::MyBits(1u);
constexpr const ::llcpp::test::name::MyBits MyBits::MY_OTHER_BIT =
::llcpp::test::name::MyBits(2u);
constexpr const ::llcpp::test::name::MyBits MyBits::mask =
::llcpp::test::name::MyBits(3u);
constexpr inline ::llcpp::test::name::MyBits MyBits::operator~() const {
return ::llcpp::test::name::MyBits(
static_cast<uint32_t>(~this->value_ & mask.value_));
}
constexpr inline ::llcpp::test::name::MyBits MyBits::operator|(
const ::llcpp::test::name::MyBits& other) const {
return ::llcpp::test::name::MyBits(
static_cast<uint32_t>(this->value_ | other.value_));
}
constexpr inline ::llcpp::test::name::MyBits MyBits::operator&(
const ::llcpp::test::name::MyBits& other) const {
return ::llcpp::test::name::MyBits(
static_cast<uint32_t>(this->value_ & other.value_));
}
constexpr inline ::llcpp::test::name::MyBits MyBits::operator^(
const ::llcpp::test::name::MyBits& other) const {
return ::llcpp::test::name::MyBits(
static_cast<uint32_t>(this->value_ ^ other.value_));
}
constexpr inline void MyBits::operator|=(
const ::llcpp::test::name::MyBits& other) {
this->value_ |= other.value_;
}
constexpr inline void MyBits::operator&=(
const ::llcpp::test::name::MyBits& other) {
this->value_ &= other.value_;
}
constexpr inline void MyBits::operator^=(
const ::llcpp::test::name::MyBits& other) {
this->value_ ^= other.value_;
}
extern "C" const fidl_type_t v1_test_name_UnionTable;
// union comment #1
//
// union comment #3
class Union {
public:
Union() : ordinal_(Ordinal::Invalid), envelope_{} {}
Union(Union&&) = default;
Union& operator=(Union&&) = default;
~Union() { reset_ptr(nullptr); }
enum class Tag : fidl_xunion_tag_t {
kField = 1, // 0x1
};
bool has_invalid_tag() const { return ordinal_ == Ordinal::Invalid; }
bool is_Field() const { return ordinal_ == Ordinal::kField; }
static Union WithField(::fidl::tracking_ptr<int32_t>&& val) {
Union result;
result.set_Field(std::move(val));
return result;
}
// union member comment #1
//
// union member comment #3
void set_Field(::fidl::tracking_ptr<int32_t>&& elem) {
ordinal_ = Ordinal::kField;
reset_ptr(static_cast<::fidl::tracking_ptr<void>>(std::move(elem)));
}
// union member comment #1
//
// union member comment #3
int32_t& mutable_Field() {
ZX_ASSERT(ordinal_ == Ordinal::kField);
return *static_cast<int32_t*>(envelope_.data.get());
}
const int32_t& Field() const {
ZX_ASSERT(ordinal_ == Ordinal::kField);
return *static_cast<int32_t*>(envelope_.data.get());
}
Tag which() const {
ZX_ASSERT(!has_invalid_tag());
return static_cast<Tag>(ordinal_);
}
static constexpr const fidl_type_t* Type = &v1_test_name_UnionTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 24;
[[maybe_unused]] static constexpr uint32_t MaxOutOfLine = 8;
static constexpr bool HasPointer = true;
private:
enum class Ordinal : fidl_xunion_tag_t {
Invalid = 0,
kField = 1, // 0x1
};
void reset_ptr(::fidl::tracking_ptr<void>&& new_ptr) {
// To clear the existing value, std::move it and let it go out of scope.
switch (static_cast<fidl_xunion_tag_t>(ordinal_)) {
case 1: {
::fidl::tracking_ptr<int32_t> to_destroy =
static_cast<::fidl::tracking_ptr<int32_t>>(
std::move(envelope_.data));
break;
}
}
envelope_.data = std::move(new_ptr);
}
static void SizeAndOffsetAssertionHelper();
Ordinal ordinal_;
FIDL_ALIGNDECL
::fidl::Envelope<void> envelope_;
};
extern "C" const fidl_type_t v1_test_name_TableTable;
// table comment #1
//
// table comment #3
class Table final {
public:
// Returns whether no field is set.
bool IsEmpty() const { return max_ordinal_ == 0; }
// table field comment #1
//
// table field comment #3
const int32_t& Field() const {
ZX_ASSERT(has_Field());
return *frame_ptr_->Field_.data;
}
int32_t& Field() {
ZX_ASSERT(has_Field());
return *frame_ptr_->Field_.data;
}
bool has_Field() const {
return max_ordinal_ >= 1 && frame_ptr_->Field_.data != nullptr;
}
Table() = default;
~Table() = default;
Table(Table&& other) noexcept = default;
Table& operator=(Table&& other) noexcept = default;
static constexpr const fidl_type_t* Type = &v1_test_name_TableTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 16;
[[maybe_unused]] static constexpr uint32_t MaxOutOfLine = 24;
static constexpr bool HasPointer = true;
class Builder;
class UnownedBuilder;
class Frame final {
public:
Frame() = default;
// In its intended usage, Frame will be referenced by a tracking_ptr. If the
// tracking_ptr is assigned before a move or copy, then it will reference
// the old invalid object. Because this is unsafe, copies are disallowed and
// moves are only allowed by friend classes that operate safely.
Frame(const Frame&) = delete;
Frame& operator=(const Frame&) = delete;
private:
Frame(Frame&&) noexcept = default;
Frame& operator=(Frame&&) noexcept = default;
::fidl::Envelope<int32_t> Field_;
friend class Table;
friend class Table::Builder;
friend class Table::UnownedBuilder;
};
private:
Table(uint64_t max_ordinal, ::fidl::tracking_ptr<Frame>&& frame_ptr)
: max_ordinal_(max_ordinal), frame_ptr_(std::move(frame_ptr)) {}
uint64_t max_ordinal_ = 0;
::fidl::tracking_ptr<Frame> frame_ptr_;
};
// Table::Builder builds Table.
// Usage:
// Table val = Table::Builder(std::make_unique<Table::Frame>())
// .set_Field(ptr)
// .build();
class Table::Builder final {
public:
~Builder() = default;
Builder() = delete;
Builder(::fidl::tracking_ptr<Table::Frame>&& frame_ptr)
: max_ordinal_(0), frame_ptr_(std::move(frame_ptr)) {}
Builder(Builder&& other) noexcept = default;
Builder& operator=(Builder&& other) noexcept = default;
Builder(const Builder& other) = delete;
Builder& operator=(const Builder& other) = delete;
// table field comment #1
//
// table field comment #3
Builder&& set_Field(::fidl::tracking_ptr<int32_t> elem) {
frame_ptr_->Field_.data = std::move(elem);
if (max_ordinal_ < 1) {
// Note: the table size is not currently reduced if nullptr is set.
// This is possible to reconsider in the future.
max_ordinal_ = 1;
}
return std::move(*this);
}
Table build() { return Table(max_ordinal_, std::move(frame_ptr_)); }
private:
uint64_t max_ordinal_ = 0;
::fidl::tracking_ptr<Table::Frame> frame_ptr_;
};
// UnownedBuilder acts like Builder but directly owns its Frame, simplifying
// working with unowned data.
class Table::UnownedBuilder final {
public:
~UnownedBuilder() = default;
UnownedBuilder() noexcept = default;
UnownedBuilder(UnownedBuilder&& other) noexcept = default;
UnownedBuilder& operator=(UnownedBuilder&& other) noexcept = default;
// table field comment #1
//
// table field comment #3
UnownedBuilder&& set_Field(::fidl::tracking_ptr<int32_t> elem) {
ZX_ASSERT(elem);
frame_.Field_.data = std::move(elem);
if (max_ordinal_ < 1) {
max_ordinal_ = 1;
}
return std::move(*this);
}
Table build() { return Table(max_ordinal_, ::fidl::unowned_ptr(&frame_)); }
private:
uint64_t max_ordinal_ = 0;
Table::Frame frame_;
};
extern "C" const fidl_type_t v1_test_name_StructTable;
// struct comment #1
//
// struct comment #3
struct Struct {
static constexpr const fidl_type_t* Type = &v1_test_name_StructTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 4;
[[maybe_unused]] static constexpr uint32_t MaxOutOfLine = 0;
static constexpr bool HasPointer = false;
// struct member comment #1
//
// struct member comment #3
int32_t Field = {};
};
extern "C" const fidl_type_t v1_test_name_InterfaceMethodRequestTable;
extern "C" const fidl_type_t v1_test_name_InterfaceMethodResponseTable;
extern "C" const fidl_type_t v1_test_name_InterfaceOnEventRequestTable;
extern "C" const fidl_type_t v1_test_name_InterfaceOnEventEventTable;
// interface comment #1
//
// interface comment #3
class Interface final {
Interface() = delete;
public:
using MethodRequest = ::fidl::AnyZeroArgMessage;
using OnEventResponse = ::fidl::AnyZeroArgMessage;
struct EventHandlers {
// event comment #1
//
// event comment #3
fit::callback<zx_status_t()> on_event;
// Fallback handler when an unknown ordinal is received.
// Caller may put custom error handling logic here.
fit::callback<zx_status_t()> unknown;
};
// Collection of return types of FIDL calls in this protocol.
class ResultOf final {
ResultOf() = delete;
private:
class Method_Impl final : private ::fidl::internal::StatusAndError {
using Super = ::fidl::internal::StatusAndError;
public:
Method_Impl(::zx::unowned_channel _client_end);
~Method_Impl() = default;
Method_Impl(Method_Impl&& other) = default;
Method_Impl& operator=(Method_Impl&& other) = default;
using Super::error;
using Super::ok;
using Super::status;
};
public:
using Method = Method_Impl;
};
// 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;
private:
class Method_Impl final : private ::fidl::internal::StatusAndError {
using Super = ::fidl::internal::StatusAndError;
public:
Method_Impl(::zx::unowned_channel _client_end);
~Method_Impl() = default;
Method_Impl(Method_Impl&& other) = default;
Method_Impl& operator=(Method_Impl&& other) = default;
using Super::error;
using Super::ok;
using Super::status;
};
public:
using Method = Method_Impl;
};
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_; }
// method comment #1
//
// method comment #3
// Allocates 16 bytes of message buffer on the stack. No heap allocation
// necessary.
ResultOf::Method Method();
// Handle all possible events defined in this protocol.
// Blocks to consume exactly one message from the channel, then call the
// corresponding handler defined in |EventHandlers|. The return status of
// the handler function is folded with any transport-level errors and
// returned.
zx_status_t HandleEvents(EventHandlers handlers);
private:
::zx::channel channel_;
};
// Methods to make a sync FIDL call directly on an unowned channel, avoiding
// setting up a client.
class Call final {
Call() = delete;
public:
// method comment #1
//
// method comment #3
// Allocates 16 bytes of message buffer on the stack. No heap allocation
// necessary.
static ResultOf::Method Method(::zx::unowned_channel _client_end);
// Handle all possible events defined in this protocol.
// Blocks to consume exactly one message from the channel, then call the
// corresponding handler defined in |EventHandlers|. The return status of
// the handler function is folded with any transport-level errors and
// returned.
static zx_status_t HandleEvents(::zx::unowned_channel client_end,
EventHandlers handlers);
};
// Messages are encoded and decoded in-place when these methods are used.
// Additionally, requests must be already laid-out according to the FIDL
// wire-format.
class InPlace final {
InPlace() = delete;
public:
// method comment #1
//
// method comment #3
static ::fidl::internal::StatusAndError Method(
::zx::unowned_channel _client_end);
};
// Pure-virtual interface to be implemented by a server.
class Interface {
public:
Interface() = default;
virtual ~Interface() = default;
using _Outer = Interface;
using _Base = ::fidl::CompleterBase;
using MethodCompleter = ::fidl::Completer<>;
virtual void Method(MethodCompleter::Sync _completer) = 0;
};
// 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 bool TryDispatch(Interface* impl, fidl_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 bool Dispatch(Interface* impl, fidl_msg_t* msg,
::fidl::Transaction* txn);
// Same as |Dispatch|, but takes a |void*| instead of |Interface*|. Only used
// with |fidl::Bind| to reduce template expansion. Do not call this method
// manually. Use |Dispatch| instead.
static bool TypeErasedDispatch(void* impl, fidl_msg_t* msg,
::fidl::Transaction* txn) {
return Dispatch(static_cast<Interface*>(impl), msg, txn);
}
// event comment #1
//
// event comment #3
static zx_status_t SendOnEventEvent(::zx::unowned_channel _chan);
// Helper functions to fill in the transaction header in a
// |DecodedMessage<TransactionalMessage>|.
class SetTransactionHeaderFor final {
SetTransactionHeaderFor() = delete;
public:
static void MethodRequest(
const ::fidl::DecodedMessage<Interface::MethodRequest>& _msg);
static void OnEventResponse(
const ::fidl::DecodedMessage<Interface::OnEventResponse>& _msg);
};
};
// service comment #1
//
// service comment #3
class Service final {
Service() = default;
public:
static constexpr char Name[] = "test.name.Service";
// Client protocol for connecting to member protocols of a service instance.
class ServiceClient final {
ServiceClient() = delete;
public:
ServiceClient(::zx::channel dir,
::fidl::internal::ConnectMemberFunc connect_func)
: dir_(std::move(dir)), connect_func_(connect_func) {}
// Connects to the member protocol "interface". Returns a
// |fidl::ClientChannel| on success, which can be used with
// |fidl::BindSyncClient| to create a synchronous client.
//
// # Errors
//
// On failure, returns a fit::error with zx_status_t != ZX_OK.
// Failures can occur if channel creation failed, or if there was an issue
// making a |fuchsia.io.Directory::Open| call.
//
// Since the call to |Open| is asynchronous, an error sent by the remote end
// will not result in a failure of this method. Any errors sent by the
// remote will appear on the |ClientChannel| returned from this method.
::fidl::result<::fidl::ClientChannel<Interface>> connect_interface() {
::zx::channel local, remote;
zx_status_t result = ::zx::channel::create(0, &local, &remote);
if (result != ZX_OK) {
return ::fit::error(result);
}
result =
connect_func_(::zx::unowned_channel(dir_),
::fidl::StringView("interface"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<Interface>(std::move(local)));
}
private:
::zx::channel dir_;
::fidl::internal::ConnectMemberFunc connect_func_;
};
// Facilitates member protocol registration for servers.
class Handler final {
public:
// Constructs a FIDL Service-typed handler. Does not take ownership of
// |service_handler|.
explicit Handler(::llcpp::fidl::ServiceHandlerInterface* service_handler)
: service_handler_(service_handler) {}
// Adds member "interface" to the service instance. |handler| will be
// invoked on connection attempts.
//
// # Errors
//
// Returns ZX_ERR_ALREADY_EXISTS if the member was already added.
zx_status_t add_interface(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("interface", std::move(handler));
}
private:
::llcpp::fidl::ServiceHandlerInterface* service_handler_; // Not owned.
};
};
// const comment #1
//
// const comment #3
constexpr int32_t C = 4u;
} // namespace name
} // namespace test
} // namespace llcpp
namespace fidl {
template <>
struct IsFidlType<::llcpp::test::name::Union> : public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::Union>);
template <>
struct IsFidlType<::llcpp::test::name::Table> : public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::Table>);
template <>
struct IsFidlType<::llcpp::test::name::Struct> : public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::Struct>);
static_assert(offsetof(::llcpp::test::name::Struct, Field) == 0);
static_assert(sizeof(::llcpp::test::name::Struct) ==
::llcpp::test::name::Struct::PrimarySize);
template <>
struct IsFidlType<::llcpp::test::name::MyBits> : public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::MyBits>);
static_assert(sizeof(::llcpp::test::name::MyBits) == sizeof(uint32_t));
} // namespace fidl