Skip to content

Commit

Permalink
Improve void/structure return logic
Browse files Browse the repository at this point in the history
  • Loading branch information
colonelpanic8 committed Mar 16, 2018
1 parent 1e5c3a4 commit 1663cf3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/DBus/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ class AutoMethod a where
funTypes :: a -> ([Type], [Type])
apply :: a -> [Variant] -> IO Reply

handleTopLevelReturn value =
case toVariant value of
Variant (ValueStructure xs) -> fmap Variant xs
v -> [v]

instance IsValue a => AutoMethod (IO a) where
funTypes io = cased where
cased = ([], case ioT io undefined of
Expand All @@ -1100,11 +1105,7 @@ instance IsValue a => AutoMethod (IO a) where
ioT :: IsValue a => IO a -> a -> (a, Type)
ioT _ a = (a, typeOf a)

apply io [] = ReplyReturn <$> (do
var <- fmap toVariant io
case fromVariant var of
Just struct -> return (structureItems struct)
Nothing -> return [var])
apply io [] = ReplyReturn . handleTopLevelReturn <$> io
apply _ _ = returnInvalidParameters

instance IsValue a => AutoMethod (IO (Either Reply a)) where
Expand All @@ -1116,7 +1117,7 @@ instance IsValue a => AutoMethod (IO (Either Reply a)) where
TypeStructure ts -> ts
_ -> [aType]

apply io [] = either id (makeSuccessReply . toVariant) <$> io
apply io [] = either id (ReplyReturn . handleTopLevelReturn) <$> io
apply _ _ = returnInvalidParameters

instance (IsValue a, AutoMethod fn) => AutoMethod (a -> fn) where
Expand Down

0 comments on commit 1663cf3

Please sign in to comment.