| // 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 <exampleusing/llcpp/fidl.h> |
| #include <zircon/fidl.h> |
| |
| namespace llcpp { |
| |
| namespace fidl { |
| namespace test { |
| namespace placementofattributes { |
| |
| class ExampleXUnion; |
| class ExampleUnion; |
| class ExampleTable; |
| struct ExampleStruct; |
| |
| enum class ExampleEnum : uint32_t { |
| |
| MEMBER = 1u, |
| }; |
| |
| // |ExampleBits| is strict, hence is guaranteed to only contain |
| // members defined in the FIDL schema when receiving it in a message. |
| // Sending unknown members will fail at runtime. |
| class ExampleBits final { |
| public: |
| constexpr ExampleBits() = default; |
| constexpr ExampleBits(const ExampleBits& other) = default; |
| |
| // Constructs an instance of |ExampleBits| from an underlying primitive value, |
| // preserving any bit member not defined in the FIDL schema. |
| explicit constexpr ExampleBits(uint32_t value) : value_(value) {} |
| const static ExampleBits MEMBER; |
| const static ExampleBits kMask; |
| |
| 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 ExampleBits& other) const { |
| return value_ == other.value_; |
| } |
| constexpr inline bool operator!=(const ExampleBits& other) const { |
| return value_ != other.value_; |
| } |
| constexpr inline ExampleBits operator~() const; |
| constexpr inline ExampleBits operator|(const ExampleBits& other) const; |
| constexpr inline ExampleBits operator&(const ExampleBits& other) const; |
| constexpr inline ExampleBits operator^(const ExampleBits& other) const; |
| constexpr inline void operator|=(const ExampleBits& other); |
| constexpr inline void operator&=(const ExampleBits& other); |
| constexpr inline void operator^=(const ExampleBits& other); |
| |
| // Constructs an instance of |ExampleBits| from an underlying primitive value |
| // if the primitive does not contain any unknown members not defined in the |
| // FIDL schema. Otherwise, returns |fit::nullopt|. |
| constexpr inline static fit::optional<ExampleBits> TryFrom(uint32_t value) { |
| if (value & ~kMask.value_) { |
| return fit::nullopt; |
| } |
| return ExampleBits(value & ExampleBits::kMask.value_); |
| } |
| |
| // Constructs an instance of |ExampleBits| from an underlying primitive value, |
| // clearing any bit member not defined in the FIDL schema. |
| constexpr inline static ExampleBits TruncatingUnknown(uint32_t value) { |
| return ExampleBits(value & ExampleBits::kMask.value_); |
| } |
| |
| private: |
| uint32_t value_ = 0; |
| }; |
| constexpr const ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::MEMBER = |
| ::llcpp::fidl::test::placementofattributes::ExampleBits(1u); |
| constexpr const ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::kMask = |
| ::llcpp::fidl::test::placementofattributes::ExampleBits(1u); |
| |
| constexpr inline ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::operator~() const { |
| return ::llcpp::fidl::test::placementofattributes::ExampleBits( |
| static_cast<uint32_t>(~this->value_ & kMask.value_)); |
| } |
| |
| constexpr inline ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::operator|( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) |
| const { |
| return ::llcpp::fidl::test::placementofattributes::ExampleBits( |
| static_cast<uint32_t>(this->value_ | other.value_)); |
| } |
| |
| constexpr inline ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::operator&( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) |
| const { |
| return ::llcpp::fidl::test::placementofattributes::ExampleBits( |
| static_cast<uint32_t>(this->value_ & other.value_)); |
| } |
| |
| constexpr inline ::llcpp::fidl::test::placementofattributes::ExampleBits |
| ExampleBits::operator^( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) |
| const { |
| return ::llcpp::fidl::test::placementofattributes::ExampleBits( |
| static_cast<uint32_t>(this->value_ ^ other.value_)); |
| } |
| |
| constexpr inline void ExampleBits::operator|=( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) { |
| this->value_ |= other.value_; |
| } |
| |
| constexpr inline void ExampleBits::operator&=( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) { |
| this->value_ &= other.value_; |
| } |
| |
| constexpr inline void ExampleBits::operator^=( |
| const ::llcpp::fidl::test::placementofattributes::ExampleBits& other) { |
| this->value_ ^= other.value_; |
| } |
| |
| class ExampleProtocol; |
| |
| extern "C" const fidl_type_t fidl_test_placementofattributes_ExampleXUnionTable; |
| |
| class ExampleXUnion { |
| public: |
| ExampleXUnion() : ordinal_(Ordinal::Invalid), envelope_{} {} |
| |
| ExampleXUnion(ExampleXUnion&&) = default; |
| ExampleXUnion& operator=(ExampleXUnion&&) = default; |
| |
| ~ExampleXUnion() { reset_ptr(nullptr); } |
| |
| enum class Tag : fidl_xunion_tag_t { |
| kVariant = 1, // 0x1 |
| kUnknown = ::std::numeric_limits<::fidl_union_tag_t>::max(), |
| }; |
| |
| bool has_invalid_tag() const { return ordinal_ == Ordinal::Invalid; } |
| |
| bool is_variant() const { return ordinal_ == Ordinal::kVariant; } |
| |
| static ExampleXUnion WithVariant(::fidl::tracking_ptr<uint32_t>&& val) { |
| ExampleXUnion result; |
| result.set_variant(std::move(val)); |
| return result; |
| } |
| |
| void set_variant(::fidl::tracking_ptr<uint32_t>&& elem) { |
| ordinal_ = Ordinal::kVariant; |
| reset_ptr(static_cast<::fidl::tracking_ptr<void>>(std::move(elem))); |
| } |
| |
| uint32_t& mutable_variant() { |
| ZX_ASSERT(ordinal_ == Ordinal::kVariant); |
| return *static_cast<uint32_t*>(envelope_.data.get()); |
| } |
| const uint32_t& variant() const { |
| ZX_ASSERT(ordinal_ == Ordinal::kVariant); |
| return *static_cast<uint32_t*>(envelope_.data.get()); |
| } |
| Tag which() const; |
| |
| static constexpr const fidl_type_t* Type = |
| &fidl_test_placementofattributes_ExampleXUnionTable; |
| 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, |
| kVariant = 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<uint32_t> to_destroy = |
| static_cast<::fidl::tracking_ptr<uint32_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 fidl_test_placementofattributes_ExampleUnionTable; |
| |
| class ExampleUnion { |
| public: |
| ExampleUnion() : ordinal_(Ordinal::Invalid), envelope_{} {} |
| |
| ExampleUnion(ExampleUnion&&) = default; |
| ExampleUnion& operator=(ExampleUnion&&) = default; |
| |
| ~ExampleUnion() { reset_ptr(nullptr); } |
| |
| enum class Tag : fidl_xunion_tag_t { |
| kVariant = 1, // 0x1 |
| }; |
| |
| bool has_invalid_tag() const { return ordinal_ == Ordinal::Invalid; } |
| |
| bool is_variant() const { return ordinal_ == Ordinal::kVariant; } |
| |
| static ExampleUnion WithVariant(::fidl::tracking_ptr<uint32_t>&& val) { |
| ExampleUnion result; |
| result.set_variant(std::move(val)); |
| return result; |
| } |
| |
| void set_variant(::fidl::tracking_ptr<uint32_t>&& elem) { |
| ordinal_ = Ordinal::kVariant; |
| reset_ptr(static_cast<::fidl::tracking_ptr<void>>(std::move(elem))); |
| } |
| |
| uint32_t& mutable_variant() { |
| ZX_ASSERT(ordinal_ == Ordinal::kVariant); |
| return *static_cast<uint32_t*>(envelope_.data.get()); |
| } |
| const uint32_t& variant() const { |
| ZX_ASSERT(ordinal_ == Ordinal::kVariant); |
| return *static_cast<uint32_t*>(envelope_.data.get()); |
| } |
| Tag which() const { |
| ZX_ASSERT(!has_invalid_tag()); |
| return static_cast<Tag>(ordinal_); |
| } |
| |
| static constexpr const fidl_type_t* Type = |
| &fidl_test_placementofattributes_ExampleUnionTable; |
| 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, |
| kVariant = 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<uint32_t> to_destroy = |
| static_cast<::fidl::tracking_ptr<uint32_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 fidl_test_placementofattributes_ExampleTableTable; |
| |
| class ExampleTable final { |
| public: |
| // Returns whether no field is set. |
| bool IsEmpty() const { return max_ordinal_ == 0; } |
| |
| const uint32_t& member() const { |
| ZX_ASSERT(has_member()); |
| return *frame_ptr_->member_.data; |
| } |
| uint32_t& member() { |
| ZX_ASSERT(has_member()); |
| return *frame_ptr_->member_.data; |
| } |
| bool has_member() const { |
| return max_ordinal_ >= 1 && frame_ptr_->member_.data != nullptr; |
| } |
| |
| ExampleTable() = default; |
| ~ExampleTable() = default; |
| ExampleTable(ExampleTable&& other) noexcept = default; |
| ExampleTable& operator=(ExampleTable&& other) noexcept = default; |
| |
| static constexpr const fidl_type_t* Type = |
| &fidl_test_placementofattributes_ExampleTableTable; |
| 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 UnownedEncodedMessage final { |
| public: |
| UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size, |
| ExampleTable* value) |
| : message_(bytes, byte_size, sizeof(ExampleTable), nullptr, 0, 0) { |
| message_.LinearizeAndEncode<ExampleTable>(value); |
| } |
| 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_; } |
| |
| private: |
| ::fidl::OutgoingMessage message_; |
| }; |
| |
| class OwnedEncodedMessage final { |
| public: |
| explicit OwnedEncodedMessage(ExampleTable* value) |
| : message_(bytes_, sizeof(bytes_), value) {} |
| 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(); |
| } |
| |
| private: |
| FIDL_ALIGNDECL |
| uint8_t bytes_[FIDL_ALIGN(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<ExampleTable>(); |
| } |
| DecodedMessage(fidl_incoming_msg_t* msg) |
| : ::fidl::internal::IncomingMessage(msg) { |
| Decode<ExampleTable>(); |
| } |
| DecodedMessage(const DecodedMessage&) = delete; |
| DecodedMessage(DecodedMessage&&) = delete; |
| DecodedMessage* operator=(const DecodedMessage&) = delete; |
| DecodedMessage* operator=(DecodedMessage&&) = delete; |
| |
| ExampleTable* PrimaryObject() { |
| ZX_DEBUG_ASSERT(ok()); |
| return reinterpret_cast<ExampleTable*>(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<ExampleTable>(); |
| } |
| } |
| }; |
| |
| 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<uint32_t> member_; |
| |
| friend class ExampleTable; |
| friend class ExampleTable::Builder; |
| friend class ExampleTable::UnownedBuilder; |
| }; |
| |
| private: |
| ExampleTable(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_; |
| }; |
| |
| // ExampleTable::Builder builds ExampleTable. |
| // Usage: |
| // ExampleTable val = |
| // ExampleTable::Builder(std::make_unique<ExampleTable::Frame>()) |
| // .set_member(ptr) |
| // .build(); |
| class ExampleTable::Builder final { |
| public: |
| ~Builder() = default; |
| Builder() = delete; |
| Builder(::fidl::tracking_ptr<ExampleTable::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; |
| |
| // Returns whether no field is set. |
| bool IsEmpty() const { return max_ordinal_ == 0; } |
| |
| Builder&& set_member(::fidl::tracking_ptr<uint32_t> elem) { |
| frame_ptr_->member_.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); |
| } |
| const uint32_t& member() const { |
| ZX_ASSERT(has_member()); |
| return *frame_ptr_->member_.data; |
| } |
| uint32_t& member() { |
| ZX_ASSERT(has_member()); |
| return *frame_ptr_->member_.data; |
| } |
| bool has_member() const { |
| return max_ordinal_ >= 1 && frame_ptr_->member_.data != nullptr; |
| } |
| |
| ExampleTable build() { |
| return ExampleTable(max_ordinal_, std::move(frame_ptr_)); |
| } |
| |
| private: |
| uint64_t max_ordinal_ = 0; |
| ::fidl::tracking_ptr<ExampleTable::Frame> frame_ptr_; |
| }; |
| |
| // UnownedBuilder acts like Builder but directly owns its Frame, simplifying |
| // working with unowned data. |
| class ExampleTable::UnownedBuilder final { |
| public: |
| ~UnownedBuilder() = default; |
| UnownedBuilder() noexcept = default; |
| UnownedBuilder(UnownedBuilder&& other) noexcept = default; |
| UnownedBuilder& operator=(UnownedBuilder&& other) noexcept = default; |
| |
| // Returns whether no field is set. |
| bool IsEmpty() const { return max_ordinal_ == 0; } |
| |
| UnownedBuilder&& set_member(::fidl::tracking_ptr<uint32_t> elem) { |
| ZX_ASSERT(elem); |
| frame_.member_.data = std::move(elem); |
| if (max_ordinal_ < 1) { |
| max_ordinal_ = 1; |
| } |
| return std::move(*this); |
| } |
| const uint32_t& member() const { |
| ZX_ASSERT(has_member()); |
| return *frame_.member_.data; |
| } |
| uint32_t& member() { |
| ZX_ASSERT(has_member()); |
| return *frame_.member_.data; |
| } |
| bool has_member() const { |
| return max_ordinal_ >= 1 && frame_.member_.data != nullptr; |
| } |
| |
| ExampleTable build() { |
| return ExampleTable(max_ordinal_, ::fidl::unowned_ptr(&frame_)); |
| } |
| |
| private: |
| uint64_t max_ordinal_ = 0; |
| ExampleTable::Frame frame_; |
| }; |
| |
| extern "C" const fidl_type_t fidl_test_placementofattributes_ExampleStructTable; |
| |
| struct ExampleStruct { |
| static constexpr const fidl_type_t* Type = |
| &fidl_test_placementofattributes_ExampleStructTable; |
| 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; |
| |
| uint32_t member = {}; |
| |
| class UnownedEncodedMessage final { |
| public: |
| UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size, |
| ExampleStruct* value) |
| : message_(bytes, byte_size, sizeof(ExampleStruct), nullptr, 0, 0) { |
| message_.LinearizeAndEncode<ExampleStruct>(value); |
| } |
| 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_; } |
| |
| private: |
| ::fidl::OutgoingMessage message_; |
| }; |
| |
| class OwnedEncodedMessage final { |
| public: |
| explicit OwnedEncodedMessage(ExampleStruct* value) |
| : message_(bytes_, sizeof(bytes_), value) {} |
| 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(); |
| } |
| |
| private: |
| FIDL_ALIGNDECL |
| uint8_t bytes_[FIDL_ALIGN(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<struct ExampleStruct>(); |
| } |
| DecodedMessage(fidl_incoming_msg_t* msg) |
| : ::fidl::internal::IncomingMessage(msg) { |
| Decode<struct ExampleStruct>(); |
| } |
| DecodedMessage(const DecodedMessage&) = delete; |
| DecodedMessage(DecodedMessage&&) = delete; |
| DecodedMessage* operator=(const DecodedMessage&) = delete; |
| DecodedMessage* operator=(DecodedMessage&&) = delete; |
| |
| struct ExampleStruct* PrimaryObject() { |
| ZX_DEBUG_ASSERT(ok()); |
| return reinterpret_cast<struct ExampleStruct*>(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<struct ExampleStruct>(); |
| } |
| } |
| }; |
| }; |
| |
| constexpr uint32_t EXAMPLE_CONST = 0u; |
| |
| extern "C" const fidl_type_t |
| fidl_test_placementofattributes_ExampleProtocolMethodRequestTable; |
| extern "C" const fidl_type_t |
| fidl_test_placementofattributes_ExampleProtocolMethodResponseTable; |
| |
| class ExampleProtocol final { |
| ExampleProtocol() = delete; |
| |
| public: |
| struct MethodRequest final { |
| FIDL_ALIGNDECL |
| fidl_message_header_t _hdr; |
| ::llcpp::exampleusing::Empty arg; |
| explicit MethodRequest(zx_txid_t _txid, ::llcpp::exampleusing::Empty& arg) |
| : arg(std::move(arg)) { |
| _InitHeader(_txid); |
| } |
| explicit MethodRequest(zx_txid_t _txid) { _InitHeader(_txid); } |
| |
| static constexpr const fidl_type_t* Type = |
| &fidl_test_placementofattributes_ExampleProtocolMethodRequestTable; |
| static constexpr uint32_t MaxNumHandles = 0; |
| static constexpr uint32_t PrimarySize = 24; |
| static constexpr uint32_t MaxOutOfLine = 0; |
| static constexpr uint32_t AltPrimarySize = 24; |
| static constexpr uint32_t AltMaxOutOfLine = 0; |
| static constexpr bool HasFlexibleEnvelope = false; |
| static constexpr bool HasPointer = false; |
| static constexpr ::fidl::internal::TransactionalMessageKind MessageKind = |
| ::fidl::internal::TransactionalMessageKind::kRequest; |
| |
| class UnownedEncodedMessage final { |
| public: |
| UnownedEncodedMessage(uint8_t* _bytes, uint32_t _byte_size, |
| zx_txid_t _txid, ::llcpp::exampleusing::Empty& arg) |
| : message_(_bytes, _byte_size, sizeof(MethodRequest), nullptr, 0, 0) { |
| FIDL_ALIGNDECL MethodRequest _request(_txid, arg); |
| message_.LinearizeAndEncode<MethodRequest>(&_request); |
| } |
| UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size, |
| MethodRequest* request) |
| : message_(bytes, byte_size, sizeof(MethodRequest), nullptr, 0, 0) { |
| message_.LinearizeAndEncode<MethodRequest>(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: |
| MethodRequest& Message() { |
| return *reinterpret_cast<MethodRequest*>(message_.bytes()); |
| } |
| ::fidl::OutgoingMessage message_; |
| }; |
| |
| class OwnedEncodedMessage final { |
| public: |
| explicit OwnedEncodedMessage(zx_txid_t _txid, |
| ::llcpp::exampleusing::Empty& arg) |
| : message_(bytes_, sizeof(bytes_), _txid, arg) {} |
| explicit OwnedEncodedMessage(MethodRequest* request) |
| : message_(bytes_, sizeof(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: |
| 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<MethodRequest>(); |
| } |
| DecodedMessage(fidl_incoming_msg_t* msg) |
| : ::fidl::internal::IncomingMessage(msg) { |
| Decode<MethodRequest>(); |
| } |
| DecodedMessage(const DecodedMessage&) = delete; |
| DecodedMessage(DecodedMessage&&) = delete; |
| DecodedMessage* operator=(const DecodedMessage&) = delete; |
| DecodedMessage* operator=(DecodedMessage&&) = delete; |
| |
| MethodRequest* PrimaryObject() { |
| ZX_DEBUG_ASSERT(ok()); |
| return reinterpret_cast<MethodRequest*>(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<MethodRequest>(); |
| } |
| } |
| }; |
| |
| private: |
| void _InitHeader(zx_txid_t _txid); |
| }; |
| |
| // Collection of return types of FIDL calls in this protocol. |
| class ResultOf final { |
| ResultOf() = delete; |
| |
| public: |
| class Method final : public ::fidl::Result { |
| public: |
| explicit Method(zx_handle_t _client, ::llcpp::exampleusing::Empty& arg); |
| explicit Method(const ::fidl::Result& result) : ::fidl::Result(result) {} |
| Method(Method&&) = delete; |
| Method(const Method&) = delete; |
| Method* operator=(Method&&) = delete; |
| Method* operator=(const Method&) = delete; |
| ~Method() = default; |
| |
| private: |
| }; |
| }; |
| |
| // 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 Method final : public ::fidl::Result { |
| public: |
| explicit Method(zx_handle_t _client, uint8_t* _request_bytes, |
| uint32_t _request_byte_capacity, |
| ::llcpp::exampleusing::Empty& arg); |
| explicit Method(const ::fidl::Result& result) : ::fidl::Result(result) {} |
| Method(Method&&) = delete; |
| Method(const Method&) = delete; |
| Method* operator=(Method&&) = delete; |
| Method* operator=(const Method&) = delete; |
| ~Method() = default; |
| }; |
| }; |
| |
| // 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 message buffer on the stack. No heap allocation |
| // necessary. |
| static ResultOf::Method Method(::zx::unowned_channel _client_end, |
| ::llcpp::exampleusing::Empty arg) { |
| return ResultOf::Method(_client_end->get(), arg); |
| } |
| |
| // Caller provides the backing storage for FIDL message via request and |
| // response buffers. |
| static UnownedResultOf::Method Method(::zx::unowned_channel _client_end, |
| ::fidl::BufferSpan _request_buffer, |
| ::llcpp::exampleusing::Empty arg) { |
| return UnownedResultOf::Method(_client_end->get(), _request_buffer.data, |
| _request_buffer.capacity, arg); |
| } |
| }; |
| |
| 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 message buffer on the stack. No heap allocation |
| // necessary. |
| ResultOf::Method Method(::llcpp::exampleusing::Empty arg) { |
| return ResultOf::Method(this->channel().get(), arg); |
| } |
| |
| // Caller provides the backing storage for FIDL message via request and |
| // response buffers. |
| UnownedResultOf::Method Method(::fidl::BufferSpan _request_buffer, |
| ::llcpp::exampleusing::Empty arg) { |
| return UnownedResultOf::Method(this->channel().get(), |
| _request_buffer.data, |
| _request_buffer.capacity, arg); |
| } |
| |
| private: |
| ::zx::channel channel_; |
| }; |
| |
| struct AsyncEventHandlers; |
| 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 = ExampleProtocol; |
| |
| using MethodCompleter = ::fidl::Completer<>; |
| |
| virtual void Method(::llcpp::exampleusing::Empty arg, |
| MethodCompleter::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 placementofattributes |
| } // namespace test |
| } // namespace fidl |
| } // namespace llcpp |
| |
| namespace fidl { |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleXUnion> |
| : public std::true_type {}; |
| template <> |
| struct IsUnion<::llcpp::fidl::test::placementofattributes::ExampleXUnion> |
| : public std::true_type {}; |
| static_assert(std::is_standard_layout_v< |
| ::llcpp::fidl::test::placementofattributes::ExampleXUnion>); |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleUnion> |
| : public std::true_type {}; |
| template <> |
| struct IsUnion<::llcpp::fidl::test::placementofattributes::ExampleUnion> |
| : public std::true_type {}; |
| static_assert(std::is_standard_layout_v< |
| ::llcpp::fidl::test::placementofattributes::ExampleUnion>); |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleTable> |
| : public std::true_type {}; |
| template <> |
| struct IsTable<::llcpp::fidl::test::placementofattributes::ExampleTable> |
| : public std::true_type {}; |
| template <> |
| struct IsTableBuilder< |
| ::llcpp::fidl::test::placementofattributes::ExampleTable::Builder> |
| : public std::true_type {}; |
| static_assert(std::is_standard_layout_v< |
| ::llcpp::fidl::test::placementofattributes::ExampleTable>); |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleStruct> |
| : public std::true_type {}; |
| template <> |
| struct IsStruct<::llcpp::fidl::test::placementofattributes::ExampleStruct> |
| : public std::true_type {}; |
| static_assert(std::is_standard_layout_v< |
| ::llcpp::fidl::test::placementofattributes::ExampleStruct>); |
| static_assert( |
| offsetof(::llcpp::fidl::test::placementofattributes::ExampleStruct, |
| member) == 0); |
| static_assert( |
| sizeof(::llcpp::fidl::test::placementofattributes::ExampleStruct) == |
| ::llcpp::fidl::test::placementofattributes::ExampleStruct::PrimarySize); |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleEnum> |
| : public std::true_type {}; |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::placementofattributes::ExampleBits> |
| : public std::true_type {}; |
| static_assert(std::is_standard_layout_v< |
| ::llcpp::fidl::test::placementofattributes::ExampleBits>); |
| static_assert(sizeof(::llcpp::fidl::test::placementofattributes::ExampleBits) == |
| sizeof(uint32_t)); |
| |
| template <> |
| struct IsFidlType< |
| ::llcpp::fidl::test::placementofattributes::ExampleProtocol::MethodRequest> |
| : public std::true_type {}; |
| template <> |
| struct IsFidlMessage< |
| ::llcpp::fidl::test::placementofattributes::ExampleProtocol::MethodRequest> |
| : public std::true_type {}; |
| static_assert(sizeof(::llcpp::fidl::test::placementofattributes:: |
| ExampleProtocol::MethodRequest) == |
| ::llcpp::fidl::test::placementofattributes::ExampleProtocol:: |
| MethodRequest::PrimarySize); |
| static_assert(offsetof(::llcpp::fidl::test::placementofattributes:: |
| ExampleProtocol::MethodRequest, |
| arg) == 16); |
| |
| } // namespace fidl |
| |
| namespace llcpp { |
| |
| namespace fidl { |
| namespace test { |
| namespace placementofattributes { |
| |
| struct ExampleProtocol::AsyncEventHandlers {}; |
| |
| class ExampleProtocol::ClientImpl final : private ::fidl::internal::ClientBase { |
| public: |
| // Allocates 24 bytes of message buffer on the stack. No heap allocation |
| // necessary. |
| ::fidl::Result Method(::llcpp::exampleusing::Empty arg); |
| |
| // Caller provides the backing storage for FIDL message via request and |
| // response buffers. |
| ::fidl::Result Method(::fidl::BufferSpan _request_buffer, |
| ::llcpp::exampleusing::Empty arg); |
| |
| private: |
| friend class ::fidl::Client<ExampleProtocol>; |
| |
| 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 ExampleProtocol protocol, and can send events in that protocol. |
| class ExampleProtocol::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 ExampleProtocol::WeakEventSender { |
| public: |
| private: |
| friend class ::fidl::ServerBindingRef<ExampleProtocol>; |
| |
| explicit WeakEventSender( |
| std::weak_ptr<::fidl::internal::AsyncServerBinding<ExampleProtocol>> |
| binding) |
| : binding_(std::move(binding)) {} |
| |
| std::weak_ptr<::fidl::internal::AsyncServerBinding<ExampleProtocol>> binding_; |
| }; |
| |
| } // namespace placementofattributes |
| } // namespace test |
| } // namespace fidl |
| } // namespace llcpp |