summaryrefslogtreecommitdiff
path: root/Connection.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-15 14:47:51 -0400
committerjoe <joe@jerkface.net>2018-06-15 14:47:51 -0400
commit6e50379635c26ba050ae66d9d60ebc38b0a3aa8c (patch)
tree51493c91e7b0ee89ee1b5f7186151f5fb62060a2 /Connection.hs
parent14b5e5189458fb656bd67099d6908eabb029b3b0 (diff)
Documentation to protocol-generic Connection interface.
Diffstat (limited to 'Connection.hs')
-rw-r--r--Connection.hs34
1 files changed, 30 insertions, 4 deletions
diff --git a/Connection.hs b/Connection.hs
index 58b4f4e5..fc4025eb 100644
--- a/Connection.hs
+++ b/Connection.hs
@@ -9,18 +9,24 @@ import qualified Data.Map as Map
9 9
10import PingMachine 10import PingMachine
11 11
12-- | This type indicates the current status of a connection. The type
13-- parameter indicates protocol-specific status information. To present
14-- information as a user-comprehensible string, use 'showStatus'.
12data Status status 15data Status status
13 = Dormant 16 = Dormant
14 | InProgress status 17 | InProgress status
15 | Established 18 | Established
16 deriving (Show,Eq,Ord,Functor) 19 deriving (Show,Eq,Ord,Functor)
17 20
21-- | A policy indicates a desired connection status.
18data Policy 22data Policy
19 = RefusingToConnect 23 = RefusingToConnect -- ^ We desire no connection.
20 | OpenToConnect 24 | OpenToConnect -- ^ We will cooperate if a remote side initiates.
21 | TryingToConnect 25 | TryingToConnect -- ^ We desire to be connected.
22 deriving (Eq,Ord,Show) 26 deriving (Eq,Ord,Show)
23 27
28-- | Read-only information obtained via the 'connections' interface to
29-- 'Manager'.
24data Connection status = Connection 30data Connection status = Connection
25 { connStatus :: STM (Status status) 31 { connStatus :: STM (Status status)
26 , connPolicy :: STM Policy 32 , connPolicy :: STM Policy
@@ -28,20 +34,40 @@ data Connection status = Connection
28 } 34 }
29 deriving Functor 35 deriving Functor
30 36
37-- | This is an interface to make or query status information about connections
38-- of a specific kind.
39--
40-- Type parameters:
41--
42-- /k/ names a connection. It should implement Ord, and can be parsed and
43-- displayed using 'stringToKey' and 'showKey'.
44--
45-- /status/ indicates the progress of a connection. It is intended as a
46-- parameter to the 'InProgress' constructor of 'Status'.
47--
31data Manager status k = Manager 48data Manager status k = Manager
32 { setPolicy :: k -> Policy -> IO () 49 { -- | Connect or disconnect a connection.
50 setPolicy :: k -> Policy -> IO ()
51 -- | Obtain a list (in Map form) of all possible connections, whether
52 -- connected or not.
33 , connections :: STM (Map k (Connection status)) 53 , connections :: STM (Map k (Connection status))
54 -- | Parse a connection key out of a string. Inverse of 'showKey'.
34 , stringToKey :: String -> Maybe k 55 , stringToKey :: String -> Maybe k
56 -- | Convert a progress value to a string.
35 , showProgress :: status -> String 57 , showProgress :: status -> String
58 -- | Show a connection key as a string.
36 , showKey :: k -> String 59 , showKey :: k -> String
37 } 60 }
38 61
62-- | Present status information (visible in a UI) for a connection.
39showStatus :: Manager status k -> Status status -> String 63showStatus :: Manager status k -> Status status -> String
40showStatus mgr Dormant = "dormant" 64showStatus mgr Dormant = "dormant"
41showStatus mgr Established = "established" 65showStatus mgr Established = "established"
42showStatus mgr (InProgress s) = "in progress ("++showProgress mgr s++")" 66showStatus mgr (InProgress s) = "in progress ("++showProgress mgr s++")"
43 67
44 68
69-- | Combine two different species of 'Manager' into a single interface using
70-- 'Either' to combine key and status types.
45addManagers :: (Ord kA, Ord kB) => 71addManagers :: (Ord kA, Ord kB) =>
46 Manager statusA kA 72 Manager statusA kA
47 -> Manager statusB kB 73 -> Manager statusB kB