| |
| |
| |
| # bind method |
| |
| |
| |
| |
| |
| |
| |
| |
| void bind |
| (T impl, [InterfaceRequest](../../package-fidl_fidl/InterfaceRequest-class.md) interfaceRequest) |
| |
| |
| |
| |
| |
| <p>Binds the given implementation to the given interface request.</p> |
| <p>Listens for messages on channel underlying the given interface request, |
| decodes them, and dispatches the decoded messages to <code>impl</code>.</p> |
| <p>This object must not already be bound.</p> |
| <p>The <code>impl</code> and <code>interfaceRequest</code> parameters must not be <code>null</code>. The |
| <code>channel</code> property of the given <code>interfaceRequest</code> must not be <code>null</code>.</p> |
| <p>Implementation note: in a generic context, the inferred type when creating |
| the <code>interfaceRequest</code> may be a super-class of <code>T</code>, possibly <code>Service</code>. |
| Since concrete classes of <code>AsyncBinding</code> are code generated, the type |
| parameter <code>T</code> will always be precise, even when used in a generic context. |
| As a result, we cannot type-bound <code>interfaceRequest</code> statically, and |
| should instead rely on dynamic behavior.</p> |
| |
| |
| |
| ## Implementation |
| |
| ```dart |
| void bind(T impl, InterfaceRequest<dynamic> interfaceRequest) { |
| if (!isUnbound) { |
| throw FidlStateException("AsyncBinding<${$interfaceName}> isn't unbound"); |
| } |
| if (impl == null) { |
| throw FidlError( |
| "AsyncBinding<${$interfaceName}> can't bind to a null impl"); |
| } |
| |
| Channel? channel = interfaceRequest.passChannel(); |
| if (channel == null) { |
| throw FidlError( |
| "AsyncBinding<${$interfaceName}> can't bind to a null InterfaceRequest channel"); |
| } |
| |
| _impl = impl; |
| _reader.bind(channel); |
| |
| state = InterfaceState.bound; |
| } |
| ``` |
| |
| |
| |
| |
| |
| |
| |