Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

Utility functions
[Linux 2.6 support]

Utility functions. More...

Data Structures

struct  driver_entry_s

Defines

#define HAL_LINUX_HOTPLUG_TIMEOUT   30000
 Timeout in milliseconds for waiting for a sysfs device to appear as a HAL device.


Typedefs

typedef char *(* ComputeFDI )(HalDevice *d, int append_num)
 Type for function to compute the UDI (unique device id) for a given HAL device.


Functions

double parse_double (const char *str)
 Parse a double represented as a decimal number (base 10) in a string.

dbus_int32_t parse_dec (const char *str)
 Parse an integer represented as a decimal number (base 10) in a string.

dbus_int32_t parse_hex (const char *str)
 Parse an integer represented as a hexa-decimal number (base 16) in a string.

long int find_num (char *pre, char *s, int base)
 Find an integer appearing right after a substring in a string.

double find_double (char *pre, char *s)
 Find a floating point number appearing right after a substring in a string and return it as a double precision IEEE754 floating point number.

int find_bcd2 (char *pre, char *s)
 Find a floating point number appearing right after a substring in a string and return it as a BCD encoded number with 2 digits of precision.

char * find_string (char *pre, char *s)
 Find a string appearing right after a substring in a string and return it.

char * read_single_line (char *filename_format,...)
 Read the first line of a file and return it.

const char * get_last_element (const char *s)
 Given a path, /foo/bar/bat/foobar, return the last element, e.g.

const char * udevinfo_path (void)
char * rename_and_merge (HalDevice *d, ComputeFDI naming_func, const char *namespace)
 This function takes a temporary device and renames it to a proper UDI using the supplied bus-specific #naming_func.

char * get_parent_sysfs_path (const char *path)
 Given a sysfs-path for a device, this functions finds the sysfs path representing the parent of the given device by truncation.

void find_and_set_physical_device (HalDevice *device)
 Set the physical device for a device.

void drivers_add_entry (const char *driver_name, const char *device_path)
 Add an entry to the bandaid driver database.

const char * drivers_lookup (const char *device_path)
 Given a device path under /sys/devices, lookup the driver.

void drivers_collect (const char *bus_name)
 Collect all drivers being used on a bus.


Variables

driver_entry_s * drivers_table_head = NULL
 Head of linked list of #driver_entry_s structs.

dbus_bool_t is_probing
 This is set to #TRUE if we are probing and #FALSE otherwise.

char sysfs_mount_path [SYSFS_PATH_MAX]
 Mount path for sysfs.


Detailed Description

Utility functions.


Define Documentation

#define HAL_LINUX_HOTPLUG_TIMEOUT   30000
 

Timeout in milliseconds for waiting for a sysfs device to appear as a HAL device.

Usually used when hotplugging usb-storage since many HAL devices (usb, usbif, scsi_host, scsi_device, block*2) appear and the linux kernel gives us these add events out of order.

My old PIII 650Mhz, 128MB laptop with GNOME 2.4 is slow when attaching a whole subtree of USB devices, so a value of 30 seconds is actually reasonable. It's important to note that it's not HAL that is taking the lions share of the resources; rather it's the shell-scripts in linux-hotplug...

Definition at line 91 of file linux_common.h.

Referenced by handle_udev_node_created(), process_input_proc_info(), visit_class_device_block(), visit_class_device_i2c_adapter(), visit_class_device_net(), visit_class_device_scsi_device(), visit_class_device_scsi_host(), visit_class_device_v4l(), visit_device_i2c(), visit_device_ide(), visit_device_ide_host(), visit_device_ieee1394(), visit_device_pci(), visit_device_usb(), and visit_device_usb_interface().


Typedef Documentation

typedef char*(* ComputeFDI)(HalDevice * d, int append_num)
 

Type for function to compute the UDI (unique device id) for a given HAL device.

Parameters:
d HalDevice object
append_num Number to append to name if not -1
Returns:
New unique device id; only good until the next invocation of this function

Definition at line 65 of file linux_common.h.

Referenced by rename_and_merge().


Function Documentation

void drivers_add_entry const char *  driver_name,
const char *  device_path
[static]
 

