types for async protocol extension
renamed AsyncMessage to ExceptionalMessage to make way for this new extension.
This commit is contained in:
parent
482422b9c5
commit
5f4228dc2b
3 changed files with 36 additions and 24 deletions
|
@ -132,13 +132,13 @@ handleRequest st req whenunavail responsehandler =
|
||||||
withExternalAddon st whenunavail $ \p -> do
|
withExternalAddon st whenunavail $ \p -> do
|
||||||
sendMessage p req
|
sendMessage p req
|
||||||
let loop = receiveResponse p responsehandler
|
let loop = receiveResponse p responsehandler
|
||||||
(Just . handleAsyncMessage loop)
|
(Just . handleExceptionalMessage loop)
|
||||||
loop
|
loop
|
||||||
where
|
where
|
||||||
handleAsyncMessage _ (ERROR err) = do
|
handleExceptionalMessage _ (ERROR err) = do
|
||||||
warning ("external special remote error: " ++ err)
|
warning ("external special remote error: " ++ err)
|
||||||
whenunavail
|
whenunavail
|
||||||
handleAsyncMessage loop (DEBUG msg) = do
|
handleExceptionalMessage loop (DEBUG msg) = do
|
||||||
liftIO $ debugM "external" msg
|
liftIO $ debugM "external" msg
|
||||||
loop
|
loop
|
||||||
|
|
||||||
|
@ -174,9 +174,9 @@ result = Just . return . Result
|
||||||
receiveResponse
|
receiveResponse
|
||||||
:: ExternalAddonProcess
|
:: ExternalAddonProcess
|
||||||
-> ResponseHandler a
|
-> ResponseHandler a
|
||||||
-> (AsyncMessage -> Maybe (Annex a))
|
-> (ExceptionalMessage -> Maybe (Annex a))
|
||||||
-> Annex a
|
-> Annex a
|
||||||
receiveResponse p handleresponse handleasync =
|
receiveResponse p handleresponse handleexceptional =
|
||||||
go =<< liftIO (catchMaybeIO $ hGetLine $ externalReceive p)
|
go =<< liftIO (catchMaybeIO $ hGetLine $ externalReceive p)
|
||||||
where
|
where
|
||||||
go Nothing = protocolError False ""
|
go Nothing = protocolError False ""
|
||||||
|
@ -188,9 +188,9 @@ receiveResponse p handleresponse handleasync =
|
||||||
Just callback -> callback >>= \case
|
Just callback -> callback >>= \case
|
||||||
Result a -> return a
|
Result a -> return a
|
||||||
GetNextMessage handleresponse' ->
|
GetNextMessage handleresponse' ->
|
||||||
receiveResponse p handleresponse' handleasync
|
receiveResponse p handleresponse' handleexceptional
|
||||||
Nothing -> case Proto.parseMessage s :: Maybe AsyncMessage of
|
Nothing -> case Proto.parseMessage s :: Maybe ExceptionalMessage of
|
||||||
Just msg -> maybe (protocolError True s) id (handleasync msg)
|
Just msg -> maybe (protocolError True s) id (handleexceptional msg)
|
||||||
Nothing -> protocolError False s
|
Nothing -> protocolError False s
|
||||||
|
|
||||||
protocolError parsed s = giveup $ "external backend protocol error, unexpectedly received \"" ++ s ++ "\" " ++
|
protocolError parsed s = giveup $ "external backend protocol error, unexpectedly received \"" ++ s ++ "\" " ++
|
||||||
|
@ -321,7 +321,7 @@ data Response
|
||||||
| PROGRESS BytesProcessed
|
| PROGRESS BytesProcessed
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data AsyncMessage
|
data ExceptionalMessage
|
||||||
= ERROR ErrorMsg
|
= ERROR ErrorMsg
|
||||||
| DEBUG String
|
| DEBUG String
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
@ -338,11 +338,11 @@ instance Proto.Serializable ProtocolVersion where
|
||||||
serialize (ProtocolVersion n) = show n
|
serialize (ProtocolVersion n) = show n
|
||||||
deserialize = ProtocolVersion <$$> readish
|
deserialize = ProtocolVersion <$$> readish
|
||||||
|
|
||||||
instance Proto.Sendable AsyncMessage where
|
instance Proto.Sendable ExceptionalMessage where
|
||||||
formatMessage (ERROR err) = ["ERROR", Proto.serialize err]
|
formatMessage (ERROR err) = ["ERROR", Proto.serialize err]
|
||||||
formatMessage (DEBUG msg) = ["DEBUG", Proto.serialize msg]
|
formatMessage (DEBUG msg) = ["DEBUG", Proto.serialize msg]
|
||||||
|
|
||||||
instance Proto.Receivable AsyncMessage where
|
instance Proto.Receivable ExceptionalMessage where
|
||||||
parseCommand "ERROR" = Proto.parse1 ERROR
|
parseCommand "ERROR" = Proto.parse1 ERROR
|
||||||
parseCommand "DEBUG" = Proto.parse1 DEBUG
|
parseCommand "DEBUG" = Proto.parse1 DEBUG
|
||||||
parseCommand _ = Proto.parseFail
|
parseCommand _ = Proto.parseFail
|
||||||
|
|
|
@ -396,7 +396,7 @@ handleRequest' st external req mp responsehandler
|
||||||
loop
|
loop
|
||||||
loop = receiveMessage st external responsehandler
|
loop = receiveMessage st external responsehandler
|
||||||
(\rreq -> Just $ handleRemoteRequest rreq >> loop)
|
(\rreq -> Just $ handleRemoteRequest rreq >> loop)
|
||||||
(\msg -> Just $ handleAsyncMessage msg >> loop)
|
(\msg -> Just $ handleExceptionalMessage msg >> loop)
|
||||||
|
|
||||||
handleRemoteRequest (PROGRESS bytesprocessed) =
|
handleRemoteRequest (PROGRESS bytesprocessed) =
|
||||||
maybe noop (\a -> liftIO $ a bytesprocessed) mp
|
maybe noop (\a -> liftIO $ a bytesprocessed) mp
|
||||||
|
@ -487,7 +487,7 @@ handleRequest' st external req mp responsehandler
|
||||||
handleRemoteRequest (INFO msg) = showInfo msg
|
handleRemoteRequest (INFO msg) = showInfo msg
|
||||||
handleRemoteRequest (VERSION _) = senderror "too late to send VERSION"
|
handleRemoteRequest (VERSION _) = senderror "too late to send VERSION"
|
||||||
|
|
||||||
handleAsyncMessage (ERROR err) = giveup $ "external special remote error: " ++ err
|
handleExceptionalMessage (ERROR err) = giveup $ "external special remote error: " ++ err
|
||||||
|
|
||||||
send = sendMessage st
|
send = sendMessage st
|
||||||
senderror = sendMessage st . ERROR
|
senderror = sendMessage st . ERROR
|
||||||
|
@ -532,9 +532,9 @@ receiveMessage
|
||||||
-> External
|
-> External
|
||||||
-> ResponseHandler a
|
-> ResponseHandler a
|
||||||
-> (RemoteRequest -> Maybe (Annex a))
|
-> (RemoteRequest -> Maybe (Annex a))
|
||||||
-> (AsyncMessage -> Maybe (Annex a))
|
-> (ExceptionalMessage -> Maybe (Annex a))
|
||||||
-> Annex a
|
-> Annex a
|
||||||
receiveMessage st external handleresponse handlerequest handleasync =
|
receiveMessage st external handleresponse handlerequest handleexceptional =
|
||||||
go =<< liftIO (catchMaybeIO $ hGetLine $ externalReceive $ externalAddonProcess st)
|
go =<< liftIO (catchMaybeIO $ hGetLine $ externalReceive $ externalAddonProcess st)
|
||||||
where
|
where
|
||||||
go Nothing = protocolError False ""
|
go Nothing = protocolError False ""
|
||||||
|
@ -546,11 +546,11 @@ receiveMessage st external handleresponse handlerequest handleasync =
|
||||||
Just callback -> callback >>= \case
|
Just callback -> callback >>= \case
|
||||||
Result a -> return a
|
Result a -> return a
|
||||||
GetNextMessage handleresponse' ->
|
GetNextMessage handleresponse' ->
|
||||||
receiveMessage st external handleresponse' handlerequest handleasync
|
receiveMessage st external handleresponse' handlerequest handleexceptional
|
||||||
Nothing -> case parseMessage s :: Maybe RemoteRequest of
|
Nothing -> case parseMessage s :: Maybe RemoteRequest of
|
||||||
Just req -> maybe (protocolError True s) id (handlerequest req)
|
Just req -> maybe (protocolError True s) id (handlerequest req)
|
||||||
Nothing -> case parseMessage s :: Maybe AsyncMessage of
|
Nothing -> case parseMessage s :: Maybe ExceptionalMessage of
|
||||||
Just msg -> maybe (protocolError True s) id (handleasync msg)
|
Just msg -> maybe (protocolError True s) id (handleexceptional msg)
|
||||||
Nothing -> protocolError False s
|
Nothing -> protocolError False s
|
||||||
protocolError parsed s = giveup $ "external special remote protocol error, unexpectedly received \"" ++ s ++ "\" " ++
|
protocolError parsed s = giveup $ "external special remote protocol error, unexpectedly received \"" ++ s ++ "\" " ++
|
||||||
if parsed
|
if parsed
|
||||||
|
|
24
Remote/External/Types.hs
vendored
24
Remote/External/Types.hs
vendored
|
@ -25,7 +25,7 @@ module Remote.External.Types (
|
||||||
Response(..),
|
Response(..),
|
||||||
RemoteRequest(..),
|
RemoteRequest(..),
|
||||||
RemoteResponse(..),
|
RemoteResponse(..),
|
||||||
AsyncMessage(..),
|
ExceptionalMessage(..),
|
||||||
ErrorMsg,
|
ErrorMsg,
|
||||||
Setting,
|
Setting,
|
||||||
Description,
|
Description,
|
||||||
|
@ -88,9 +88,8 @@ type PID = Int
|
||||||
newtype ExtensionList = ExtensionList [String]
|
newtype ExtensionList = ExtensionList [String]
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- When adding a new RemoteRequest, also add it to the list here.
|
|
||||||
supportedExtensionList :: ExtensionList
|
supportedExtensionList :: ExtensionList
|
||||||
supportedExtensionList = ExtensionList ["INFO"]
|
supportedExtensionList = ExtensionList ["INFO", "ASYNC"]
|
||||||
|
|
||||||
data PrepareStatus = Unprepared | Prepared | FailedPrepare ErrorMsg
|
data PrepareStatus = Unprepared | Prepared | FailedPrepare ErrorMsg
|
||||||
|
|
||||||
|
@ -323,17 +322,29 @@ instance Proto.Sendable RemoteResponse where
|
||||||
formatMessage (CREDS login password) = [ "CREDS", Proto.serialize login, Proto.serialize password ]
|
formatMessage (CREDS login password) = [ "CREDS", Proto.serialize login, Proto.serialize password ]
|
||||||
|
|
||||||
-- Messages that can be sent at any time by either git-annex or the remote.
|
-- Messages that can be sent at any time by either git-annex or the remote.
|
||||||
data AsyncMessage
|
data ExceptionalMessage
|
||||||
= ERROR ErrorMsg
|
= ERROR ErrorMsg
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
instance Proto.Sendable AsyncMessage where
|
instance Proto.Sendable ExceptionalMessage where
|
||||||
formatMessage (ERROR err) = [ "ERROR", Proto.serialize err ]
|
formatMessage (ERROR err) = [ "ERROR", Proto.serialize err ]
|
||||||
|
|
||||||
instance Proto.Receivable AsyncMessage where
|
instance Proto.Receivable ExceptionalMessage where
|
||||||
parseCommand "ERROR" = Proto.parse1 ERROR
|
parseCommand "ERROR" = Proto.parse1 ERROR
|
||||||
parseCommand _ = Proto.parseFail
|
parseCommand _ = Proto.parseFail
|
||||||
|
|
||||||
|
-- Messages used by the async protocol extension.
|
||||||
|
data AsyncMessage
|
||||||
|
= START_ASYNC JobId
|
||||||
|
| END_ASYNC JobId
|
||||||
|
| UPDATE_ASYNC JobId
|
||||||
|
|
||||||
|
instance Proto.Receivable AsyncMessage where
|
||||||
|
parseCommand "START-ASYNC" = Proto.parse1 START_ASYNC
|
||||||
|
parseCommand "END-ASYNC" = Proto.parse1 END_ASYNC
|
||||||
|
parseCommand "UPDATE-ASYNC" = Proto.parse1 UPDATE_ASYNC
|
||||||
|
parseCommand _ = Proto.parseFail
|
||||||
|
|
||||||
-- Data types used for parameters when communicating with the remote.
|
-- Data types used for parameters when communicating with the remote.
|
||||||
-- All are serializable.
|
-- All are serializable.
|
||||||
type ErrorMsg = String
|
type ErrorMsg = String
|
||||||
|
@ -341,6 +352,7 @@ type Setting = String
|
||||||
type Description = String
|
type Description = String
|
||||||
type ProtocolVersion = Int
|
type ProtocolVersion = Int
|
||||||
type Size = Maybe Integer
|
type Size = Maybe Integer
|
||||||
|
type JobId = String
|
||||||
|
|
||||||
supportedProtocolVersions :: [ProtocolVersion]
|
supportedProtocolVersions :: [ProtocolVersion]
|
||||||
supportedProtocolVersions = [1]
|
supportedProtocolVersions = [1]
|
||||||
|
|
Loading…
Reference in a new issue