hal.h File Reference

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

Go to the source code of this file.

Defines

#define MOUNTPOINT_CARD   "/media/mmcblk0p1"
#define MOUNT_OPTIONS   "iocharset=iso8859-1,utf8,noatime"

Functions

gboolean hal_set_services (void)
 Setup HAL context and set callbacks for hal events.
void hal_add_devices (void)
 Scan HAL for available devices, run init and add to devicelist.
void hal_check_dbus_error (DBusError *error)
 Print and reset a dbus error.
void hal_device_print (const char *udi)
 Print a device to stdout, useful for debugging.
char ** hal_get_iterator_value (const LibHalPropertyType type, LibHalPropertySetIterator *iter)
 Return the value of iterator from Hal properties.
char ** hal_property_value (const char *key, const char *udi, const hal_device *device)
 Return the value of Hal property.
gchar * hal_get_mountpoint_device (void)
void hal_remount_all_volumes (gpointer callback_function, gpointer user_data)
void hal_unmount_all_volumes (gpointer callback_function, gpointer user_data)
void hal_report_mounted_volumes (const char *ipc_service)

Define Documentation

#define MOUNT_OPTIONS   "iocharset=iso8859-1,utf8,noatime"

Definition at line 51 of file hal.h.

Referenced by udi_mount_volume().

#define MOUNTPOINT_CARD   "/media/mmcblk0p1"

File Name : hal.h

Description: The HAL Hardware Abstraction functions 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 50 of file hal.h.

Referenced by cb_sys_get_card_mountpoint(), check_disk_free(), hal_device_property_modified(), hal_device_removed(), hal_get_mountpoint_device(), on_card_indexed(), on_phase_1_complete(), post_process_startup(), start_demo_mode(), sys_set_card(), udi_mount_volume(), and volume_is_mounted().


Function Documentation

void hal_add_devices ( void   ) 

Scan HAL for available devices, run init and add to devicelist.

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

Name : hal_add_devices

Parameters:
-- 
Returns:
--

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

Definition at line 191 of file hal.c.

References hal_check_dbus_error(), hal_device_list_add_device(), hal_property_matches_udi(), halContext, LOGPRINTF, udi_mount_volume(), and volume_is_mounted().

Referenced by start_phase_3().

