refactor XMPP client
This commit is contained in:
parent
74385e3d38
commit
a1228e27ed
12 changed files with 291 additions and 175 deletions
31
Assistant/Types/NetMessager.hs
Normal file
31
Assistant/Types/NetMessager.hs
Normal file
|
@ -0,0 +1,31 @@
|
|||
{- git-annex assistant out of band network messager types
|
||||
-
|
||||
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Assistant.Types.NetMessager where
|
||||
|
||||
import Common.Annex
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MSampleVar
|
||||
|
||||
{- Messages that can be sent out of band by a network messager. -}
|
||||
data NetMessage = NotifyPush [UUID]
|
||||
|
||||
{- Controls for the XMPP client.
|
||||
-
|
||||
- It can be fed XMPP messages to send.
|
||||
-
|
||||
- It can also be sent a signal when it should restart for some reason. -}
|
||||
data NetMessagerControl = NetMessagerControl
|
||||
{ netMessages :: TChan (NetMessage)
|
||||
, netMessagerRestart :: MSampleVar ()
|
||||
}
|
||||
|
||||
newNetMessagerControl :: IO NetMessagerControl
|
||||
newNetMessagerControl = NetMessagerControl
|
||||
<$> atomically newTChan
|
||||
<*> newEmptySV
|
|
@ -8,10 +8,8 @@
|
|||
module Assistant.Types.Pushes where
|
||||
|
||||
import Common.Annex
|
||||
import Utility.TSet
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MSampleVar
|
||||
import Data.Time.Clock
|
||||
import qualified Data.Map as M
|
||||
|
||||
|
@ -19,24 +17,8 @@ import qualified Data.Map as M
|
|||
type PushMap = M.Map Remote UTCTime
|
||||
type FailedPushMap = TMVar PushMap
|
||||
|
||||
{- The TSet is recent, successful pushes that other remotes should be
|
||||
- notified about.
|
||||
-
|
||||
- The MSampleVar is written to when the PushNotifier thread should be
|
||||
- restarted for some reason.
|
||||
-}
|
||||
data PushNotifier = PushNotifier
|
||||
{ pushNotifierSuccesses :: TSet UUID
|
||||
, pushNotifierWaiter :: MSampleVar ()
|
||||
}
|
||||
|
||||
{- The TMVar starts empty, and is left empty when there are no
|
||||
- failed pushes. This way we can block until there are some failed pushes.
|
||||
-}
|
||||
newFailedPushMap :: IO FailedPushMap
|
||||
newFailedPushMap = atomically newEmptyTMVar
|
||||
|
||||
newPushNotifier :: IO PushNotifier
|
||||
newPushNotifier = PushNotifier
|
||||
<$> newTSet
|
||||
<*> newEmptySV
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue