devicelist.c File Reference

#include <glib.h>
#include <hal/libhal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "devicelist.h"
#include "hal.h"
#include "log.h"
Include dependency graph for devicelist.c:

Go to the source code of this file.

Functions

void hal_free_property_value (char **values)
void hal_free_device_property (hal_device_property *property)
void hal_free_device (hal_device *device)
hal_device_propertyhal_new_device_property (char *key, char **values)
hal_devicehal_device_list_add_device (LibHalContext *ctx, const char *udi)
 Add udi to device list.
gboolean hal_device_list_remove_device (const char *udi)
 Remove udi from device list.
hal_devicehal_device_list_find_device (const char *udi)
 Return the device pointed to by udi.
hal_device_propertyhal_device_list_get_property (const char *key, const hal_device *device)
 Return the property of the given device.
hal_devicehal_device_list_get_root ()
 Get device llst root.
gboolean hal_device_list_set_property (const char *udi, const char *key)
 Set property of udi from device list.
gboolean hal_device_list_remove_property (const char *udi, const char *key)
 Remove 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.

Variables

static hal_devicehal_device_root

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_free_device ( hal_device device  ) 

Definition at line 99 of file devicelist.c.

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

Referenced by hal_device_list_add_device(), and hal_device_list_remove_device().

00100 {
00101     LOGPRINTF("entry");
00102 
00103     hal_device_property *property = device->properties;
00104     hal_device_property *previous_property;
00105 
00106     g_free(device->udi);
00107     
00108     while (property != NULL)
00109     {
00110         previous_property = property;
00111         property = property->next;
00112         g_free(previous_property);
00113     }
00114     
00115     g_free(device);
00116     device = NULL;
00117 }

Here is the caller graph for this function:

void hal_free_device_property ( hal_device_property property  ) 

Definition at line 89 of file devicelist.c.

References hal_free_property_value(), hal_device_property::key, LOGPRINTF, and hal_device_property::values.

Referenced by hal_device_list_remove_property().

00090 {
00091     LOGPRINTF("entry");
00092 
00093     g_free(property->key);
00094     property->key = NULL;
00095     hal_free_property_value(property->values);
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_free_property_value ( char **  values  ) 

Definition at line 73 of file devicelist.c.

References LOGPRINTF.

Referenced by hal_device_list_add_device(), hal_device_list_set_property(), and hal_free_device_property().

00074 {
00075     LOGPRINTF("entry");
00076 
00077     char **cur_value = values;
00078     
00079     while ((*cur_value) != NULL)
00080     {
00081         g_free(*cur_value);
00082         cur_value++;
00083     }
00084     g_free(values);
00085     values = NULL;
00086 }

Here is the caller graph for this function:

hal_device_property* hal_new_device_property ( char *  key,
char **  values 
)

Definition at line 120 of file devicelist.c.

References hal_device_property::key, and hal_device_property::values.

Referenced by hal_device_list_add_device(), and hal_device_list_set_property().

00121 {
00122 //    LOGPRINTF("entry: key %s", key);
00123 
00124     hal_device_property *new_property = g_try_malloc0(sizeof(hal_device_property));
00125     if (new_property == NULL) 
00126     { 
00127         return NULL; 
00128     }
00129     new_property->values = values;
00130     new_property->key = key;
00131     return new_property;
00132 }

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:


Variable Documentation

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

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

Definition at line 61 of file devicelist.c.

Generated by  doxygen 1.6.2-20100208