NervesHubLink.Extensions behaviour (nerves_hub_link v2.7.2)

View Source

Extensions are a mechanism for transmitting messages for non-critical functionality over the existing NervesHub Socket. An extension will only attach if the server-side requests it from the device to ensure it will not disrupt regular operation.

This module provides a behaviour with a macro to use for implementing an Extension.

Extensions are started as separate GenServers under a DynamicSupervisor and any messages namespaced for a specific extension will be forwarded to that extension's GenServer.

Summary

Callbacks

Invoked when routing an Extension event

Functions

Attach specified extensions

Returns a specification to start this module under a supervisor.

Detach specified extensions

List extensions currently available

Callbacks

handle_event(t, map, state)

@callback handle_event(String.t(), map(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()

Invoked when routing an Extension event

Behaves the same as GenServer.handle_info/2

Functions

attach(extension)

@spec attach(String.t() | [String.t()] | :all) :: :ok

Attach specified extensions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

detach(extension)

@spec detach(String.t() | [String.t()] | :all) :: :ok

Detach specified extensions

Also supports :all as an argument for cases NervesHubLink may want to detach all of them at once

handle_event(event, message)

@spec handle_event(String.t(), map()) :: :ok

list()

@spec list() :: [
  %{
    required(String.t()) => %{
      attached?: boolean(),
      attach_ref: String.t(),
      module: module(),
      version: boolean()
    }
  }
]

List extensions currently available

start_link(opts \\ [])

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