Skip to content

Commit

Permalink
Add properties changed signal
Browse files Browse the repository at this point in the history
  • Loading branch information
colonelpanic8 committed Mar 15, 2018
1 parent 96fc91b commit 3d58173
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
7 changes: 4 additions & 3 deletions dbus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ library
DBus
DBus.Client
DBus.Generation
DBus.Introspection
DBus.Socket
DBus.Transport
DBus.Internal.Address
DBus.Internal.Message
DBus.Internal.Types
DBus.Internal.Wire
DBus.Introspection
DBus.Socket
DBus.TH
DBus.Transport

test-suite dbus_tests
type: exitcode-stdio-1.0
Expand Down
54 changes: 41 additions & 13 deletions lib/DBus/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module DBus.Client
, setPropertyValue
, getAllProperties
, getAllPropertiesMap
, buildPropertiesInterface

-- * Receiving method calls
, export
Expand Down Expand Up @@ -129,6 +130,7 @@ module DBus.Client
, buildIntrospectionInterface
, buildIntrospectionMethod
, buildIntrospectionProperty
, buildIntrospectableInterface

-- * Name reservation
, requestName
Expand Down Expand Up @@ -453,21 +455,27 @@ buildPropertiesInterface :: Client -> Interface
buildPropertiesInterface client =
let alwaysPresent = clientInterfaces client
getPropertyObjF propertyInterfaceName memberName path info =
findInterfaceAtPath alwaysPresent info path (Just $ fromString propertyInterfaceName) >>=
findInterfaceAtPath alwaysPresent info path
(Just $ fromString propertyInterfaceName) >>=
(maybeToEither errorUnknownMethod . findProperty (fromString memberName))
getPropertyObj propertyInterfaceName memberName path =
getPropertyObjF propertyInterfaceName memberName path <$>
readIORef (clientObjects client)
callGet MethodCall { methodCallPath = path } propertyInterfaceName memberName =
callGet MethodCall { methodCallPath = path }
propertyInterfaceName memberName =
left makeErrorReply <$>
runExceptT (do
property <- ExceptT $ getPropertyObj propertyInterfaceName memberName path
ExceptT $ sequenceA $ maybeToEither errorNotAuthorized $ propertyGetter property)
callSet MethodCall { methodCallPath = path } propertyInterfaceName memberName value =
property <- ExceptT $ getPropertyObj propertyInterfaceName
memberName path
ExceptT $ sequenceA $ maybeToEither errorNotAuthorized $
propertyGetter property)
callSet MethodCall { methodCallPath = path }
propertyInterfaceName memberName value =
left makeErrorReply <$>
runExceptT (do
property <- ExceptT $ getPropertyObj propertyInterfaceName memberName path
setter <- ExceptT $ return $ maybeToEither errorNotAuthorized $ propertySetter property
setter <- ExceptT $ return $ maybeToEither errorNotAuthorized $
propertySetter property
lift $ setter value)
callGetAll MethodCall { methodCallPath = path } propertyInterfaceName =
left makeErrorReply <$>
Expand All @@ -484,13 +492,33 @@ buildPropertiesInterface client =
} <- properties]
lift $ M.fromList <$> T.sequenceA nameGetters)
in
defaultInterface { interfaceName = propertiesInterfaceName
, interfaceMethods =
[ autoMethodWithMsg "Get" callGet
, autoMethodWithMsg "GetAll" callGetAll
, autoMethodWithMsg "Set" callSet
]
}
defaultInterface
{ interfaceName = propertiesInterfaceName
, interfaceMethods =
[ autoMethodWithMsg "Get" callGet
, autoMethodWithMsg "GetAll" callGetAll
, autoMethodWithMsg "Set" callSet
]
, interfaceSignals =
[ I.Signal
{ I.signalName = "PropertiesChanged"
, I.signalArgs =
[ I.SignalArg
{ I.signalArgName = "interface_name"
, I.signalArgType = T.TypeString
}
, I.SignalArg
{ I.signalArgName = "changed_properties"
, I.signalArgType = T.TypeDictionary T.TypeString T.TypeVariant
}
, I.SignalArg
{ I.signalArgName = "invalidated_properties"
, I.signalArgType = T.TypeArray T.TypeString
}
]
}
]
}

buildIntrospectableInterface :: Client -> Interface
buildIntrospectableInterface client =
Expand Down

0 comments on commit 3d58173

Please sign in to comment.