module System.UDev.Enumerate
( Enumerate
, newEnumerate
, Subsystem
, addMatchSubsystem
, addNoMatchSubsystem
, SysAttr
, SysValue
, addMatchSysattr
, addNoMatchSysattr
, addMatchProperty
, addMatchTag
, addMatchParent
, addMatchIsInitialized
, addMatchSysname
, addSyspath
, scanDevices
, scanSubsystems
, getListEntry
) where
import Data.ByteString as BS
import Foreign
import Foreign.C.Error
import Foreign.C.String
import Foreign.C.Types
import System.Posix.FilePath
import System.UDev.Context
import System.UDev.Device
import System.UDev.List
import System.UDev.Types
foreign import ccall unsafe "udev_enumerate_new"
c_new :: UDev -> IO Enumerate
newEnumerate :: UDev -> IO Enumerate
newEnumerate = c_new
foreign import ccall unsafe "udev_enumerate_add_match_subsystem"
c_addMatchSubsystem :: Enumerate -> CString -> IO CInt
type Subsystem = ByteString
addMatchSubsystem :: Enumerate
-> Subsystem
-> IO ()
addMatchSubsystem enumerate subsystem = do
throwErrnoIfMinus1_ "addMatchSubsystem" $ do
useAsCString subsystem $
c_addMatchSubsystem enumerate
foreign import ccall unsafe "udev_enumerate_add_nomatch_subsystem"
c_addNoMatchSubsystem :: Enumerate -> CString -> IO CInt
addNoMatchSubsystem :: Enumerate
-> Subsystem
-> IO ()
addNoMatchSubsystem enumerate subsystem = do
throwErrnoIfMinus1_ "addNoMatchSubsystem" $ do
useAsCString subsystem $
c_addNoMatchSubsystem enumerate
type SysAttr = ByteString
type SysValue = ByteString
foreign import ccall unsafe "udev_enumerate_add_match_sysattr"
c_addMatchSysattr :: Enumerate -> CString -> CString -> IO CInt
addMatchSysattr :: Enumerate
-> SysAttr
-> Maybe SysValue
-> IO ()
addMatchSysattr enumerate sysattr mvalue = do
throwErrnoIf_ (< 0) "addMatchSysattr" $ do
useAsCString sysattr $ \ c_sysattr -> do
case mvalue of
Nothing -> c_addMatchSysattr enumerate c_sysattr nullPtr
Just value -> do
useAsCString value $ \ c_value -> do
c_addMatchSysattr enumerate c_sysattr c_value
foreign import ccall unsafe "udev_enumerate_add_nomatch_sysattr"
c_addNoMatchSysattr :: Enumerate -> CString -> CString -> IO CInt
addNoMatchSysattr :: Enumerate
-> ByteString
-> Maybe ByteString
-> IO ()
addNoMatchSysattr enumerate sysattr mvalue = do
throwErrnoIf_ (< 0) "addNoMatchSysattr" $ do
useAsCString sysattr $ \ c_sysattr -> do
case mvalue of
Nothing -> c_addNoMatchSysattr enumerate c_sysattr nullPtr
Just value -> do
useAsCString value $ \ c_value -> do
c_addNoMatchSysattr enumerate c_sysattr c_value
foreign import ccall unsafe "udev_enumerate_add_match_property"
c_addMatchProperty :: Enumerate -> CString -> CString -> IO CInt
addMatchProperty :: Enumerate
-> ByteString
-> ByteString
-> IO ()
addMatchProperty enumerate prop value = do
throwErrnoIf_ (< 0) "addMatchProperty" $ do
useAsCString prop $ \ c_prop -> do
useAsCString value $ \ c_value -> do
c_addMatchProperty enumerate c_prop c_value
foreign import ccall unsafe "udev_enumerate_add_match_tag"
c_addMatchTag :: Enumerate -> CString -> IO CInt
addMatchTag :: Enumerate
-> ByteString
-> IO ()
addMatchTag enumerate tag = do
throwErrnoIf_ (< 0) "addMatchTag" $ do
useAsCString tag $ \ c_tag -> do
c_addMatchTag enumerate c_tag
foreign import ccall unsafe "udev_enumerate_add_match_parent"
c_addMatchParent :: Enumerate -> Device -> IO CInt
addMatchParent :: Enumerate
-> Device
-> IO ()
addMatchParent enumerate dev = do
throwErrnoIf_ (< 0) "addMatchParent" $ do
c_addMatchParent enumerate dev
foreign import ccall unsafe "udev_enumerate_add_match_is_initialized"
c_addMatchIsInitialized :: Enumerate -> IO CInt
addMatchIsInitialized :: Enumerate -> IO ()
addMatchIsInitialized enumerate = do
throwErrnoIfMinus1_ "addMatchIsInitialized" $ do
c_addMatchIsInitialized enumerate
foreign import ccall unsafe "udev_enumerate_add_match_sysname"
c_addMatchSysname :: Enumerate -> CString -> IO CInt
addMatchSysname :: Enumerate
-> ByteString
-> IO ()
addMatchSysname enumerate sysName = do
throwErrnoIfMinus1_ "addMatchSysname" $ do
useAsCString sysName $
c_addMatchSysname enumerate
foreign import ccall unsafe "udev_enumerate_add_syspath"
c_addSyspath :: Enumerate -> CString -> IO CInt
addSyspath :: Enumerate
-> RawFilePath
-> IO ()
addSyspath enumerate syspath = do
throwErrnoIf_ (< 0) "addSyspath" $ do
useAsCString syspath $ \ c_syspath -> do
c_addSyspath enumerate c_syspath
foreign import ccall unsafe "udev_enumerate_scan_devices"
c_scanDevices :: Enumerate -> IO CInt
scanDevices :: Enumerate -> IO ()
scanDevices = throwErrnoIfMinus1_ "scanDevices" . c_scanDevices
foreign import ccall unsafe "udev_enumerate_scan_subsystems"
c_scanSubsystems :: Enumerate -> IO CInt
scanSubsystems :: Enumerate -> IO ()
scanSubsystems = throwErrnoIfMinus1_ "scanSubsystems" . c_scanSubsystems
foreign import ccall unsafe "udev_enumerate_get_list_entry"
c_getListEntry :: Enumerate -> IO List
getListEntry :: Enumerate -> IO List
getListEntry = c_getListEntry