diff options
author | Will Thompson <will@willthompson.co.uk> | 2012-04-15 12:05:57 +0100 |
---|---|---|
committer | Will Thompson <will@willthompson.co.uk> | 2012-04-15 12:05:57 +0100 |
commit | 99588322f998852eb8a97de87a43e17f984d9b8c (patch) | |
tree | 69f2f575ee266e64e3c56897105f6b35aaa6b9d6 /Bustle/Loader | |
parent | 5d29c197e7cee089eb79bd5f289e3857d27d9049 (diff) |
Use some dbus-core types rather than String
Diffstat (limited to 'Bustle/Loader')
-rw-r--r-- | Bustle/Loader/OldSkool.hs | 21 | ||||
-rw-r--r-- | Bustle/Loader/Pcap.hs | 9 |
2 files changed, 23 insertions, 7 deletions
diff --git a/Bustle/Loader/OldSkool.hs b/Bustle/Loader/OldSkool.hs index 4a0ca9f..8976962 100644 --- a/Bustle/Loader/OldSkool.hs +++ b/Bustle/Loader/OldSkool.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedStrings #-} {- Bustle.Loader.OldSkool: reads the output of bustle-dbus-monitor Copyright © 2008–2011 Collabora Ltd. @@ -22,6 +23,8 @@ module Bustle.Loader.OldSkool where import Bustle.Types +import qualified DBus.Types as D +import qualified Data.Text as T import Text.ParserCombinators.Parsec hiding (Parser) import Data.Map (Map) import Data.Maybe (isJust) @@ -80,12 +83,24 @@ none = do string "<none>" return Nothing +pathify :: String -> D.ObjectPath +pathify s = case D.objectPath (T.pack s) of + Just p -> p + Nothing -> D.objectPath_ "/unparseable/object/path" + +interfacify :: String -> Maybe D.InterfaceName +interfacify = D.interfaceName . T.pack + +memberNamify :: String -> D.MemberName +memberNamify s = case D.memberName (T.pack s) of + Just m -> m + Nothing -> D.memberName_ "UnparseableMemberName" entireMember :: Parser Member entireMember = do - let p = many1 (oneOf "/_" <|> alphaNum) <?> "path" - i = none <|> fmap Just (many1 (oneOf "._" <|> alphaNum)) <?> "iface" - m = many1 (oneOf "_" <|> alphaNum) <?> "membername" + let p = pathify <$> many1 (oneOf "/_" <|> alphaNum) <?> "path" + i = none <|> fmap interfacify (many1 (oneOf "._" <|> alphaNum)) <?> "iface" + m = memberNamify <$> many1 (oneOf "_" <|> alphaNum) <?> "membername" Member <$> p <* t <*> i <* t <*> m <?> "member" diff --git a/Bustle/Loader/Pcap.hs b/Bustle/Loader/Pcap.hs index c87c947..40410b2 100644 --- a/Bustle/Loader/Pcap.hs +++ b/Bustle/Loader/Pcap.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedStrings #-} {- Bustle.Loader.Pcap: loads logs out of pcap files using dbus-core Copyright © 2011–2012 Collabora Ltd. @@ -69,9 +70,9 @@ convertMember :: (a -> ObjectPath) -> a -> B.Member convertMember getObjectPath getInterfaceName getMemberName m = - B.Member (T.unpack . objectPathText . getObjectPath $ m) - (fmap (T.unpack . interfaceNameText) . getInterfaceName $ m) - (T.unpack . memberNameText . getMemberName $ m) + B.Member (getObjectPath m) + (getInterfaceName m) + (getMemberName m) type PendingMessages = Map (Maybe BusName, Serial) (MethodCall, B.DetailedMessage) @@ -172,7 +173,7 @@ bustlify µs bytes m = do -- FIXME: obviously this should be more robust: -- • check that the service really is the bus daemon -- • don't crash if the body of the call or reply doesn't contain one bus name. - | B.membername (B.member (B.dmMessage dm)) == "GetNameOwner" + | memberNameText (B.membername (B.member (B.dmMessage dm))) == "GetNameOwner" -> bustlifyNOC ( fromJust . fromVariant $ (methodCallBody rawCall !! 0) , Nothing , fromVariant $ (methodReturnBody mr !! 0) |