diff options
author | Mitchell Rosen <mitchellwrosen@gmail.com> | 2018-10-27 16:51:05 -0500 |
---|---|---|
committer | Mitchell Rosen <mitchellwrosen@gmail.com> | 2018-10-27 22:11:56 -0500 |
commit | 719cc5375972fdab189bc1672dfa062e1734f75a (patch) | |
tree | 2f22e09a3de03333590bd2b9ea061bd1e7efa565 /src/IPC/DBus.hs | |
parent | 559c61db9571f887263bdfc0f736aaa2bab9e265 (diff) | |
download | xmobar-719cc5375972fdab189bc1672dfa062e1734f75a.tar.gz xmobar-719cc5375972fdab189bc1672dfa062e1734f75a.tar.bz2 |
Return a dbus error if unknown method or signal
Diffstat (limited to 'src/IPC/DBus.hs')
-rw-r--r-- | src/IPC/DBus.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/IPC/DBus.hs b/src/IPC/DBus.hs index b9bffd5..f6fdcb7 100644 --- a/src/IPC/DBus.hs +++ b/src/IPC/DBus.hs @@ -17,7 +17,7 @@ module IPC.DBus (runIPC) where import DBus import DBus.Client hiding (interfaceName) import qualified DBus.Client as DC -import Control.Monad (when) +import Data.Maybe (isNothing) import Control.Concurrent.STM import Control.Exception (handle) import System.IO (stderr, hPutStrLn) @@ -57,10 +57,17 @@ sendSignalMethod mvst = makeMethod sendSignalName sendSignalName = memberName_ "SendSignal" sendSignalMethodCall :: MethodCall -> DBusR Reply - sendSignalMethodCall mc = liftIO $ do - when ( methodCallMember mc == sendSignalName ) - $ mapM_ (sendSignal . fromVariant) (methodCallBody mc) - return ( ReplyReturn [] ) + sendSignalMethodCall mc = liftIO $ + if methodCallMember mc == sendSignalName + then do + let signals :: [Maybe SignalType] + signals = map fromVariant (methodCallBody mc) + mapM_ sendSignal signals + if any isNothing signals + then return ( ReplyError errorInvalidParameters [] ) + else return ( ReplyReturn [] ) + else + return ( ReplyError errorUnknownMethod [] ) sendSignal :: Maybe SignalType -> IO () sendSignal = maybe (return ()) (atomically . putTMVar mvst) |