blob: b4b8ba0666fa9ad3e5bfb76a9d2862d6653118fd (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
|
{- git-remote-daemon data types.
-
- Copyright 2014 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module RemoteDaemon.Types where
import qualified Git.Types as Git
import qualified Utility.SimpleProtocol as Proto
-- Messages that the daemon emits.
data Emitted
= CONNECTED RemoteName
| DISCONNECTED RemoteName
| CHANGED RemoteName ShaList
| STATUS RemoteName UserMessage
| ERROR RemoteName UserMessage
-- Messages that the deamon consumes.
data Consumed
= PAUSE
| RESUME
| PUSH RemoteName
| RELOAD
type RemoteName = String
type UserMessage = String
type ShaList = [Git.Sha]
instance Proto.Sendable Emitted where
formatMessage (CONNECTED remote) =
["CONNECTED", Proto.serialize remote]
formatMessage (DISCONNECTED remote) =
["DISCONNECTED", Proto.serialize remote]
formatMessage (CHANGED remote shas) =
["CHANGED"
, Proto.serialize remote
, Proto.serialize shas
]
formatMessage (STATUS remote msg) =
["STATUS"
, Proto.serialize remote
, Proto.serialize msg
]
formatMessage (ERROR remote msg) =
["ERROR"
, Proto.serialize remote
, Proto.serialize msg
]
instance Proto.Sendable Consumed where
formatMessage PAUSE = ["PAUSE"]
formatMessage RESUME = ["RESUME"]
formatMessage (PUSH remote) = ["PUSH", Proto.serialize remote]
formatMessage RELOAD = ["RELOAD"]
instance Proto.Receivable Emitted where
parseCommand "CONNECTED" = Proto.parse1 CONNECTED
parseCommand "DISCONNECTED" = Proto.parse1 DISCONNECTED
parseCommand "CHANGED" = Proto.parse2 CHANGED
parseCommand "STATUS" = Proto.parse2 STATUS
parseCommand "ERROR" = Proto.parse2 ERROR
parseCommand _ = Proto.parseFail
instance Proto.Receivable Consumed where
parseCommand "PAUSE" = Proto.parse0 PAUSE
parseCommand "RESUME" = Proto.parse0 RESUME
parseCommand "PUSH" = Proto.parse1 PUSH
parseCommand "RELOAD" = Proto.parse0 RELOAD
parseCommand _ = Proto.parseFail
instance Proto.Serializable [Char] where
serialize = id
deserialize = Just
instance Proto.Serializable ShaList where
serialize = unwords . map Git.fromRef
deserialize = Just . map Git.Ref . words
|