# `ExCEP.Cluster.Server`

Edge Cluster (Master) TCP/TLS server and Gateway session registry.

Listens on a CEP channel port (`9901` for `:management` or `9902` for `:business`,
or port `0` for OS-assigned ephemeral ports in tests), spawns an `ExCEP.Cluster.Session`
per connected Edge Gateway, and routes Cluster -> Gateway commands by `gateway_id`.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_session`

```elixir
@spec get_session(GenServer.server(), String.t()) ::
  {:ok, pid()} | {:error, :not_connected}
```

Looks up the active `ExCEP.Cluster.Session` pid for `gateway_id`.

# `list_gateways`

```elixir
@spec list_gateways(GenServer.server()) :: [String.t()]
```

Returns the list of currently connected and authenticated `gateway_id`s.

# `port`

```elixir
@spec port(GenServer.server()) :: :inet.port_number()
```

Returns the bound TCP listening port.

# `pull_file`

```elixir
@spec pull_file(GenServer.server(), String.t(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, term()}
```

Pulls a file from a connected Gateway using Section 6.2.1 (`FileGet` + `FileDataTrans`).

# `push_file`

```elixir
@spec push_file(GenServer.server(), String.t(), String.t(), binary(), keyword()) ::
  :ok | {:error, term()}
```

Pushes a binary file to a connected Gateway using Section 6.2.2 (`FileSend` + `FileDataTrans`).

# `request`

```elixir
@spec request(GenServer.server(), String.t(), ExCEP.Codec.DataAsdu.t(), keyword()) ::
  {:ok, ExCEP.Codec.DataAsdu.t()} | {:error, term()}
```

Sends a `%DataAsdu{}` request to `gateway_id` and awaits its correlated response.

# `send_asdu`

```elixir
@spec send_asdu(GenServer.server(), String.t(), ExCEP.Codec.DataAsdu.t(), keyword()) ::
  :ok | {:error, term()}
```

Sends a one-way `%DataAsdu{}` to the connected `gateway_id`.

# `start_link`

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

# `stop`

```elixir
@spec stop(GenServer.server()) :: :ok
```

Stops the Cluster server and closes all active sessions.

---

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