blob: 032b960d991c9bdf1211db5c193051a433670db6 [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 service {
class SecondProtocol;
class FirstProtocol;
class SingleMemberService;
class MultiHomogeneousMemberService;
class MultiHeterogeneousMemberService;
class EmptyService;
extern "C" const fidl_type_t
fidl_test_service_SecondProtocolMethodOnSecondRequestTable;
extern "C" const fidl_type_t
fidl_test_service_SecondProtocolMethodOnSecondResponseTable;
class SecondProtocol final {
SecondProtocol() = delete;
public:
struct MethodOnSecondRequest final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
explicit MethodOnSecondRequest(zx_txid_t _txid) { _InitHeader(_txid); }
static constexpr const fidl_type_t* Type =
&::fidl::_llcpp_coding_AnyZeroArgMessageTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 16;
static constexpr uint32_t MaxOutOfLine = 0;
static constexpr uint32_t AltPrimarySize = 16;
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)
: message_(_bytes, _byte_size, sizeof(MethodOnSecondRequest), nullptr,
0, 0) {
FIDL_ALIGNDECL MethodOnSecondRequest _request(_txid);
message_.LinearizeAndEncode<MethodOnSecondRequest>(&_request);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
MethodOnSecondRequest* request)
: message_(bytes, byte_size, sizeof(MethodOnSecondRequest), nullptr,
0, 0) {
message_.LinearizeAndEncode<MethodOnSecondRequest>(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:
MethodOnSecondRequest& Message() {
return *reinterpret_cast<MethodOnSecondRequest*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(zx_txid_t _txid)
: message_(bytes_, sizeof(bytes_), _txid) {}
explicit OwnedEncodedMessage(MethodOnSecondRequest* 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<MethodOnSecondRequest>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<MethodOnSecondRequest>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
MethodOnSecondRequest* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<MethodOnSecondRequest*>(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<MethodOnSecondRequest>();
}
}
};
private:
void _InitHeader(zx_txid_t _txid);
};
// Collection of return types of FIDL calls in this protocol.
class ResultOf final {
ResultOf() = delete;
public:
class MethodOnSecond final : public ::fidl::Result {
public:
explicit MethodOnSecond(zx_handle_t _client);
explicit MethodOnSecond(const ::fidl::Result& result)
: ::fidl::Result(result) {}
MethodOnSecond(MethodOnSecond&&) = delete;
MethodOnSecond(const MethodOnSecond&) = delete;
MethodOnSecond* operator=(MethodOnSecond&&) = delete;
MethodOnSecond* operator=(const MethodOnSecond&) = delete;
~MethodOnSecond() = 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 MethodOnSecond final : public ::fidl::Result {
public:
explicit MethodOnSecond(zx_handle_t _client);
explicit MethodOnSecond(const ::fidl::Result& result)
: ::fidl::Result(result) {}
MethodOnSecond(MethodOnSecond&&) = delete;
MethodOnSecond(const MethodOnSecond&) = delete;
MethodOnSecond* operator=(MethodOnSecond&&) = delete;
MethodOnSecond* operator=(const MethodOnSecond&) = delete;
~MethodOnSecond() = 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 16 bytes of message buffer on the stack. No heap allocation
// necessary.
static ResultOf::MethodOnSecond MethodOnSecond(
::zx::unowned_channel _client_end) {
return ResultOf::MethodOnSecond(_client_end->get());
}
};
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 16 bytes of message buffer on the stack. No heap allocation
// necessary.
ResultOf::MethodOnSecond MethodOnSecond() {
return ResultOf::MethodOnSecond(this->channel().get());
}
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 = SecondProtocol;
using MethodOnSecondCompleter = ::fidl::Completer<>;
virtual void MethodOnSecond(MethodOnSecondCompleter::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_service_FirstProtocolMethodOnFirstRequestTable;
extern "C" const fidl_type_t
fidl_test_service_FirstProtocolMethodOnFirstResponseTable;
class FirstProtocol final {
FirstProtocol() = delete;
public:
struct MethodOnFirstRequest final {
FIDL_ALIGNDECL
fidl_message_header_t _hdr;
explicit MethodOnFirstRequest(zx_txid_t _txid) { _InitHeader(_txid); }
static constexpr const fidl_type_t* Type =
&::fidl::_llcpp_coding_AnyZeroArgMessageTable;
static constexpr uint32_t MaxNumHandles = 0;
static constexpr uint32_t PrimarySize = 16;
static constexpr uint32_t MaxOutOfLine = 0;
static constexpr uint32_t AltPrimarySize = 16;
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)
: message_(_bytes, _byte_size, sizeof(MethodOnFirstRequest), nullptr,
0, 0) {
FIDL_ALIGNDECL MethodOnFirstRequest _request(_txid);
message_.LinearizeAndEncode<MethodOnFirstRequest>(&_request);
}
UnownedEncodedMessage(uint8_t* bytes, uint32_t byte_size,
MethodOnFirstRequest* request)
: message_(bytes, byte_size, sizeof(MethodOnFirstRequest), nullptr, 0,
0) {
message_.LinearizeAndEncode<MethodOnFirstRequest>(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:
MethodOnFirstRequest& Message() {
return *reinterpret_cast<MethodOnFirstRequest*>(message_.bytes());
}
::fidl::OutgoingMessage message_;
};
class OwnedEncodedMessage final {
public:
explicit OwnedEncodedMessage(zx_txid_t _txid)
: message_(bytes_, sizeof(bytes_), _txid) {}
explicit OwnedEncodedMessage(MethodOnFirstRequest* 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<MethodOnFirstRequest>();
}
DecodedMessage(fidl_incoming_msg_t* msg)
: ::fidl::internal::IncomingMessage(msg) {
Decode<MethodOnFirstRequest>();
}
DecodedMessage(const DecodedMessage&) = delete;
DecodedMessage(DecodedMessage&&) = delete;
DecodedMessage* operator=(const DecodedMessage&) = delete;
DecodedMessage* operator=(DecodedMessage&&) = delete;
MethodOnFirstRequest* PrimaryObject() {
ZX_DEBUG_ASSERT(ok());
return reinterpret_cast<MethodOnFirstRequest*>(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<MethodOnFirstRequest>();
}
}
};
private:
void _InitHeader(zx_txid_t _txid);
};
// Collection of return types of FIDL calls in this protocol.
class ResultOf final {
ResultOf() = delete;
public:
class MethodOnFirst final : public ::fidl::Result {
public:
explicit MethodOnFirst(zx_handle_t _client);
explicit MethodOnFirst(const ::fidl::Result& result)
: ::fidl::Result(result) {}
MethodOnFirst(MethodOnFirst&&) = delete;
MethodOnFirst(const MethodOnFirst&) = delete;
MethodOnFirst* operator=(MethodOnFirst&&) = delete;
MethodOnFirst* operator=(const MethodOnFirst&) = delete;
~MethodOnFirst() = 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 MethodOnFirst final : public ::fidl::Result {
public:
explicit MethodOnFirst(zx_handle_t _client);
explicit MethodOnFirst(const ::fidl::Result& result)
: ::fidl::Result(result) {}
MethodOnFirst(MethodOnFirst&&) = delete;
MethodOnFirst(const MethodOnFirst&) = delete;
MethodOnFirst* operator=(MethodOnFirst&&) = delete;
MethodOnFirst* operator=(const MethodOnFirst&) = delete;
~MethodOnFirst() = 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 16 bytes of message buffer on the stack. No heap allocation
// necessary.
static ResultOf::MethodOnFirst MethodOnFirst(
::zx::unowned_channel _client_end) {
return ResultOf::MethodOnFirst(_client_end->get());
}
};
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 16 bytes of message buffer on the stack. No heap allocation
// necessary.
ResultOf::MethodOnFirst MethodOnFirst() {
return ResultOf::MethodOnFirst(this->channel().get());
}
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 = FirstProtocol;
using MethodOnFirstCompleter = ::fidl::Completer<>;
virtual void MethodOnFirst(MethodOnFirstCompleter::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;
};
class SingleMemberService final {
SingleMemberService() = default;
public:
static constexpr char Name[] = "fidl.test.service.SingleMemberService";
// 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 "single_member". 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<FirstProtocol>>
connect_single_member() {
::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("single_member"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<FirstProtocol>(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 "single_member" 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_single_member(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("single_member", std::move(handler));
}
private:
::llcpp::fidl::ServiceHandlerInterface* service_handler_; // Not owned.
};
};
class MultiHomogeneousMemberService final {
MultiHomogeneousMemberService() = default;
public:
static constexpr char Name[] =
"fidl.test.service.MultiHomogeneousMemberService";
// 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 "first_member". 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<FirstProtocol>>
connect_first_member() {
::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("first_member"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<FirstProtocol>(std::move(local)));
}
// Connects to the member protocol "second_member". 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<FirstProtocol>>
connect_second_member() {
::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("second_member"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<FirstProtocol>(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 "first_member" 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_first_member(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("first_member", std::move(handler));
}
// Adds member "second_member" 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_second_member(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("second_member", std::move(handler));
}
private:
::llcpp::fidl::ServiceHandlerInterface* service_handler_; // Not owned.
};
};
class MultiHeterogeneousMemberService final {
MultiHeterogeneousMemberService() = default;
public:
static constexpr char Name[] =
"fidl.test.service.MultiHeterogeneousMemberService";
// 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 "first_member". 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<FirstProtocol>>
connect_first_member() {
::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("first_member"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<FirstProtocol>(std::move(local)));
}
// Connects to the member protocol "second_member". 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<SecondProtocol>>
connect_second_member() {
::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("second_member"), std::move(remote));
if (result != ZX_OK) {
return ::fit::error(result);
}
return ::fit::ok(::fidl::ClientChannel<SecondProtocol>(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 "first_member" 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_first_member(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("first_member", std::move(handler));
}
// Adds member "second_member" 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_second_member(
::llcpp::fidl::ServiceHandlerInterface::MemberHandler handler) {
return service_handler_->AddMember("second_member", std::move(handler));
}
private:
::llcpp::fidl::ServiceHandlerInterface* service_handler_; // Not owned.
};
};
class EmptyService final {
EmptyService() = default;
public:
static constexpr char Name[] = "fidl.test.service.EmptyService";
// 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) {
(void)dir;
(void)connect_func;
}
private:
};
// 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) {
(void)service_handler;
}
private:
};
};
} // namespace service
} // namespace test
} // namespace fidl
} // namespace llcpp
namespace fidl {
template <>
struct IsFidlType<
::llcpp::fidl::test::service::SecondProtocol::MethodOnSecondRequest>
: public std::true_type {};
template <>
struct IsFidlMessage<
::llcpp::fidl::test::service::SecondProtocol::MethodOnSecondRequest>
: public std::true_type {};
static_assert(
sizeof(
::llcpp::fidl::test::service::SecondProtocol::MethodOnSecondRequest) ==
::llcpp::fidl::test::service::SecondProtocol::MethodOnSecondRequest::
PrimarySize);
template <>
struct IsFidlType<
::llcpp::fidl::test::service::FirstProtocol::MethodOnFirstRequest>
: public std::true_type {};
template <>
struct IsFidlMessage<
::llcpp::fidl::test::service::FirstProtocol::MethodOnFirstRequest>
: public std::true_type {};
static_assert(
sizeof(::llcpp::fidl::test::service::FirstProtocol::MethodOnFirstRequest) ==
::llcpp::fidl::test::service::FirstProtocol::MethodOnFirstRequest::
PrimarySize);
} // namespace fidl
namespace llcpp {
namespace fidl {
namespace test {
namespace service {
struct SecondProtocol::AsyncEventHandlers {};
class SecondProtocol::ClientImpl final : private ::fidl::internal::ClientBase {
public:
// Allocates 16 bytes of message buffer on the stack. No heap allocation
// necessary.
::fidl::Result MethodOnSecond();
private:
friend class ::fidl::Client<SecondProtocol>;
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 SecondProtocol protocol, and can send events in that protocol.
class SecondProtocol::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 SecondProtocol::WeakEventSender {
public:
private:
friend class ::fidl::ServerBindingRef<SecondProtocol>;
explicit WeakEventSender(
std::weak_ptr<::fidl::internal::AsyncServerBinding<SecondProtocol>>
binding)
: binding_(std::move(binding)) {}
std::weak_ptr<::fidl::internal::AsyncServerBinding<SecondProtocol>> binding_;
};
struct FirstProtocol::AsyncEventHandlers {};
class FirstProtocol::ClientImpl final : private ::fidl::internal::ClientBase {
public:
// Allocates 16 bytes of message buffer on the stack. No heap allocation
// necessary.
::fidl::Result MethodOnFirst();
private:
friend class ::fidl::Client<FirstProtocol>;
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 FirstProtocol protocol, and can send events in that protocol.
class FirstProtocol::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 FirstProtocol::WeakEventSender {
public:
private:
friend class ::fidl::ServerBindingRef<FirstProtocol>;
explicit WeakEventSender(
std::weak_ptr<::fidl::internal::AsyncServerBinding<FirstProtocol>>
binding)
: binding_(std::move(binding)) {}
std::weak_ptr<::fidl::internal::AsyncServerBinding<FirstProtocol>> binding_;
};
} // namespace service
} // namespace test
} // namespace fidl
} // namespace llcpp