chromium/chromecast/external_mojo/public/mojom/connector.mojom

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module chromecast.external_mojo.mojom;

import "mojo/public/mojom/base/time.mojom";

// Struct for information provided when calling QueryServiceList().
struct ExternalServiceInfo {
  // Service name provided to RegisterServiceInstance.
  string name;
  // TimeTicks value when the service was last registered.
  mojo_base.mojom.TimeTicks connect_time;
  // TimeTicks value when the service was disconnected.
  // This value is set to TimeTicks() if the service is currently connected.
  mojo_base.mojom.TimeTicks disconnect_time;
};

// Interface for external (non-Chromium process) Mojo services to receive Mojo
// binding requests from other processes/services.
interface ExternalService {
  // Called when another service/process wants to bind to the interface with the
  // given |interface_name| on this service.
  OnBindInterface(string interface_name,
                  handle<message_pipe> interface_pipe);
};

struct ServiceInstanceInfo {
   string service_name;
   pending_remote<ExternalService> service_remote;
};

// Interface to register external Mojo services to the broker, and bind to
// registered Mojo services. This provides functionality similar to Chromium's
// service manager, but avoids any dependency on the service manager since this
// is intended for use by code outside of the Chrome repository.
interface ExternalConnector {
  // Registers services with the broker.
  RegisterServiceInstances(array<ServiceInstanceInfo> instances_info);

  // Asks the broker to pass the |interface_pipe| to the registered service with
  // the given |service_name| to be bound to the appropriate interface. If the
  // |service_name| is not registered yet, the request will remain pending until
  // the service is registered.
  BindInterface(string service_name,
                string interface_name,
                handle<message_pipe> interface_pipe);

  // Binds a new receiver to the Connector implementation, to allow clients to
  // clone Connector pointers for use on other threads.
  Clone(pending_receiver<ExternalConnector> receiver);

  // Binds to a Chromium service_manager::Connector instance, if possible.
  BindChromiumConnector(handle<message_pipe> interface_pipe);

  // Query services that are available from this connector.
  QueryServiceList() => (array<ExternalServiceInfo> services);
};