blob: 4dbc33ed1cc1a73aa41feaf372644cd676a87598 [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/vmo.h>
#include <zircon/fidl.h>
namespace llcpp {
namespace test {
namespace name {
class UnionWithHandle;
class TableWithHandle;
struct HandlesInTypes;
extern "C" const fidl_type_t v1_test_name_UnionWithHandleTable;
class UnionWithHandle {
public:
UnionWithHandle() : ordinal_(Ordinal::Invalid), envelope_{} {}
UnionWithHandle(UnionWithHandle&&) = default;
UnionWithHandle& operator=(UnionWithHandle&&) = default;
~UnionWithHandle() { reset_ptr(nullptr); }
enum class Tag : fidl_xunion_tag_t {
kH = 1, // 0x1
kUnknown = ::std::numeric_limits<::fidl_union_tag_t>::max(),
};
bool has_invalid_tag() const { return ordinal_ == Ordinal::Invalid; }
bool is_h() const { return ordinal_ == Ordinal::kH; }
static UnionWithHandle WithH(::fidl::tracking_ptr<::zx::vmo>&& val) {
UnionWithHandle result;
result.set_h(std::move(val));
return result;
}
void set_h(::fidl::tracking_ptr<::zx::vmo>&& elem) {
ordinal_ = Ordinal::kH;
reset_ptr(static_cast<::fidl::tracking_ptr<void>>(std::move(elem)));
}
::zx::vmo& mutable_h() {
ZX_ASSERT(ordinal_ == Ordinal::kH);
return *static_cast<::zx::vmo*>(envelope_.data.get());
}
const ::zx::vmo& h() const {
ZX_ASSERT(ordinal_ == Ordinal::kH);
return *static_cast<::zx::vmo*>(envelope_.data.get());
}
void* unknownData() const {
ZX_ASSERT(which() == Tag::kUnknown);
return envelope_.data.get();
}
Tag which() const;
static constexpr const fidl_type_t* Type = &v1_test_name_UnionWithHandleTable;
static constexpr uint32_t MaxNumHandles = 1;
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,
kH = 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<::zx::vmo> to_destroy =
static_cast<::fidl::tracking_ptr<::zx::vmo>>(
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_TableWithHandleTable;
class TableWithHandle final {
public:
// Returns whether no field is set.
bool IsEmpty() const { return max_ordinal_ == 0; }
const ::zx::vmo& h() const {
ZX_ASSERT(has_h());
return *frame_ptr_->h_.data;
}
::zx::vmo& h() {
ZX_ASSERT(has_h());
return *frame_ptr_->h_.data;
}
bool has_h() const {
return max_ordinal_ >= 1 && frame_ptr_->h_.data != nullptr;
}
TableWithHandle() = default;
~TableWithHandle() = default;
TableWithHandle(TableWithHandle&& other) noexcept = default;
TableWithHandle& operator=(TableWithHandle&& other) noexcept = default;
static constexpr const fidl_type_t* Type = &v1_test_name_TableWithHandleTable;
static constexpr uint32_t MaxNumHandles = 1;
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<::zx::vmo> h_;
friend class TableWithHandle;
friend class TableWithHandle::Builder;
friend class TableWithHandle::UnownedBuilder;
};
private:
TableWithHandle(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_;
};
// TableWithHandle::Builder builds TableWithHandle.
// Usage:
// TableWithHandle val =
// TableWithHandle::Builder(std::make_unique<TableWithHandle::Frame>())
// .set_h(ptr)
// .build();
class TableWithHandle::Builder final {
public:
~Builder() = default;
Builder() = delete;
Builder(::fidl::tracking_ptr<TableWithHandle::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;
Builder&& set_h(::fidl::tracking_ptr<::zx::vmo> elem) {
frame_ptr_->h_.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);
}
TableWithHandle build() {
return TableWithHandle(max_ordinal_, std::move(frame_ptr_));
}
private:
uint64_t max_ordinal_ = 0;
::fidl::tracking_ptr<TableWithHandle::Frame> frame_ptr_;
};
// UnownedBuilder acts like Builder but directly owns its Frame, simplifying
// working with unowned data.
class TableWithHandle::UnownedBuilder final {
public:
~UnownedBuilder() = default;
UnownedBuilder() noexcept = default;
UnownedBuilder(UnownedBuilder&& other) noexcept = default;
UnownedBuilder& operator=(UnownedBuilder&& other) noexcept = default;
UnownedBuilder&& set_h(::fidl::tracking_ptr<::zx::vmo> elem) {
ZX_ASSERT(elem);
frame_.h_.data = std::move(elem);
if (max_ordinal_ < 1) {
max_ordinal_ = 1;
}
return std::move(*this);
}
TableWithHandle build() {
return TableWithHandle(max_ordinal_, ::fidl::unowned_ptr(&frame_));
}
private:
uint64_t max_ordinal_ = 0;
TableWithHandle::Frame frame_;
};
extern "C" const fidl_type_t v1_test_name_HandlesInTypesTable;
struct HandlesInTypes {
static constexpr const fidl_type_t* Type = &v1_test_name_HandlesInTypesTable;
static constexpr uint32_t MaxNumHandles = 4294967295;
static constexpr uint32_t PrimarySize = 104;
[[maybe_unused]] static constexpr uint32_t MaxOutOfLine = 4294967295;
static constexpr bool HasPointer = true;
::zx::vmo normal_handle = {};
::fidl::VectorView<::zx::vmo> handle_in_vec = {};
::fidl::Array<::zx::vmo, 5> handle_in_array = {};
::fidl::VectorView<::fidl::Array<::zx::vmo, 5>> handle_in_mixed_vec_array =
{};
::llcpp::test::name::TableWithHandle table_with_handle = {};
::llcpp::test::name::UnionWithHandle union_with_handle = {};
};
} // namespace name
} // namespace test
} // namespace llcpp
namespace fidl {
template <>
struct IsFidlType<::llcpp::test::name::UnionWithHandle>
: public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::UnionWithHandle>);
template <>
struct IsFidlType<::llcpp::test::name::TableWithHandle>
: public std::true_type {};
static_assert(std::is_standard_layout_v<::llcpp::test::name::TableWithHandle>);
template <>
struct IsFidlType<::llcpp::test::name::HandlesInTypes> : public std::true_type {
};
static_assert(std::is_standard_layout_v<::llcpp::test::name::HandlesInTypes>);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes, normal_handle) ==
0);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes, handle_in_vec) ==
8);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes, handle_in_array) ==
24);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes,
handle_in_mixed_vec_array) == 48);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes,
table_with_handle) == 64);
static_assert(offsetof(::llcpp::test::name::HandlesInTypes,
union_with_handle) == 80);
static_assert(sizeof(::llcpp::test::name::HandlesInTypes) ==
::llcpp::test::name::HandlesInTypes::PrimarySize);
} // namespace fidl