Bluez.DBus (bluez v0.1.0)

Copy Markdown View Source

Shared helpers for outbound D-Bus method calls to org.bluez over a rebus connection, used by Bluez.Client (passive scanning) and Bluez.Gatt (active connections).

The rebus connection correlates in-flight calls by serial and replies via GenServer.reply/2, so concurrent calls on one connection don't serialize — a slow Device1.Connect does not block a ReadValue to another device. The timeout here is purely the caller's patience (GenServer.call/3 exit, surfaced as {:error, {:exit, ...}}).

Callers beware: these block the calling process for up to timeout. Call from a Task (never from a GenServer's own loop) for anything that can be slow — Connect can take ~25 s, GATT reads up to the ATT timeout.

Summary

Functions

Install a bus-side match rule so the daemon routes matching signals to this connection (rebus installs none by itself).

Synchronous method call to org.bluez{:ok, reply_body} | {:error, reason}.

Like call/7 but to an arbitrary bus name. call/7 is this with destination: "org.bluez"; Bluez.BlueAlsa uses it to reach org.bluealsa over the same kind of connection. Same error normalization.

Fetch org.bluez's full object tree (ObjectManager.GetManagedObjects).

Functions

add_match(conn, rule)

@spec add_match(pid(), String.t()) :: term()

Install a bus-side match rule so the daemon routes matching signals to this connection (rebus installs none by itself).

call(conn, path, interface, member, signature, body, timeout \\ 5000)

@spec call(pid(), String.t(), String.t(), String.t(), String.t(), list(), timeout()) ::
  {:ok, list()} | {:error, term()}

Synchronous method call to org.bluez{:ok, reply_body} | {:error, reason}.

Pass signature: "" for argument-less members. Errors are normalized: a D-Bus error reply yields {:error, error_name}, a raise yields {:error, exception}, and a GenServer.call timeout / dead connection yields {:error, {:exit, reason}} (exits are caught, not propagated).

call_to(conn, destination, path, interface, member, signature, body, timeout \\ 5000)

@spec call_to(
  pid(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  list(),
  timeout()
) :: {:ok, list()} | {:error, term()}

Like call/7 but to an arbitrary bus name. call/7 is this with destination: "org.bluez"; Bluez.BlueAlsa uses it to reach org.bluealsa over the same kind of connection. Same error normalization.

get_managed_objects(conn, timeout \\ 5000)

@spec get_managed_objects(pid(), timeout()) :: {:ok, list()} | {:error, term()}

Fetch org.bluez's full object tree (ObjectManager.GetManagedObjects).