template <class Service>

class ServiceReconnector

Defined at line 63 of file ../../src/lib/fidl/contrib/connection/service_reconnector.h

ServiceReconnector is a utility class to make staying connected to a fidl protocol easier.

Using this class requires defining a |ConnectLambda| that takes as an argument a

|ConnectResolver|.

NOTE: ServiceReconnector must be used from the |dispatcher| thread.

This includes construction, destruction, and making calls.

For example, if you had a fidl service like:

type error = strict enum : int32 {

ERROR = 1;

}

protocol SimpleProtocol {

DoAction() -> () error Error;

}

Then using service connector would be as simple as:

auto reconnector = ServiceReconnector

<SimpleProtocol

>::Create(dispatcher_, "SimpleProtocol",

[](ServiceReconnector

<SimpleProtocol

>::ConnectResolver resolver) {

auto connection = component::ConnectAt

<SimpleProtocol

>(svc());

if (connection.is_error()) {

resolver.resolve(std::nullopt);

} else {

resolver.resolve(std::move(connection.value()));

}

});

reconnector->Do([](fidl::Client

<SimpleProtocol

>

&protocol

) {

// Do something with |protocol| here.

})

Public Methods

std::shared_ptr<ServiceReconnector<Service>> Create (async_dispatcher_t * dispatcher, std::string tag, ConnectLambda && connect, size_t max_queued_callbacks, DisconnectLambda && disconnect)

Create makes an instance of ServiceReconnector.

|dispatcher| the dispatcher thread where the fidl service should be connected from.

|tag| Used in error messages, so that multiple ConnectResolvers will have distinguishable

logging.

|connect| A lambda that is called each time ServiceReconnector tries to connect or re-connect

to the service.

|max_queued_callbacks| (default: 20) How many |DoCallback|s should be stored while waiting for

a connection before further |DoCallback|s will be ignored.

|disconnect| Called whenever the ServiceReconnector detects that the underlying service has

been disconnected. Useful in the case of a nested ServiceReconnector, so that the

sub-service reconnect can be triggered if the parent service disconnects.

Defined at line 133 of file ../../src/lib/fidl/contrib/connection/service_reconnector.h

void Do (DoCallback && callback)

Defined at line 156 of file ../../src/lib/fidl/contrib/connection/service_reconnector.h

void Shutdown ()

Shutdown makes sure that no new |DoCallback|s will be queued, so the class can cleanly shut

down.

Defined at line 179 of file ../../src/lib/fidl/contrib/connection/service_reconnector.h

void Reconnect ()

Force a reconnection to the underlying service.

Defined at line 185 of file ../../src/lib/fidl/contrib/connection/service_reconnector.h

Records