-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnerves_hub_link.ex
72 lines (60 loc) · 1.91 KB
/
nerves_hub_link.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
defmodule NervesHubLink do
@moduledoc """
The Device-side client for NervesHub.
The `:nerves_hub_link` Erlang application will start by default if installed
as a dependency and use provided configuration to connect to a NervesHub
server.
This module primarily provides utility functions for checking the status of
the connection and performing some operations such as reconnecting, sending
a file to a connected console and more.
"""
alias NervesHubLink.Socket
@doc """
Checks if the device is connected to the NervesHub device channel.
"""
@spec connected?() :: boolean()
def connected?() do
Socket.check_connection(:device)
end
@spec console_connected?() :: boolean()
def console_connected?() do
Socket.check_connection(:console)
end
@doc """
Checks if the device has a socket connection with NervesHub
"""
@spec socket_connected?() :: boolean()
def socket_connected?() do
Socket.check_connection(:socket)
end
@doc """
Return whether there's currently an active console session
"""
@spec console_active?() :: boolean()
defdelegate console_active?, to: Socket
@doc """
Current status of the update manager
"""
@spec status :: NervesHubLink.UpdateManager.State.status()
defdelegate status(), to: NervesHubLink.UpdateManager
@doc """
Restart the socket and device channel
"""
@spec reconnect() :: :ok
defdelegate reconnect(), to: Socket
@doc """
Send update progress percentage for display in web
"""
@spec send_update_progress(non_neg_integer()) :: :ok
defdelegate send_update_progress(progress), to: Socket
@doc """
Send an update status to web
"""
@spec send_update_status(String.t() | atom()) :: :ok
defdelegate send_update_status(status), to: Socket
@doc """
Send a file to the connected console
"""
@spec send_file(Path.t()) :: :ok | {:error, :too_large | File.posix()}
defdelegate send_file(file_path), to: Socket
end