devicelist.h File Reference

#include <hal/libhal.h>
Include dependency graph for devicelist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hal_device_property
struct  hal_device

Typedefs

typedef G_BEGIN_DECLS struct
hal_device_property 
hal_device_property
typedef struct hal_device hal_device

Functions

hal_devicehal_device_list_add_device (LibHalContext *ctx, const char *udi)
 Add udi to device list.
hal_device_propertyhal_device_list_get_property (const char *property, const hal_device *device)
 Return the property of the given device.
hal_devicehal_device_list_find_device (const char *udi)
 Return the device pointed to by udi.
hal_devicehal_device_list_get_root ()
 Get device llst root.
gboolean hal_device_list_remove_device (const char *udi)
 Remove udi from device list.
gboolean hal_device_list_remove_property (const char *udi, const char *key)
 Remove property of udi from device list.
gboolean hal_device_list_set_property (const char *udi, const char *key)
 Set property of udi from device list.
void hal_print_all_devices ()
 Print all available devices (for debugging).
int hal_count_devices ()
 Return the number of devices available.

Typedef Documentation

typedef struct hal_device hal_device
typedef G_BEGIN_DECLS struct hal_device_property hal_device_property

File Name : devicelist.h

Description: Functions to maintain a list of available HAL devices Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Parts used from halevt, Copyright (C) 2007 Patrice Dumas <pertusus at="" free="" dot="" fr>="">


Function Documentation

int hal_count_devices (  ) 

Return the number of devices available.

---------------------------------------------------------------------------

Name : hal_count_devices

Returns:
Number of devices

--------------------------------------------------------------------------

Definition at line 397 of file devicelist.c.

References hal_device::next.

00398 {
00399     int nr = 0;
00400     hal_device *device = hal_device_root;
00401     while (device != NULL)
00402     {
00403         nr++;
00404         device = device->next;
00405     }
00406     return nr;
00407 }

hal_device* hal_device_list_add_device ( LibHalContext *  ctx,
const char *  udi 
)

Add udi to device list.

---------------------------------------------------------------------------

Name : hal_device_list_add_device

Parameters:
ctx HAL context
udi Unique Device Id
Returns:

--------------------------------------------------------------------------

Definition at line 135 of file devicelist.c.

References hal_check_dbus_error(), hal_free_device(), hal_free_property_value(), hal_get_iterator_value(), hal_new_device_property(), LOGPRINTF, hal_device::next, hal_device_property::next, hal_device::properties, and hal_device::udi.

Referenced by hal_add_devices(), and hal_device_added().

00136 {
00137     LOGPRINTF("entry: udi %s", udi);
00138 
00139     DBusError dbus_error;
00140     LibHalPropertySet *pset = NULL;
00141     LibHalPropertySetIterator it;
00142     hal_device *device = NULL;
00143     char *key = NULL;
00144     char **value;
00145     hal_device_property *new_property = NULL;
00146 
00147     dbus_error_init(&dbus_error);
00148     
00149     device = g_try_malloc0(sizeof(hal_device));
00150     if (device == NULL) 
00151     { 
00152         goto oom;
00153     }
00154     device->properties = NULL;
00155 
00156     pset = libhal_device_get_all_properties(ctx, udi, &dbus_error);
00157     hal_check_dbus_error(&dbus_error);
00158     if (pset == NULL)
00159     {
00160         goto oom;
00161     }
00162 
00163     for (libhal_psi_init(&it, pset); libhal_psi_has_more(&it); libhal_psi_next(&it))
00164     {
00165         LibHalPropertyType type = libhal_psi_get_type(&it);
00166         key = g_strdup(libhal_psi_get_key(&it));
00167         if (key == NULL) 
00168         { 
00169             goto oom; 
00170         }
00171         
00172         value = hal_get_iterator_value(type, &it);
00173         if (value == NULL) 
00174         { 
00175             g_free(key);
00176             goto oom; 
00177         }
00178 
00179         new_property = hal_new_device_property(key, value);
00180         if (new_property == NULL) 
00181         { 
00182             hal_free_property_value(value);
00183             g_free(key);
00184             goto oom; 
00185         }
00186         new_property->next = device->properties;
00187         device->properties = new_property;
00188     }
00189     
00190     device->next = hal_device_root;
00191     device->udi = g_strdup(udi);
00192     if (device->udi == NULL) 
00193     { 
00194         goto oom;
00195     }
00196     hal_device_root = device;
00197     
00198     libhal_free_property_set(pset); 
00199     
00200     return device;
00201 
00202 oom:
00203     LOGPRINTF("No property found for %s (or oom)", udi);
00204 
00205     if (device) 
00206         hal_free_device(device);
00207     if (pset) 
00208         libhal_free_property_set(pset); 
00209     return NULL;
00210 }

Here is the call graph for this function:

Here is the caller graph for this function:

hal_device* hal_device_list_find_device ( const char *  udi  ) 

Return the device pointed to by udi.

---------------------------------------------------------------------------

Name : hal_device_list_find_device

Parameters:
udi Unique Device Id
Returns:

--------------------------------------------------------------------------

Definition at line 253 of file devicelist.c.

References LOGPRINTF, hal_device::next, and hal_device::udi.

Referenced by device_is_internal_mmc_host(), hal_device_list_remove_property(), hal_device_list_set_property(), hal_device_property_modified(), hal_device_removed(), and volume_is_mounted().

00254 {
00255     LOGPRINTF("entry: udi %s", udi);
00256     
00257     g_return_val_if_fail(udi!=NULL, NULL);
00258 
00259     hal_device *device = hal_device_root;
00260     while (device != NULL)
00261     {
00262         if (device->udi && (strcmp(device->udi, udi)==0)) 
00263         { 
00264             return device; 
00265         }
00266         device = device->next;
00267     }
00268     return NULL;
00269 }

Here is the caller graph for this function:

hal_device_property* hal_device_list_get_property ( const char *  property,
const hal_device device 
)

Return the property of the given device.

---------------------------------------------------------------------------

Name : hal_device_list_get_property

Parameters:
property 
device 
Returns:

--------------------------------------------------------------------------

Definition at line 272 of file devicelist.c.

References LOGPRINTF, and hal_device::properties.

Referenced by device_is_internal_mmc_host(), hal_device_list_set_property(), hal_device_property_modified(), hal_get_mountpoint_device(), hal_property_value(), remount_next_volume(), report_unmounting_volumes(), and unmount_volume().

00273 {
00274 //    LOGPRINTF("entry: key %s", key);
00275     
00276     g_return_val_if_fail(key!=NULL, NULL);
00277     
00278     if (device == NULL)
00279     {
00280         return NULL;
00281     }
00282 
00283     hal_device_property *property = device->properties;
00284     while (property != NULL)
00285     {
00286         if (property->key && (strcmp(property->key, key)==0))
00287         {
00288             LOGPRINTF("entry found: key %s, property %p, %p, %s", key, property->values, *property->values, *property->values);
00289             return property;
00290         }
00291         property = property->next;
00292     }
00293     return NULL;
00294 }

Here is the caller graph for this function:

hal_device* hal_device_list_get_root (  ) 

Get device llst root.

---------------------------------------------------------------------------

Name : hal_device_list_get_root

Parameters:
-- 
Returns:
Returns root of device list

--------------------------------------------------------------------------

Definition at line 297 of file devicelist.c.

Referenced by hal_get_mountpoint_device(), remount_next_volume(), report_unmounting_volumes(), and unmount_volumes().

00298 {
00299     return hal_device_root;
00300 }

Here is the caller graph for this function:

gboolean hal_device_list_remove_device ( const char *  udi  ) 

Remove udi from device list.

---------------------------------------------------------------------------

Name : hal_device_list_remove_device

Parameters:
udi Unique Device Id
Returns:
Returns TRUE on success, FALSE on failure

--------------------------------------------------------------------------

Definition at line 213 of file devicelist.c.

References hal_free_device(), LOGPRINTF, hal_device::next, and hal_device::udi.

Referenced by hal_device_removed().

