template <typename FidlMethod>
class WireResponseContext
Defined at line 198 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/client_base.h
|WireResponseContext| is used to monitor the outcome of an outstanding asynchronous
|FidlMethod| method call without heap memory allocation. They are used in
combination with the caller-allocating async API flavors of FIDL clients.
## Lifecycle
The FIDL runtime has no requirements on how |WireResponseContext|s are
allocated.
Once a |WireResponseContext| is passed to the client, ownership is
transferred to the FIDL runtime. Ownership is returned back to the user when
|OnResult| is invoked. This means that the user must keep the response
context object alive for the duration of the async method call. |OnResult| is
guaranteed to be invoked exactly once regardless of success or error.
## Usage
Subclass |WireResponseContext| and override its |OnResult| method. Example:
// Lets say we have a `Game` object that loads some required asset
// using the `Disk` FIDL protocol and its `Download` method.
class Game : public fidl::WireResponseContext
<Disk
::Download> {
public:
void LoadGame() {
// Passing `this` to the caller-allocating flavor since `Game`
// implements the corresponding response context.
disk_client_.buffer(arena_)->Download("foo.zip").ThenExactlyOnce(this);
}
private:
void OnResult(fidl::WireUnownedResult
<Disk
::Download>
&
result) final {
if (!result.ok()) {
std::cerr
<
<
"Downloading failed: "
<
<
result.error();
return;
}
// Access the response.
fidl::WireResponse
<Disk
::Download>
&
response = result.value();
}
fidl::WireClient
<Disk
> disk_client_;
fidl::Arena
<
> arena_;
};
Public Methods
void OnResult (::fidl::internal::WireUnownedResultType<FidlMethod> & result)
Invoked when a response has been received or an error was detected for this
call.
## If |result| represents a success
|result| borrows the decoded response. The implementation may transfer out
handles contained in the message, but should not access the bytes in
|result| once this method returns.
## If |result| represents an error
An error occurred while processing this FIDL call:
- Failed to encode the outgoing request specific to this call.
- Failed to decode the incoming response specific to this call.
- The peer endpoint was closed.
- Error from the |async_dispatcher_t|.
- Error from the underlying transport.
- The server sent a malformed message.
- The user explicitly initiated binding teardown.
- The call raced with an external error in the meantime that caused binding
teardown.
|OnResult| is always invoked asynchronously whether in case of success
or error, unless the dispatcher is shut down, in which case it will be
called synchronously.
void WireResponseContext<FidlMethod> ()
Defined at line 200 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/client_base.h