Drone.Supervisor (ex_drone v0.3.0)

View Source

Dynamic supervisor for drone vehicle processes.

Each drone is started as a child Drone.Vehicle process under this supervisor. Processes are looked up by name via the Drone.Vehicle.Registry.

Prefer Drone.connect/2 / Drone.disconnect/1 over calling this module directly unless you are embedding vehicles in a custom supervision tree.

Examples

{:ok, _pid} = Drone.Supervisor.start_link([])

{:ok, _vehicle} =
  Drone.Supervisor.start_vehicle(
    name: :alpha,
    adapter: :sim
  )

:ok = Drone.Supervisor.stop_vehicle(:alpha)

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the dynamic supervisor (named Drone.Supervisor).

Starts a Drone.Vehicle child under this supervisor.

Terminates the vehicle registered under name.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the dynamic supervisor (named Drone.Supervisor).

Parameters

Returns

GenServer.on_start().

Examples

{:ok, _pid} = Drone.Supervisor.start_link([])

start_vehicle(opts)

@spec start_vehicle(keyword()) :: Supervisor.on_start_child()

Starts a Drone.Vehicle child under this supervisor.

Parameters

Returns

Supervisor.on_start_child() ({:ok, pid} \| {:error, reason}).

Examples

{:ok, _pid} =
  Drone.Supervisor.start_vehicle(
    name: :sim_1,
    adapter: :sim,
    battery: 100
  )

stop_vehicle(name)

@spec stop_vehicle(atom()) :: :ok | {:error, :not_found}

Terminates the vehicle registered under name.

Parameters

Returns

  • :ok — child terminated
  • {:error, :not_found} — no process registered under that name

Examples

:ok = Drone.Supervisor.stop_vehicle(:sim_1)
{:error, :not_found} = Drone.Supervisor.stop_vehicle(:missing)