refactor XMPP client

This commit is contained in:
Joey Hess 2012-11-03 14:16:17 -04:00
parent 74385e3d38
commit a1228e27ed
12 changed files with 291 additions and 175 deletions

View 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

View file

@ -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