| // 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/bti.h> |
| #include <lib/zx/channel.h> |
| #include <lib/zx/clock.h> |
| #include <lib/zx/debuglog.h> |
| #include <lib/zx/event.h> |
| #include <lib/zx/eventpair.h> |
| #include <lib/zx/exception.h> |
| #include <lib/zx/fifo.h> |
| #include <lib/zx/guest.h> |
| #include <lib/zx/handle.h> |
| #include <lib/zx/interrupt.h> |
| #include <lib/zx/iommu.h> |
| #include <lib/zx/job.h> |
| #include <lib/zx/pager.h> |
| #include <lib/zx/pcidevice.h> |
| #include <lib/zx/pmt.h> |
| #include <lib/zx/port.h> |
| #include <lib/zx/process.h> |
| #include <lib/zx/profile.h> |
| #include <lib/zx/resource.h> |
| #include <lib/zx/socket.h> |
| #include <lib/zx/suspendtoken.h> |
| #include <lib/zx/thread.h> |
| #include <lib/zx/timer.h> |
| #include <lib/zx/vcpu.h> |
| #include <lib/zx/vmar.h> |
| #include <lib/zx/vmo.h> |
| #endif // __Fuchsia__ |
| #include <zircon/fidl.h> |
| |
| namespace llcpp { |
| |
| namespace fidl { |
| namespace test { |
| namespace handles { |
| |
| enum class obj_type : uint32_t { |
| |
| NONE = 0u, |
| |
| PROCESS = 1u, |
| |
| THREAD = 2u, |
| |
| VMO = 3u, |
| |
| CHANNEL = 4u, |
| |
| EVENT = 5u, |
| |
| PORT = 6u, |
| |
| INTERRUPT = 9u, |
| |
| PCI_DEVICE = 11u, |
| |
| LOG = 12u, |
| |
| SOCKET = 14u, |
| |
| RESOURCE = 15u, |
| |
| EVENTPAIR = 16u, |
| |
| JOB = 17u, |
| |
| VMAR = 18u, |
| |
| FIFO = 19u, |
| |
| GUEST = 20u, |
| |
| VCPU = 21u, |
| |
| TIMER = 22u, |
| |
| IOMMU = 23u, |
| |
| BTI = 24u, |
| |
| PROFILE = 25u, |
| |
| PMT = 26u, |
| |
| SUSPEND_TOKEN = 27u, |
| |
| PAGER = 28u, |
| |
| EXCEPTION = 29u, |
| |
| CLOCK = 30u, |
| |
| STREAM = 31u, |
| |
| MSI_ALLOCATION = 32u, |
| |
| MSI_INTERRUPT = 33u, |
| }; |
| |
| struct Handles; |
| class SomeProtocol; |
| |
| #ifdef __Fuchsia__ |
| extern "C" const fidl_type_t fidl_test_handles_HandlesTable; |
| |
| struct Handles { |
| static constexpr const fidl_type_t* Type = &fidl_test_handles_HandlesTable; |
| static constexpr uint32_t MaxNumHandles = 33; |
| static constexpr uint32_t PrimarySize = 132; |
| [[maybe_unused]] static constexpr uint32_t MaxOutOfLine = 0; |
| static constexpr bool HasPointer = false; |
| |
| ::zx::handle plain_handle = {}; |
| |
| ::zx::bti bti_handle = {}; |
| |
| ::zx::channel channel_handle = {}; |
| |
| ::zx::clock clock_handle = {}; |
| |
| ::zx::debuglog debuglog_handle = {}; |
| |
| ::zx::event event_handle = {}; |
| |
| ::zx::eventpair eventpair_handle = {}; |
| |
| ::zx::exception exception_handle = {}; |
| |
| ::zx::fifo fifo_handle = {}; |
| |
| ::zx::guest guest_handle = {}; |
| |
| ::zx::interrupt interrupt_handle = {}; |
| |
| ::zx::iommu iommu_handle = {}; |
| |
| ::zx::job job_handle = {}; |
| |
| ::zx::pager pager_handle = {}; |
| |
| ::zx::pcidevice pcidevice_handle = {}; |
| |
| ::zx::pmt pmt_handle = {}; |
| |
| ::zx::port port_handle = {}; |
| |
| ::zx::process process_handle = {}; |
| |
| ::zx::profile profile_handle = {}; |
| |
| ::zx::resource resource_handle = {}; |
| |
| ::zx::socket socket_handle = {}; |
| |
| ::zx::suspendtoken suspendtoken_handle = {}; |
| |
| ::zx::thread thread_handle = {}; |
| |
| ::zx::timer timer_handle = {}; |
| |
| ::zx::vcpu vcpu_handle = {}; |
| |
| ::zx::vmar vmar_handle = {}; |
| |
| ::zx::vmo vmo_handle = {}; |
| |
| ::zx::vmo rights_handle = {}; |
| |
| ::zx::handle aliased_plain_handle_field = {}; |
| |
| ::zx::vmo aliased_subtype_handle_field = {}; |
| |
| ::zx::vmo aliased_rights_handle_field = {}; |
| |
| ::zx::channel some_protocol = {}; |
| |
| ::zx::channel request_some_protocol = {}; |
| |
| void _CloseHandles(); |
| |
| class UnownedEncodedMessage final { |
| public: |
| UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size, Handles* value) |
| : message_(bytes, byte_size, sizeof(Handles), handles_, |
| std::min(ZX_CHANNEL_MAX_MSG_HANDLES, MaxNumHandles), 0) { |
| message_.LinearizeAndEncode<Handles>(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: |
| zx_handle_disposition_t |
| handles_[std::min(ZX_CHANNEL_MAX_MSG_HANDLES, MaxNumHandles)]; |
| ::fidl::OutgoingMessage message_; |
| }; |
| |
| class OwnedEncodedMessage final { |
| public: |
| explicit OwnedEncodedMessage(Handles* 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 Handles>(); |
| } |
| DecodedMessage(fidl_incoming_msg_t* msg) |
| : ::fidl::internal::IncomingMessage(msg) { |
| Decode<struct Handles>(); |
| } |
| DecodedMessage(const DecodedMessage&) = delete; |
| DecodedMessage(DecodedMessage&&) = delete; |
| DecodedMessage* operator=(const DecodedMessage&) = delete; |
| DecodedMessage* operator=(DecodedMessage&&) = delete; |
| ~DecodedMessage() { |
| if (ok() && (PrimaryObject() != nullptr)) { |
| PrimaryObject()->_CloseHandles(); |
| } |
| } |
| |
| struct Handles* PrimaryObject() { |
| ZX_DEBUG_ASSERT(ok()); |
| return reinterpret_cast<struct Handles*>(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) { |
| zx_handle_info_t |
| handles[std::min(ZX_CHANNEL_MAX_MSG_HANDLES, MaxNumHandles)]; |
| Init(outgoing_message, handles, |
| std::min(ZX_CHANNEL_MAX_MSG_HANDLES, MaxNumHandles)); |
| if (ok()) { |
| Decode<struct Handles>(); |
| } |
| } |
| }; |
| }; |
| #endif // __Fuchsia__ |
| |
| class SomeProtocol final { |
| SomeProtocol() = delete; |
| |
| public: |
| // Collection of return types of FIDL calls in this protocol. |
| class ResultOf final { |
| ResultOf() = delete; |
| |
| public: |
| }; |
| |
| // 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: |
| }; |
| |
| // Methods to make a sync FIDL call directly on an unowned channel, avoiding |
| // setting up a client. |
| class Call final { |
| Call() = delete; |
| |
| public: |
| }; |
| |
| 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_; } |
| |
| 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 = SomeProtocol; |
| |
| 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 handles |
| } // namespace test |
| } // namespace fidl |
| } // namespace llcpp |
| |
| namespace fidl { |
| |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::handles::obj_type> |
| : public std::true_type {}; |
| |
| #ifdef __Fuchsia__ |
| template <> |
| struct IsFidlType<::llcpp::fidl::test::handles::Handles> |
| : public std::true_type {}; |
| template <> |
| struct IsStruct<::llcpp::fidl::test::handles::Handles> : public std::true_type { |
| }; |
| static_assert(std::is_standard_layout_v<::llcpp::fidl::test::handles::Handles>); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, plain_handle) == |
| 0); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, bti_handle) == 4); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, channel_handle) == |
| 8); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, clock_handle) == |
| 12); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| debuglog_handle) == 16); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, event_handle) == |
| 20); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| eventpair_handle) == 24); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| exception_handle) == 28); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, fifo_handle) == |
| 32); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, guest_handle) == |
| 36); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| interrupt_handle) == 40); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, iommu_handle) == |
| 44); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, job_handle) == |
| 48); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, pager_handle) == |
| 52); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| pcidevice_handle) == 56); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, pmt_handle) == |
| 60); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, port_handle) == |
| 64); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, process_handle) == |
| 68); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, profile_handle) == |
| 72); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| resource_handle) == 76); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, socket_handle) == |
| 80); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| suspendtoken_handle) == 84); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, thread_handle) == |
| 88); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, timer_handle) == |
| 92); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, vcpu_handle) == |
| 96); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, vmar_handle) == |
| 100); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, vmo_handle) == |
| 104); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, rights_handle) == |
| 108); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| aliased_plain_handle_field) == 112); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| aliased_subtype_handle_field) == 116); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| aliased_rights_handle_field) == 120); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, some_protocol) == |
| 124); |
| static_assert(offsetof(::llcpp::fidl::test::handles::Handles, |
| request_some_protocol) == 128); |
| static_assert(sizeof(::llcpp::fidl::test::handles::Handles) == |
| ::llcpp::fidl::test::handles::Handles::PrimarySize); |
| #endif // __Fuchsia__ |
| |
| } // namespace fidl |
| |
| namespace llcpp { |
| |
| namespace fidl { |
| namespace test { |
| namespace handles { |
| |
| struct SomeProtocol::AsyncEventHandlers {}; |
| |
| class SomeProtocol::ClientImpl final : private ::fidl::internal::ClientBase { |
| public: |
| private: |
| friend class ::fidl::Client<SomeProtocol>; |
| |
| 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 SomeProtocol protocol, and can send events in that protocol. |
| class SomeProtocol::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 SomeProtocol::WeakEventSender { |
| public: |
| private: |
| friend class ::fidl::ServerBindingRef<SomeProtocol>; |
| |
| explicit WeakEventSender( |
| std::weak_ptr<::fidl::internal::AsyncServerBinding<SomeProtocol>> binding) |
| : binding_(std::move(binding)) {} |
| |
| std::weak_ptr<::fidl::internal::AsyncServerBinding<SomeProtocol>> binding_; |
| }; |
| |
| } // namespace handles |
| } // namespace test |
| } // namespace fidl |
| } // namespace llcpp |