-- | List devices with the given class
--
-- TODO: support dynamic asynchronous device adding/removal
listDevicesWithClass :: DeviceManager -> String -> Sys [(DevicePath,DeviceTree)]
listDevicesWithClass dm cls = atomically $ do
   subs <- readTVar (dmSubsystems dm)
   devs <- readTVar (dmDevices dm)
   ds <- listDevices' dm

   let paths = Map.lookup (Text.pack cls) subs
               ||> Set.elems . subsystemDevices
               |> fromMaybe []
       getNode x = case deviceTreeLookup x devs of
                     Just n  -> n
                     Nothing -> error ("Mismatch between device tree and device subsystem index! Report this as a Haskus bug. (" ++ show x ++ ") " ++ show ds)
       nodes = fmap getNode paths
   return (paths `zip` nodes)
listDevicesWithClass :: DeviceManager -> String -> Sys [(DevicePath,DeviceTree)]
listDevicesWithClass dm cls = atomically $ do
   subs <- readTVar (dmSubsystems dm)
   devs <- readTVar (dmDevices dm)
   ds <- listDevices' dm

   let paths = Map.lookup (Text.pack cls) subs
               ||> Set.elems . subsystemDevices
               |> fromMaybe []
       getNode x = case deviceTreeLookup x devs of
                     Just n  -> n
                     Nothing -> error ("Mismatch between device tree and device subsystem index! Report this as a Haskus bug. (" ++ show x ++ ") " ++ show ds)
       nodes = fmap getNode paths
   return (paths `zip` nodes)
listDevicesWithClass dm cls = atomically $ do
   subs <- readTVar (dmSubsystems dm)
   devs <- readTVar (dmDevices dm)
   ds <- listDevices' dm

   let paths = Map.lookup (Text.pack cls) subs
               ||> Set.elems . subsystemDevices
               |> fromMaybe []
       getNode x = case deviceTreeLookup x devs of
                     Just n  -> n
                     Nothing -> error ("Mismatch between device tree and device subsystem index! Report this as a Haskus bug. (" ++ show x ++ ") " ++ show ds)
       nodes = fmap getNode paths
   return (paths `zip` nodes)