Add an entry to the bandaid driver database.

Parameters:
driver_name Name of the driver
device_path Path to device, must start with /sys/devices

Definition at line 589 of file linux_common.c.

References DIE, and drivers_table_head.

Referenced by drivers_collect().

void drivers_collect const char *  bus_name  ) 
 

Collect all drivers being used on a bus.

This is only bandaid until sysutils fill in the driver_name in sysfs_device.

Parameters:
bus_name Name of bus, e.g. pci, usb

Definition at line 627 of file linux_common.c.

References DIE, drivers_add_entry(), and sysfs_mount_path.

Referenced by linux_i2c_init(), linux_ieee1394_init(), linux_pci_init(), and linux_usb_init().

const char * drivers_lookup const char *  device_path  ) 
 

Given a device path under /sys/devices, lookup the driver.

You need to have called drivers_collect() on the bus-type before hand.

Parameters:
device_path sysfs path to device
Returns:
Driver name or #NULL if no driver is bound to that sysfs device

Definition at line 610 of file linux_common.c.

References drivers_table_head.

Referenced by visit_device_i2c(), visit_device_ieee1394(), visit_device_pci(), visit_device_usb(), and visit_device_usb_interface().

void find_and_set_physical_device HalDevice device  ) 
 

Set the physical device for a device.

This function visits all parent devices and sets the property info.physical_device to the first parent device that doesn't have the info.physical_device property set.

Parameters:
device HalDevice to process

Definition at line 535 of file linux_common.c.

References ds_device_find(), ds_property_exists(), ds_property_get_string(), ds_property_set_string(), HalDevice, and HalDevice_s::udi.

Referenced by visit_class_device_block_got_parent(), visit_class_device_i2c_adapter_got_parent(), visit_class_device_scsi_device_got_parent(), visit_class_device_scsi_host_got_parent(), visit_device_ide_got_parent(), and visit_device_ide_host_got_parent().

int find_bcd2 char *  pre,
char *  s
 

Find a floating point number appearing right after a substring in a string and return it as a BCD encoded number with 2 digits of precision.

The result is undefined if the number isn't properly formatted or the substring didn't exist in the given string.

Parameters:
pre Substring preceding the value to parse
s String to analyze
Returns:
Number

Definition at line 175 of file linux_common.c.

References find_string().

Referenced by usb_proc_handle_device_info(), and usb_proc_handle_topology().

double find_double char *  pre,
char *  s
 

Find a floating point number appearing right after a substring in a string and return it as a double precision IEEE754 floating point number.

The result is undefined if the number isn't properly formatted or the substring didn't exist in the given string.

Parameters:
pre Substring preceding the value to parse
s String to analyze
Returns:
Number

Todo:
Handle errors gracefully

Definition at line 148 of file linux_common.c.

References DIE.

long int find_num char *  pre,
char *  s,
int  base
 

Find an integer appearing right after a substring in a string.

The result is LONG_MAX if the number isn't properly formatted or the substring didn't exist in the given string.

Parameters:
pre Substring preceding the value to parse
s String to analyze
base Base, e.g. decimal or hexadecimal, that number appears in
Returns:
Number

Todo:
Handle errors gracefully

Definition at line 115 of file linux_common.c.

Referenced by input_proc_handle_bits(), input_proc_handle_interface(), and usb_proc_handle_topology().

char * find_string char *  pre,
char *  s
 

Find a string appearing right after a substring in a string and return it.

The string return is statically allocated and is only valid until the next invocation of this function.

The result is undefined if the substring didn't exist in the given string.

Parameters:
pre Substring preceding the value to parse
s String to analyze
Returns:
Number

Definition at line 241 of file linux_common.c.

Referenced by find_bcd2(), input_proc_handle_handlers(), input_proc_handle_name(), and input_proc_handle_phys().

const char * get_last_element const char *  s  ) 
 

Given a path, /foo/bar/bat/foobar, return the last element, e.g.

foobar.

Parameters:
path Path
Returns:
Pointer into given string

Definition at line 327 of file linux_common.c.

