|
|
|
@ -6,6 +6,7 @@ import Network.Xmpp.Types |
|
|
|
import Control.Applicative((<$>)) |
|
|
|
import Control.Applicative((<$>)) |
|
|
|
import Control.Concurrent |
|
|
|
import Control.Concurrent |
|
|
|
import Control.Concurrent.STM |
|
|
|
import Control.Concurrent.STM |
|
|
|
|
|
|
|
import Control.Concurrent.STM.TVar (TVar, readTVar, writeTVar) |
|
|
|
import qualified Control.Exception.Lifted as Ex |
|
|
|
import qualified Control.Exception.Lifted as Ex |
|
|
|
import Control.Monad.IO.Class |
|
|
|
import Control.Monad.IO.Class |
|
|
|
import Control.Monad.Reader |
|
|
|
import Control.Monad.Reader |
|
|
|
@ -151,7 +152,7 @@ waitForPresence f chans = do |
|
|
|
|
|
|
|
|
|
|
|
-- TODO: Wait for presence error? |
|
|
|
-- TODO: Wait for presence error? |
|
|
|
|
|
|
|
|
|
|
|
-- | Run an XmppMonad action in isolation. Reader and writer workers will be |
|
|
|
-- | Run an XmppConMonad action in isolation. Reader and writer workers will be |
|
|
|
-- temporarily stopped and resumed with the new session details once the action |
|
|
|
-- temporarily stopped and resumed with the new session details once the action |
|
|
|
-- returns. The action will run in the calling thread. Any uncaught exceptions |
|
|
|
-- returns. The action will run in the calling thread. Any uncaught exceptions |
|
|
|
-- will be interpreted as connection failure. |
|
|
|
-- will be interpreted as connection failure. |
|
|
|
@ -205,6 +206,14 @@ sendMessage m chans = sendStanza (MessageS m) chans |
|
|
|
-- | Executes a function to update the event handlers. |
|
|
|
-- | Executes a function to update the event handlers. |
|
|
|
modifyHandlers :: (EventHandlers -> EventHandlers) -> Session -> IO () |
|
|
|
modifyHandlers :: (EventHandlers -> EventHandlers) -> Session -> IO () |
|
|
|
modifyHandlers f session = atomically $ modifyTVar (eventHandlers session) f |
|
|
|
modifyHandlers f session = atomically $ modifyTVar (eventHandlers session) f |
|
|
|
|
|
|
|
where |
|
|
|
|
|
|
|
-- Borrowing modifyTVar from |
|
|
|
|
|
|
|
-- http://hackage.haskell.org/packages/archive/stm/2.4/doc/html/src/Control-Concurrent-STM-TVar.html |
|
|
|
|
|
|
|
-- as it's not available in GHC 7.0. |
|
|
|
|
|
|
|
modifyTVar :: TVar a -> (a -> a) -> STM () |
|
|
|
|
|
|
|
modifyTVar var f = do |
|
|
|
|
|
|
|
x <- readTVar var |
|
|
|
|
|
|
|
writeTVar var (f x) |
|
|
|
|
|
|
|
|
|
|
|
-- | Sets the handler to be executed when the server connection is closed. |
|
|
|
-- | Sets the handler to be executed when the server connection is closed. |
|
|
|
setConnectionClosedHandler :: (StreamError -> Session -> IO ()) -> Session -> IO () |
|
|
|
setConnectionClosedHandler :: (StreamError -> Session -> IO ()) -> Session -> IO () |
|
|
|
|