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.

dbus_bool_t class_device_get_major_minor (const char *sysfs_path, int *major, int *minor)
 Utility function to retrieve major and minor number for a class device.

dbus_bool_t class_device_get_device_file (const char *sysfs_path, char *dev_file, int dev_file_length)
 Get the name of the special device file given the sysfs path for a class 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 93 of file common.h.

Referenced by bus_device_visit(), class_device_got_parent_device(), class_device_got_sysdevice(), class_device_visit(), and handle_device_event().


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 64 of file common.h.

Referenced by rename_and_merge().


Function Documentation

dbus_bool_t class_device_get_device_file const char *  sysfs_path,
char *  dev_file,
int  dev_file_length
 

Get the name of the special device file given the sysfs path for a class device.

Parameters:
sysfs_path Path to class device in sysfs
dev_file Where the special device file name should be stored
dev_file_length Size of dev_file character array

Definition at line 614 of file common.c.

References sysfs_mount_path.

Referenced by class_device_visit().

dbus_bool_t class_device_get_major_minor const char *  sysfs_path,
int *  major,
int *  minor
 

Utility function to retrieve major and minor number for a class device.

The class device must have a dev file in the #sysfs_path directory and it must be of the form d:d.

Parameters:
sysfs_path Path to directory in sysfs filesystem of class device
major Major device number will be stored here
minor Minor device number will be stored here
Returns:
TRUE on success, otherwise FALSE

Definition at line 585 of file common.c.

Referenced by block_class_pre_process().

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 692 of file 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 730 of file common.c.

References DIE, drivers_add_entry(), and sysfs_mount_path.

Referenced by pci_device_init(), and usb_device_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 713 of file common.c.

References drivers_table_head.

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 537 of file common.c.

Referenced by block_class_pre_process().

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 174 of file 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 147 of file 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 114 of file common.c.

Referenced by 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 240 of file common.c.

Referenced by find_bcd2().

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 326 of file common.c.

Referenced by block_class_pre_process(), and input_class_get_device_file_target().

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 509 of file common.c.

References DIE.

Referenced by bus_device_visit(), and class_device_visit().

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 78 of file common.c.

Referenced by block_class_pre_process(), and net_class_pre_process().

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 65 of file 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 94 of file common.c.

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 285 of file common.c.

Referenced by block_class_pre_process().

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 392 of file common.c.

References ComputeFDI, di_search_and_merge(), and hal_device_print().

Referenced by bus_device_got_parent().


Generated on Sat Apr 24 19:57:49 2004 for HAL by doxygen 1.3.6-20040222