ENH log failures for bluetooth listeners
This commit is contained in:
parent
04a7a70747
commit
7432a8f841
|
@ -28,6 +28,11 @@ module Data.Internal.DBus
|
||||||
, fromSingletonVariant
|
, fromSingletonVariant
|
||||||
, bodyToMaybe
|
, bodyToMaybe
|
||||||
, exportPair
|
, exportPair
|
||||||
|
, displayBusName
|
||||||
|
, displayObjectPath
|
||||||
|
, displayMemberName
|
||||||
|
, displayInterfaceName
|
||||||
|
, displayWrapQuote
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -200,8 +205,7 @@ matchSignalFull client b p i m = do
|
||||||
case res of
|
case res of
|
||||||
Just o -> return $ Just $ matchSignal (Just o) p i m
|
Just o -> return $ Just $ matchSignal (Just o) p i m
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
logError $
|
logError msg
|
||||||
"could not add signal matcher on bus " <> bus_ <> " with match: " <> match
|
|
||||||
return Nothing
|
return Nothing
|
||||||
where
|
where
|
||||||
bus_ = displayWrapQuote $ displayBusName b
|
bus_ = displayWrapQuote $ displayBusName b
|
||||||
|
@ -209,11 +213,11 @@ matchSignalFull client b p i m = do
|
||||||
path_ = displayWrapQuote . displayObjectPath <$> p
|
path_ = displayWrapQuote . displayObjectPath <$> p
|
||||||
mem_ = displayWrapQuote . displayMemberName <$> m
|
mem_ = displayWrapQuote . displayMemberName <$> m
|
||||||
match =
|
match =
|
||||||
displayWrapQuote $
|
intersperse ", " $
|
||||||
mconcat $
|
mapMaybe (\(k, v) -> fmap ((k <> "=") <>) v) $
|
||||||
intersperse ", " $
|
zip ["interface", "path", "member"] [iface_, path_, mem_]
|
||||||
mapMaybe (\(k, v) -> fmap ((k <> "=") <>) v) $
|
stem = "could not get match rule for bus " <> bus_
|
||||||
zip ["interface", "path", "member"] [iface_, path_, mem_]
|
msg = if null match then stem else stem <> " where " <> mconcat match
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Properties
|
-- Properties
|
||||||
|
|
|
@ -81,7 +81,6 @@ startAdapter is cs cb cl = do
|
||||||
forM_ (findAdapter ot) $ \adapter -> do
|
forM_ (findAdapter ot) $ \adapter -> do
|
||||||
-- set up adapter
|
-- set up adapter
|
||||||
initAdapter state adapter cl
|
initAdapter state adapter cl
|
||||||
-- TODO this step could fail; at least warn the user...
|
|
||||||
void $ addAdaptorListener state dpy adapter cl
|
void $ addAdaptorListener state dpy adapter cl
|
||||||
-- set up devices on the adapter (and listeners for adding/removing devices)
|
-- set up devices on the adapter (and listeners for adding/removing devices)
|
||||||
let devices = findDevices adapter ot
|
let devices = findDevices adapter ot
|
||||||
|
@ -223,6 +222,8 @@ initAdapter
|
||||||
-> m ()
|
-> m ()
|
||||||
initAdapter state adapter client = do
|
initAdapter state adapter client = do
|
||||||
reply <- callGetPowered adapter client
|
reply <- callGetPowered adapter client
|
||||||
|
-- TODO this could fail if the variant is something weird; the only
|
||||||
|
-- indication I will get is "NA"
|
||||||
putPowered state $ fromSingletonVariant reply
|
putPowered state $ fromSingletonVariant reply
|
||||||
|
|
||||||
matchBTProperty
|
matchBTProperty
|
||||||
|
@ -232,6 +233,31 @@ matchBTProperty
|
||||||
-> m (Maybe MatchRule)
|
-> m (Maybe MatchRule)
|
||||||
matchBTProperty sys p = matchPropertyFull sys btBus (Just p)
|
matchBTProperty sys p = matchPropertyFull sys btBus (Just p)
|
||||||
|
|
||||||
|
withBTPropertyRule
|
||||||
|
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m, IsVariant a)
|
||||||
|
=> SysClient
|
||||||
|
-> ObjectPath
|
||||||
|
-> (Maybe a -> m ())
|
||||||
|
-> InterfaceName
|
||||||
|
-> T.Text
|
||||||
|
-> m (Maybe SignalHandler)
|
||||||
|
withBTPropertyRule cl path update iface prop = do
|
||||||
|
res <- matchBTProperty cl path
|
||||||
|
case res of
|
||||||
|
Just rule -> Just <$> addMatchCallback rule (signalToUpdate . matchConnected) cl
|
||||||
|
Nothing -> do
|
||||||
|
logError $
|
||||||
|
"could not add listener for prop "
|
||||||
|
<> prop_
|
||||||
|
<> " on path "
|
||||||
|
<> path_
|
||||||
|
return Nothing
|
||||||
|
where
|
||||||
|
path_ = displayObjectPath path
|
||||||
|
prop_ = Utf8Builder $ encodeUtf8Builder prop
|
||||||
|
signalToUpdate = withSignalMatch update
|
||||||
|
matchConnected = matchPropertyChanged iface prop
|
||||||
|
|
||||||
addAdaptorListener
|
addAdaptorListener
|
||||||
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
||||||
=> MutableBtState
|
=> MutableBtState
|
||||||
|
@ -240,10 +266,9 @@ addAdaptorListener
|
||||||
-> SysClient
|
-> SysClient
|
||||||
-> m (Maybe SignalHandler)
|
-> m (Maybe SignalHandler)
|
||||||
addAdaptorListener state dpy adaptor sys = do
|
addAdaptorListener state dpy adaptor sys = do
|
||||||
rule <- matchBTProperty sys adaptor
|
withBTPropertyRule sys adaptor procMatch adapterInterface adaptorPowered
|
||||||
forM rule $ \r -> addMatchCallback r (procMatch . matchPowered) sys
|
|
||||||
where
|
where
|
||||||
procMatch = withSignalMatch $ \b -> putPowered state b >> dpy
|
procMatch b = putPowered state b >> dpy
|
||||||
|
|
||||||
callGetPowered
|
callGetPowered
|
||||||
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
||||||
|
@ -255,9 +280,6 @@ callGetPowered adapter =
|
||||||
memberName_ $
|
memberName_ $
|
||||||
T.unpack adaptorPowered
|
T.unpack adaptorPowered
|
||||||
|
|
||||||
matchPowered :: [Variant] -> SignalMatch Bool
|
|
||||||
matchPowered = matchPropertyChanged adapterInterface adaptorPowered
|
|
||||||
|
|
||||||
putPowered :: MonadUnliftIO m => MutableBtState -> Maybe Bool -> m ()
|
putPowered :: MonadUnliftIO m => MutableBtState -> Maybe Bool -> m ()
|
||||||
putPowered m ds = modifyMVar_ m (\s -> return s {btPowered = ds})
|
putPowered m ds = modifyMVar_ m (\s -> return s {btPowered = ds})
|
||||||
|
|
||||||
|
@ -309,13 +331,9 @@ addDeviceListener
|
||||||
-> SysClient
|
-> SysClient
|
||||||
-> m (Maybe SignalHandler)
|
-> m (Maybe SignalHandler)
|
||||||
addDeviceListener state dpy device sys = do
|
addDeviceListener state dpy device sys = do
|
||||||
rule <- matchBTProperty sys device
|
withBTPropertyRule sys device procMatch devInterface devConnected
|
||||||
forM rule $ \r -> addMatchCallback r (procMatch . matchConnected) sys
|
|
||||||
where
|
where
|
||||||
procMatch = withSignalMatch $ \c -> updateDevice state device c >> dpy
|
procMatch c = updateDevice state device c >> dpy
|
||||||
|
|
||||||
matchConnected :: [Variant] -> SignalMatch Bool
|
|
||||||
matchConnected = matchPropertyChanged devInterface devConnected
|
|
||||||
|
|
||||||
callGetConnected
|
callGetConnected
|
||||||
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
||||||
|
|
Loading…
Reference in New Issue