Referenced by visit_class_device_block_got_parent(), visit_class_device_i2c_adapter(), visit_class_device_scsi_device(), visit_class_device_scsi_host(), and visit_class_device_v4l().

char * get_parent_sysfs_path const char *  path  ) 
 

Given a sysfs-path for a device, this functions finds the sysfs path representing the parent of the given device by truncation.

Parameters:
path Sysfs-path of device to find parent for
Returns:
Path for parent; must be freed by caller

Definition at line 507 of file linux_common.c.

References DIE.

Referenced by visit_class_device_block(), visit_class_device_i2c_adapter(), visit_class_device_scsi_device(), visit_class_device_scsi_host(), visit_device_i2c(), visit_device_ide(), visit_device_ide_host(), visit_device_ieee1394(), visit_device_pci(), visit_device_usb(), and visit_device_usb_interface().

dbus_int32_t parse_dec const char *  str  ) 
 

Parse an integer represented as a decimal number (base 10) in a string.

Parameters:
str String to parse
Returns:
Integer; If there was an error parsing the result is undefined.

Todo:
Check error condition

Definition at line 79 of file linux_common.c.

Referenced by handle_hotplug(), visit_class_device_block(), visit_class_device_block_got_parent(), visit_class_device_net(), visit_device_usb(), and visit_device_usb_interface().

double parse_double const char *  str  ) 
 

Parse a double represented as a decimal number (base 10) in a string.

Parameters:
str String to parse
Returns:
Double; If there was an error parsing the result is undefined.

Todo:
Check error condition

Definition at line 66 of file linux_common.c.

dbus_int32_t parse_hex const char *  str  ) 
 

Parse an integer represented as a hexa-decimal number (base 16) in a string.

Parameters:
str String to parse
Returns:
Integer; If there was an error parsing the result is undefined.

Todo:
Check error condition

Definition at line 95 of file linux_common.c.

Referenced by handle_hotplug(), visit_device_pci(), and visit_device_usb().

char * read_single_line char *  filename_format,
  ...
 

Read the first line of a file and return it.

Parameters:
filename_format Name of file, printf-style formatted
Returns:
Pointer to string or #NULL if the file could not be opened. The result is only valid until the next invocation of this function.

Definition at line 286 of file linux_common.c.

Referenced by visit_class_device_block_got_parent().

char * rename_and_merge HalDevice d,
ComputeFDI  naming_func,
const char *  namespace
 

This function takes a temporary device and renames it to a proper UDI using the supplied bus-specific #naming_func.

After renaming the HAL daemon will locate a .fdi file and possibly merge information into the object.

This function handles the fact that identical devices (for instance two completely identical USB mice) gets their own unique device id by appending a trailing number after it.

You cannot rely on the HalDevice object you gave this function, since information may have been merged into an existing HalDevice object. Use ds_device_find() to get the corresponding HalDevice object.

The device _is not_ added to the GDL. You need to call ds_gdl_add() explicitly to do this.

Parameters:
d HalDevice object
naming_func Function to compute bus-specific UDI
namespace Namespace of properties that must match, e.g. "usb", "pci", in order to have matched a device
Returns:
New UDI for the device or #NULL if the device already existed. In the event that the device already existed the given HalDevice object is destroyed.

Not a match, must be case a). Choose next computed_udi and try again!

Definition at line 393 of file linux_common.c.

References ComputeFDI, di_search_and_merge(), ds_device_destroy(), ds_device_find(), ds_device_matches(), ds_device_merge(), ds_device_set_udi(), ds_print(), ds_property_exists(), ds_property_get_bool(), ds_property_set_bool(), ds_property_set_string(), and HalDevice.

Referenced by visit_class_device_block_got_parent(), visit_class_device_i2c_adapter_got_parent(), visit_class_device_scsi_device_got_parent(), visit_class_device_scsi_host_got_parent(), visit_device_i2c_got_parent(), visit_device_ide_got_parent(), visit_device_ide_host_got_parent(), visit_device_ieee1394_got_parent(), visit_device_pci_got_parent(), visit_device_usb_got_parent(), and visit_device_usbif_got_parent().


Generated on Thu Mar 11 21:32:26 2004 for HAL by doxygen 1.3.6-20040222