00214 {
00215     LOGPRINTF("entry: udi %s", udi);
00216 
00217     g_return_val_if_fail(udi!=NULL, FALSE);
00218 
00219     hal_device *previous = hal_device_root;
00220     hal_device *device = hal_device_root;
00221 
00222     // no device 
00223     if (device == NULL) 
00224     {
00225         return FALSE; 
00226     }
00227 
00228     LOGPRINTF("Removing %s", udi);
00229 
00230     // device is the first one 
00231     if (device->udi && (strcmp(device->udi, udi)==0))
00232     {
00233         hal_device_root = device->next;
00234         hal_free_device(device);
00235         return TRUE;
00236     }
00237 
00238     while (device != NULL)
00239     {
00240         if (device->udi && (strcmp(device->udi, udi)==0))
00241         {
00242             previous->next = device->next;
00243             hal_free_device(device);
00244             return TRUE;
00245         }
00246         previous = device;
00247         device = device->next;
00248     }
00249     return FALSE;
00250 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean hal_device_list_remove_property ( const char *  udi,
const char *  key 
)

Remove property of udi from device list.

---------------------------------------------------------------------------

Name : hal_device_list_remove_property

Parameters:
udi Unique Device Id
key 
Returns:
Returns TRUE on success, FALSE on failure

--------------------------------------------------------------------------

Definition at line 351 of file devicelist.c.

References hal_device_list_find_device(), hal_free_device_property(), LOGPRINTF, hal_device_property::next, and hal_device::properties.

Referenced by hal_device_property_modified().

00352 {
00353     LOGPRINTF("entry: udi %s", udi);
00354 
00355     hal_device *device = hal_device_list_find_device(udi);
00356     if (device == NULL || device->properties == NULL) 
00357     { 
00358         return FALSE; 
00359     }
00360 
00361     hal_device_property *property = device->properties;
00362     // first property 
00363     if (property->key && (strcmp(property->key, key)==0))
00364     {
00365         device->properties = property->next;
00366         hal_free_device_property(property);
00367     }
00368     
00369     hal_device_property *previous = property;
00370 
00371     while (property != NULL)
00372     {
00373         if (property->key && (strcmp(property->key, key)==0))
00374         {
00375             previous->next = property->next;
00376             hal_free_device_property(property);
00377             return TRUE;
00378         }
00379         previous = property;
00380         property = property->next;
00381     }
00382     return FALSE;
00383 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean hal_device_list_set_property ( const char *  udi,
const char *  key 
)

Set property of udi from device list.

---------------------------------------------------------------------------

Name : hal_device_list_set_property

Parameters:
udi Unique Device Id
key 
Returns:
Returns TRUE on success, FALSE on failure

--------------------------------------------------------------------------

Definition at line 303 of file devicelist.c.

References hal_device_list_find_device(), hal_device_list_get_property(), hal_free_property_value(), hal_new_device_property(), hal_property_value(), LOGPRINTF, hal_device::properties, and hal_device_property::values.

Referenced by hal_device_property_modified().

00304 {
00305     LOGPRINTF("entry: udi %s", udi);
00306 
00307     hal_device *device = hal_device_list_find_device(udi);
00308     hal_device_property *property;
00309 
00310     char **values;
00311 
00312     if (device == NULL) 
00313     {
00314         return FALSE; 
00315     }
00316 
00317     values = hal_property_value(key, udi, NULL);
00318     if (values == NULL) 
00319     {
00320         return FALSE; 
00321     }
00322 
00323     property = hal_device_list_get_property(key, device);
00324     if (property != NULL)
00325     {
00326         hal_free_property_value(property->values);
00327         property->values = values;
00328     }
00329     else
00330     {
00331         char *new_key = g_strdup(key);
00332         if (new_key == NULL)
00333         {
00334             hal_free_property_value(values);
00335             return FALSE; 
00336         }
00337         property = hal_new_device_property(new_key, values);
00338         if (property == NULL) 
00339         {
00340             hal_free_property_value(values);
00341             g_free(new_key);
00342             return FALSE; 
00343         }
00344         property->next = device->properties;
00345         device->properties = property;
00346     }
00347     return TRUE;
00348 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_print_all_devices (  ) 

Print all available devices (for debugging).

---------------------------------------------------------------------------

Name : hal_print_all_devices

Returns:
--

--------------------------------------------------------------------------

Definition at line 386 of file devicelist.c.

References hal_device_print(), hal_device::next, and hal_device::udi.

00387 {
00388     hal_device *device = hal_device_root;
00389     while (device != NULL)
00390     {
00391         hal_device_print(device->udi);
00392         device = device->next;
00393     }
00394 }

Here is the call graph for this function:

Generated by  doxygen 1.6.2-20100208