# `Rclex`
[🔗](https://github.com/rclex/rclex/blob/v0.13.1/lib/rclex.ex#L1)

User API for `Elixir.Rclex`.

# `topic_name`

```elixir
@type topic_name() :: String.t()
```

`topic_name` must lead with "/".

# `publish`

```elixir
@spec publish(
  message :: struct(),
  topic_name :: topic_name(),
  node_name :: String.t(),
  opts :: [{:namespace, String.t()}]
) :: :ok | {:error, :not_found}
```

Publish message.

- `topic_name` must lead with "/"

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> alias Rclex.Pkgs.StdMsgs
    iex> Rclex.publish(struct(StdMsgs.Msg.String, %{data: "hello"}), "/chatter", "node", namespace: "/example")
    :ok
    iex> Rclex.publish(struct(StdMsgs.Msg.String, %{data: "hello"}), "/chatter", "node")
    {:error, :not_found}

# `start_node`

```elixir
@spec start_node(name :: String.t(), opts :: [{:namespace, String.t()}]) ::
  :ok | {:error, :already_started} | {:error, term()}
```

Start node.

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> Rclex.start_node("node", namespace: "/example")
    :ok
    iex> Rclex.start_node("node", namespace: "/example")
    {:error, :already_started}

# `start_publisher`

```elixir
@spec start_publisher(
  message_type :: module(),
  topic_name :: topic_name(),
  node_name :: String.t(),
  opts :: [namespace: String.t(), qos: Rclex.QoS.t()]
) :: :ok | {:error, :already_started} | {:error, term()}
```

Start publisher.

- `topic_name` must lead with "/"

## Examples

    iex> alias Rclex.Pkgs.StdMsgs
    iex> Rclex.start_publisher(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    :ok
    iex> Rclex.start_publisher(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    {:error, :already_started}

# `start_subscription`

```elixir
@spec start_subscription(
  callback :: function(),
  message_type :: module(),
  topic_name :: topic_name(),
  node_name :: String.t(),
  opts :: [namespace: String.t(), qos: Rclex.QoS.t()]
) :: :ok | {:error, :already_started} | {:error, term()}
```

Start subscription.

- `topic_name` must lead with "/"

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"
- `:qos` if not specified, applied the default which equals return of `Rclex.QoS.profile_default/0`

## Examples

    iex> alias Rclex.Pkgs.StdMsgs
    iex> Rclex.start_subscription(&IO.inspect/1, StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    :ok
    iex> Rclex.start_subscription(&IO.inspect/1, StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    {:error, :already_started}

# `start_timer`

```elixir
@spec start_timer(
  period_ms :: non_neg_integer(),
  callback :: function(),
  timer_name :: String.t(),
  node_name :: String.t(),
  opts :: [{:namespace, String.t()}]
) :: :ok | {:error, :already_started} | {:error, term()}
```

Start timer.

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> Rclex.start_timer(1000, fn -> IO.inspect("tick") end, "tick", "node", namespace: "/example")
    :ok
    iex> Rclex.start_timer(1000, fn -> IO.inspect("tick") end, "tick", "node", namespace: "/example")
    {:error, :already_started}

# `stop_node`

```elixir
@spec stop_node(name :: String.t(), opts :: [{:namespace, String.t()}]) ::
  :ok | {:error, :not_found}
```

Stop node. And also stop the entities on the node, `publisher`, `subscription` and `timer`.

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> Rclex.stop_node("node", namespace: "/example")
    :ok
    iex> Rclex.stop_node("node", namespace: "/example")
    {:error, :not_found}

# `stop_publisher`

```elixir
@spec stop_publisher(
  message_type :: module(),
  topic_name :: topic_name(),
  node_name :: String.t(),
  opts :: [{:namespace, String.t()}]
) :: :ok | {:error, :not_found}
```

Stop publisher.

- `topic_name` must lead with "/"

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> alias Rclex.Pkgs.StdMsgs
    iex> Rclex.stop_publisher(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    :ok
    iex> Rclex.stop_publisher(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    {:error, :not_found}

# `stop_subscription`

```elixir
@spec stop_subscription(
  message_type :: module(),
  topic_name :: topic_name(),
  node_name :: String.t(),
  opts :: [{:namespace, String.t()}]
) :: :ok | {:error, :not_found}
```

Stop subscription.

- `topic_name` must lead with "/"

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> alias Rclex.Pkgs.StdMsgs
    iex> Rclex.stop_subscription(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    :ok
    iex> Rclex.stop_subscription(StdMsgs.Msg.String, "/chatter", "node", namespace: "/example")
    {:error, :not_found}

# `stop_timer`

```elixir
@spec stop_timer(
  timer_name :: String.t(),
  node_name :: String.t(),
  opts :: [{:namespace, String.t()}]
) :: :ok | {:error, :not_found}
```

Stop timer.

### opts

- `:namespace` must lead with "/". if not specified, the default is "/"

## Examples

    iex> Rclex.stop_timer("tick", "node", namespace: "/example")
    :ok
    iex> Rclex.stop_timer("tick", "node", namespace: "/example")
    {:error, :not_found}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
