Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/switchx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ defmodule SwitchX do
def auth(conn, password),
do: auth(conn, password, @timeout)

@spec auth(conn :: pid(), password :: String.t(), timeout :: non_neg_integer()) :: {:ok, term} | {:error, term}
@spec auth(conn :: pid(), password :: String.t(), timeout :: non_neg_integer()) ::
{:ok, term} | {:error, term}
def auth(conn, password, timeout),
do: safe_gen_call(conn, {:auth, password}, timeout)

Expand Down Expand Up @@ -85,7 +86,8 @@ defmodule SwitchX do
def bg_api(conn, args),
do: bg_api(conn, args, @timeout)

@spec bg_api(conn :: pid(), args :: String.t(), timeout :: non_neg_integer()) :: {:ok, event :: SwitchX.Event}
@spec bg_api(conn :: pid(), args :: String.t(), timeout :: non_neg_integer()) ::
{:ok, event :: SwitchX.Event}
def bg_api(conn, args, timeout),
do: safe_gen_call(conn, {:bgapi, args}, timeout)

Expand Down Expand Up @@ -172,7 +174,7 @@ defmodule SwitchX do
event :: SwitchX.Event,
event_uuid :: nil | String.t(),
timeout :: non_neg_integer()
) :: {:ok, term} | :error
) :: {:ok, term} | :error
def send_event(conn, event_name, event, event_uuid, timeout) do
safe_gen_call(conn, {:sendevent, event_name, event, event_uuid}, timeout)
end
Expand All @@ -199,7 +201,12 @@ defmodule SwitchX do
send_message(conn, nil, event, @timeout)
end

@spec send_message(conn :: pid(), uuid :: nil | String.t(), event :: SwitchX.Event, timeout :: non_neg_integer()) :: {:ok, term}
@spec send_message(
conn :: pid(),
uuid :: nil | String.t(),
event :: SwitchX.Event,
timeout :: non_neg_integer()
) :: {:ok, term}
def send_message(conn, uuid, event, timeout) do
safe_gen_call(conn, {:sendmsg, uuid, event}, timeout)
end
Expand Down Expand Up @@ -244,7 +251,8 @@ defmodule SwitchX do
The 'myevents' subscription allows your inbound socket connection to behave like an outbound socket connect.
It will "lock on" to the events for a particular uuid and will ignore all other events
"""
@spec my_events(conn :: pid(), uuid :: nil | String.t(), timeout :: non_neg_integer()) :: :ok | {:error, term}
@spec my_events(conn :: pid(), uuid :: nil | String.t(), timeout :: non_neg_integer()) ::
:ok | {:error, term}
def my_events(conn, uuid, timeout),
do: safe_gen_call(conn, {:myevents, uuid}, timeout)

Expand Down Expand Up @@ -366,7 +374,8 @@ defmodule SwitchX do
defp safe_gen_call(conn, command, timeout) do
try do
:gen_statem.call(conn, command, timeout)
rescue
catch
:exit, err -> err
err -> err
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/switchx/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule SwitchX.Connection do
end

defp post_init(data) do
Logger.info("SwitchX #{inspect self()} Starting.")
Logger.info("SwitchX #{inspect(self())} Starting.")
:telemetry.execute([:switchx, :connection, data.connection_mode], %{value: 1}, %{})
end

Expand Down Expand Up @@ -111,6 +111,7 @@ defmodule SwitchX.Connection do
case content_type do
"text/disconnect-notice" ->
handle_event(:disconnect, event, state, data)

^content_type ->
apply(__MODULE__, state, [:event, event, data])
end
Expand Down Expand Up @@ -259,7 +260,7 @@ defmodule SwitchX.Connection do
end

def ready(:call, {:bgapi, args}, from, data) do
#job_uuid = UUID.uuid4()
# job_uuid = UUID.uuid4()
:gen_tcp.send(data.socket, "bgapi #{args}\n\n")
data = put_in(data.commands_sent, :queue.in(from, data.commands_sent))
{:keep_state, data}
Expand Down Expand Up @@ -350,7 +351,7 @@ defmodule SwitchX.Connection do
@impl true
def terminate(reason, _state, data) do
:telemetry.execute([:switchx, :connection, data.connection_mode], %{value: -1}, %{})
Logger.info("SwitchX #{inspect self()} Finishing. #{inspect reason}")
Logger.info("SwitchX #{inspect(self())} Finishing. #{inspect(reason)}")
:ok
end

Expand Down
2 changes: 1 addition & 1 deletion lib/switchx/connection/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule SwitchX.Connection.Socket do

# case :gen_tcp.recv(socket, 0) do
case :gen_tcp.recv(socket, 0, 1_000) do
#Socket has closed, parsing data until now
# Socket has closed, parsing data until now
{:error, :closed} ->
# Logger.info("SwitchXSock closed with payload: #{inspect payload}")
SwitchX.Event.new(payload)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule SwitchX.MixProject do
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :telemetry,]
extra_applications: [:logger, :telemetry]
]
end

Expand Down