LdmManager

LdmManager — Device Manager

Functions

Properties

LdmManagerFlags flags Read / Write / Construct Only

Signals

void device-added Action
void device-removed Action

Types and Values

Object Hierarchy

    GFlags
    ╰── LdmManagerFlags
    GObject
    ╰── LdmManager

Description

The manager object is used to introspect the system and discover various devices. Using the LdmManager APIs one can enumerate specific device classes.

LdmManager internally makes use of libudev to provide low level enumeration and hotplug event capabilities, but will convert those raw devices and interfaces into the more readily consumable LdmDevice type.

Using the manager is very simple, and in a few lines you can grab all the devices from the system for introspection.

C example:

1
2
3
LdmManager *manager = ldm_manager_new(LDM_MANAGER_FLAGS_NONE);
g_autoptr(GPtrArray) devices = ldm_manager_get_devices(LDM_DEVICE_TYPE_ANY);
LdmDevice *device = devices->pdata[0];

Vala example:

1
2
var manager = new Ldm.Manager();
var devices = manager.get_devices();

Functions

ldm_manager_new ()

LdmManager *
ldm_manager_new (LdmManagerFlags flags);

Construct a new LdmManager Without any specified flags, the new LdmManager will default to monitoring for hotplug events.

Parameters

flags

Control behaviour of the new manager.

 

Returns

A newly created LdmManager.

[transfer full]


ldm_manager_get_devices ()

GPtrArray *
ldm_manager_get_devices (LdmManager *manager,
                         LdmDeviceType class_mask);

Return a subset of the devices known to this manager that happen to match the given classmask. As an example you might call this function with LDM_DEVICE_TYPE_GPU|LDM_DEVICE_TYPE_PCI to find all PCI GPUs on the system.

This function will return an array of references to our internal storage, so that they persist should hotplugging then disable the device. It is advisable to not rely on the device list staying valid for any duration of time, and instead use it for basic probing, not persistence.

Parameters

class_mask

Bitwise mask of LdmDeviceType

 

Returns

a list of all currently known devices.

[element-type Ldm.Device][transfer container]


ldm_manager_get_providers ()

GPtrArray *
ldm_manager_get_providers (LdmManager *manager,
                           LdmDevice *device);

Walk the plugins and find all known providers for the given device, if they can support it. The returned GPtrArray will free all elements when it itself is freed.

Returns

a list of all possible providers.

[element-type Ldm.Provider][transfer container]


ldm_manager_add_modalias_plugin_for_path ()

gboolean
ldm_manager_add_modalias_plugin_for_path
                               (LdmManager *manager,
                                const gchar *path);

Add a new LdmModaliasPlugin to the manager for the given path. This is a convenience wrapper around ldm_modalias_plugin_new_from_filename and ldm_manager_add_plugin.

Note that newer modalias plugins have a higher priority than older plugins, so you should add newest drivers last if you have multiple driver versions. This is already taken care of by using the glob-based function ldm_manager_add_modalias_plugins_for_directory

i.e. insert 380 driver AFTER 340.

Parameters

path

The fully qualified ".modaliases" file path

 

Returns

TRUE if a new plugin was added


ldm_manager_add_modalias_plugins_for_directory ()

gboolean
ldm_manager_add_modalias_plugins_for_directory
                               (LdmManager *manager,
                                const gchar *directory);

Attempt to bulk-add LdmModaliasPlugin objects from the given directory to ensure preservation of sort order and ease of use.

This function is used to add well known modalias paths to the plugin and construct plugins used for hardware detection.

Parameters

directory

Path containing *.modaliases files

 

Returns

TRUE if a new plugin was added


ldm_manager_add_system_modalias_plugins ()

gboolean
ldm_manager_add_system_modalias_plugins
                               (LdmManager *manager);

Attempt to add all modalias plugins directory from the modalias directory set when the library was compiled.

This is a convenience wrapper around ldm_manager_add_modalias_plugins_for_directory.

Returns

TRUE if any modalias plugins were added.


ldm_manager_add_plugin ()

void
ldm_manager_add_plugin (LdmManager *manager,
                        LdmPlugin *plugin);

Add a new plugin to the current set of plugins. The plugins are used to provide automatic hardware detection capabilities to the LdmManager and provide the internal API required for ldm_manager_get_providers to work.

Parameters

plugin

New plugin to add.

[transfer full]

Types and Values

enum LdmManagerFlags

Override the behaviour of the new LdmManager to allow disabling of hotplug events, etc.

Members

LDM_MANAGER_FLAGS_NONE

No special behaviour required

 

LDM_MANAGER_FLAGS_NO_MONITOR

Disable hotplug events

 

LDM_MANAGER_FLAGS_GPU_QUICK

Only allow GPU devices for fast initialisation

 

Property Details

The “flags” property

  “flags”                    LdmManagerFlags

The flags set at time of construction dictating the behaviour of this manager

Flags: Read / Write / Construct Only

Signal Details

The “device-added” signal

void
user_function (LdmManager *manager,
               LdmDevice  *device,
               gpointer    user_data)

Connect to this signal to be notified about devices as they become available to the LdmManager.

Parameters

manager

The manager owning the device

 

device

The newly available device

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “device-removed” signal

void
user_function (LdmManager *manager,
               LdmDevice  *device,
               gpointer    user_data)

Connect to this signal to be notified when a device is about to be removed from the LdmManager. The device being passed will be unreffed after this signal is emitted, so do not attempt to hold any references to it.

Parameters

manager

The manager owning the device

 

device

The device being removed

 

user_data

user data set when the signal handler was connected.

 

Flags: Action