00192 {
00193     LOGPRINTF("entry");
00194 
00195     g_return_if_fail(halContext != NULL);
00196     
00197     DBusError error;
00198     char **all_udi = NULL;
00199     char **current_udi = NULL;
00200     int num_device = 0;
00201     hal_device *device = NULL;
00202 
00203     dbus_error_init(&error);
00204     all_udi = libhal_get_all_devices(halContext, &num_device, &error);
00205     hal_check_dbus_error(&error);
00206 
00207     if (all_udi == NULL)
00208     {
00209        LOGPRINTF("No HAL devices. Out of memory or an error occured in HAL");
00210        return;
00211     }
00212 
00213     current_udi = all_udi;
00214 
00215     while ((*current_udi) != NULL)
00216     {
00217         // Here we match all the removable devices that aren't 
00218         // already mounted and mount and register them.
00219         char *storage_device = libhal_device_get_property_string(halContext, *current_udi, "block.storage_device", NULL);
00220         if (  
00221                libhal_device_property_exists(halContext, *current_udi, "block.device", NULL)
00222                &&
00223                hal_property_matches_udi("block.is_volume", "true", *current_udi) 
00224                &&
00225                hal_property_matches_udi("volume.is_mounted", "false", *current_udi) 
00226            )
00227         {
00228             udi_mount_volume(*current_udi);
00229         }
00230         else if (
00231                    libhal_device_property_exists(halContext, *current_udi, "block.device", NULL)
00232                    &&
00233                    hal_property_matches_udi("block.is_volume", "true", *current_udi) 
00234                    &&
00235                    hal_property_matches_udi("volume.is_mounted", "true", *current_udi) 
00236                 )
00237         {
00238             // register volumes already mounted at startup
00239             // this is mainly useful while testing
00240             volume_is_mounted(halContext, *current_udi);
00241         }
00242        
00243         device = hal_device_list_add_device(halContext, *current_udi);
00244         if (storage_device) libhal_free_string(storage_device);
00245         current_udi++;
00246     }
00247 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_check_dbus_error ( DBusError *  error  ) 

Print and reset a dbus error.

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

Name : hal_check_dbus_error

Parameters:
error Pointer to DBusError, memory is freed when set
Returns:
--

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

Definition at line 173 of file hal.c.

References ERRORPRINTF.

Referenced by hal_add_devices(), hal_device_list_add_device(), hal_property_matches_udi(), and hal_udi_property_value().

00174 {
00175     if (dbus_error_is_set(error)) 
00176     {
00177         ERRORPRINTF("DBus Error! %s: %s", error->name, error->message);
00178         dbus_error_free(error);
00179     }
00180 }

Here is the caller graph for this function:

void hal_device_print ( const char *  udi  ) 

Print a device to stdout, useful for debugging.

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

Name : hal_device_print

Parameters:
udi Unique Device Id
Returns:
--

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

Definition at line 183 of file hal.c.

References halContext.

Referenced by hal_print_all_devices().

00184 {
00185     g_return_if_fail(halContext != NULL);
00186     
00187     libhal_device_print(halContext, udi, NULL);
00188 }

Here is the caller graph for this function:

char** hal_get_iterator_value ( const LibHalPropertyType  type,
LibHalPropertySetIterator *  iter 
)

Return the value of iterator from Hal properties.

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

Name : hal_get_iterator_value

Parameters:
type LibHalPropertyType type of property
iter LibHalPropertySetIterator iterator
Returns:
value array

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

Definition at line 250 of file hal.c.

References LOGPRINTF.

Referenced by hal_device_list_add_device().

00251 {
00252     char **value = NULL;
00253     char tmp[256];
00254 
00255     if (type == LIBHAL_PROPERTY_TYPE_STRLIST)
00256     {
00257        return libhal_psi_get_strlist(iter);
00258     }
00259  
00260     value = g_try_malloc0(2*sizeof(char *));
00261     if (value == NULL) 
00262     { 
00263         return NULL; 
00264     }
00265     value[1] = NULL;
00266 
00267     if (type == DBUS_TYPE_STRING)
00268     {
00269         char *hal_value = libhal_psi_get_string(iter);
00270         if (hal_value != NULL)
00271         {
00272             value[0] = g_strdup(hal_value);
00273         }
00274     }
00275     else if (type == DBUS_TYPE_BOOLEAN)
00276     {
00277         dbus_bool_t value_b = libhal_psi_get_bool(iter);
00278         if (value_b == TRUE)
00279         {
00280             value[0] = g_strdup("true");
00281         }
00282         else
00283         {
00284             value[0] = g_strdup("false");
00285         }
00286     }
00287     else if (type == DBUS_TYPE_INT32)
00288     {
00289         dbus_int32_t int_value = libhal_psi_get_int(iter);
00290         snprintf(tmp, 255, "%d", int_value);
00291         tmp[255] = '\0';
00292         value[0] = g_strdup(tmp);
00293     }
00294     else if (type == DBUS_TYPE_UINT64)
00295     {
00296         dbus_uint64_t uint_value = libhal_psi_get_uint64(iter);
00297         snprintf(tmp, 255, "%llu", uint_value);
00298         tmp[255] = '\0';
00299         value[0] = g_strdup(tmp);
00300     }
00301     else if (type == DBUS_TYPE_DOUBLE)
00302     {
00303         double dble_value = libhal_psi_get_double(iter);
00304         snprintf(tmp, 255, "%g", dble_value);
00305         tmp[255] = '\0';
00306         value[0] = g_strdup(tmp);
00307     }
00308     else
00309     {
00310         LOGPRINTF("Unhandled HAL iterator type: %d", type);
00311     }
00312     return value;
00313 }

Here is the caller graph for this function:

gchar* hal_get_mountpoint_device ( void   ) 

Definition at line 428 of file hal.c.

References hal_device_list_get_property(), hal_device_list_get_root(), LOGPRINTF, MOUNTPOINT_CARD, hal_device::next, and hal_device_property::values.

Referenced by sys_set_card().

00429 {
00430     LOGPRINTF("entry");
00431 
00432     gchar *dev_name = NULL;
00433     hal_device *device = hal_device_list_get_root();
00434     hal_device_property *property;
00435 
00436     while (device != NULL)
00437     {
00438         property = hal_device_list_get_property("volume.mount_point", device);
00439         if ((property != NULL) && (*property->values != NULL) && ((*property->values)[0] != '\0'))
00440         {
00441             if ((*property->values !=NULL) && (strcmp(*property->values, MOUNTPOINT_CARD) == 0))
00442             {
00443                 property = hal_device_list_get_property("block.device", device);
00444                 if ((property != NULL) && (*property->values != NULL) && ((*property->values)[0] != '\0'))
00445                 {
00446                     dev_name = *property->values;
00447                     break;
00448                 }
00449             }
00450         }
00451         device = device->next;
00452     }
00453     return dev_name;
00454 }

Here is the call graph for this function:

Here is the caller graph for this function:

char** hal_property_value ( const char *  key,
const char *  udi,
const hal_device device 
)

Return the value of Hal property.

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

Name : hal_property_value

Parameters:
key 
udi Unique Device Id
device hal_device
Returns:
value array

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

Definition at line 316 of file hal.c.

References hal_device_list_get_property(), hal_udi_property_value(), and LOGPRINTF.

Referenced by hal_device_list_set_property().

00317 {
00318     char **values;
00319 
00320     if ((udi == NULL) || (key == NULL))
00321     {
00322         LOGPRINTF("Warning: hal_property_value was called with a NULL value");
00323         return NULL;
00324     }
00325     if (!strcmp(key,"udi"))
00326     {
00327         char *new_udi = g_strdup(udi);
00328         if (new_udi == NULL) 
00329         { 
00330             return NULL; 
00331         }
00332         values = g_try_malloc0(2*sizeof(char*));
00333         if (values == NULL)
00334         {
00335             g_free(new_udi);
00336             return NULL;
00337         }
00338         values[0] = new_udi;
00339         values[1] = NULL;
00340         return values;
00341     }
00342 
00343     if (device != NULL) 
00344     { 
00345         hal_device_property *property = hal_device_list_get_property(key, device);
00346         return property->values;
00347     }
00348     return hal_udi_property_value(key, udi);
00349 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_remount_all_volumes ( gpointer  callback_function,
gpointer  user_data 
)

Definition at line 352 of file hal.c.

References g_remount_all_volumes, g_remount_callback_data, g_remount_callback_func, LOGPRINTF, remount_next_volume(), and WARNPRINTF.

Referenced by cb_sys_card_mount(), and usb_set_state().

00353 {
00354     LOGPRINTF("entry");
00355 
00356     if (g_remount_callback_func != NULL)        
00357     {
00358         WARNPRINTF("sorry, remounting already in progress");
00359     }
00360     else
00361     {
00362         // setup callback function
00363         g_remount_all_volumes = TRUE;
00364         g_remount_callback_func = callback_function;
00365         g_remount_callback_data = user_data;
00366     
00367         // start remounting
00368         remount_next_volume();
00369     }
00370 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_report_mounted_volumes ( const char *  ipc_service  ) 
gboolean hal_set_services ( void   ) 

Setup HAL context and set callbacks for hal events.

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

Name : hal_set_services

Parameters:
-- 
Returns:
TRUE if successfully set up, FALSE otherwise

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

Definition at line 117 of file hal.c.

References eripc_client_context_t::context, eripc_get_system_connection(), eripcClient, ERRORPRINTF, hal_device_added(), hal_device_property_modified(), hal_device_removed(), halContext, LOGPRINTF, and WARNPRINTF.

Referenced by main().

00118 {
00119     gboolean retval = FALSE;
00120     DBusConnection *dbus_connection;
00121     DBusError error;
00122 
00123     LOGPRINTF("entry");
00124 
00125     dbus_error_init (&error);
00126 
00127     halContext = libhal_ctx_new();
00128     if (halContext == NULL)
00129     {
00130         ERRORPRINTF("Failed to create HAL context");
00131         return FALSE;
00132     }
00133   
00134     dbus_connection = eripc_get_system_connection(eripcClient->context);
00135     
00136     retval = libhal_ctx_set_dbus_connection(halContext, dbus_connection);
00137     if (!retval)
00138     {
00139         ERRORPRINTF("Failed to setup dbus connection");
00140         return FALSE;
00141     }
00142 
00143     retval = libhal_ctx_set_device_added(halContext, hal_device_added);
00144     if (!retval)
00145     {
00146         ERRORPRINTF("Failed to set callback");
00147         return FALSE;
00148     }
00149     
00150     libhal_ctx_set_device_removed(halContext, hal_device_removed);
00151     libhal_ctx_set_device_property_modified(halContext, hal_device_property_modified);
00152 
00153     if (!libhal_ctx_init(halContext, NULL))
00154     {
00155         ERRORPRINTF("Failed to initialize HAL connection to daemon");
00156         libhal_ctx_free(halContext);
00157         halContext = NULL;
00158         return FALSE;
00159     }
00160     
00161     libhal_device_property_watch_all(halContext, &error);
00162     if (dbus_error_is_set (&error)) 
00163     {
00164         WARNPRINTF("Failed to watch all HAL properties: %s", error.message);
00165         dbus_error_free (&error);
00166         return FALSE;
00167     }
00168     
00169     return TRUE;
00170 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_unmount_all_volumes ( gpointer  callback_function,
gpointer  user_data 
)

Definition at line 404 of file hal.c.

References g_unmount_all_volumes, g_unmount_callback_data, g_unmount_callback_func, LOGPRINTF, sync(), unmount_volumes(), and WARNPRINTF.

Referenced by do_unmount().

00405 {
00406     LOGPRINTF("entry");
00407 
00408     if (g_unmount_callback_func != NULL)        
00409     {
00410         WARNPRINTF("sorry, unmounting already in progress");
00411     }
00412     else
00413     {
00414         // setup callback function
00415         g_unmount_all_volumes = TRUE;
00416         g_unmount_callback_func = callback_function;
00417         g_unmount_callback_data = user_data;
00418     
00419         // flush buffers to disk
00420         sync();
00421         
00422         // start unmounting
00423         unmount_volumes();
00424     }
00425 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208