00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <ctype.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <getopt.h>
00035 #include <assert.h>
00036 #include <unistd.h>
00037 #include <stdarg.h>
00038 #include <limits.h>
00039 #include <glib.h>
00040
00041 #include "../logger.h"
00042 #include "../device_store.h"
00043 #include "../hald.h"
00044 #include "common.h"
00045 #include "bus_device.h"
00046
00054 typedef struct {
00055 HalDevice *device;
00056 BusDeviceHandler *handler;
00057 } AsyncInfo;
00058
00059
00060 static void bus_device_got_parent (HalDeviceStore *store, HalDevice *parent,
00061 gpointer user_data);
00062
00071 dbus_bool_t
00072 bus_device_accept (BusDeviceHandler *self, const char *path,
00073 struct sysfs_device *device, dbus_bool_t is_probing)
00074 {
00075
00076 return strcmp (device->bus, self->sysfs_bus_name) == 0;
00077 }
00078
00089 void
00090 bus_device_visit (BusDeviceHandler *self, const char *path,
00091 struct sysfs_device *device, dbus_bool_t is_probing)
00092 {
00093 AsyncInfo *ai;
00094 HalDevice *d;
00095 char *parent_sysfs_path;
00096 char buf[256];
00097
00098
00099 d = hal_device_new ();
00100 hal_device_store_add (hald_get_tdl (), d);
00101 hal_device_property_set_string (d, "info.bus", self->hal_bus_name);
00102 hal_device_property_set_string (d, "linux.sysfs_path", path);
00103 hal_device_property_set_string (d, "linux.sysfs_path_device", path);
00104
00109 snprintf (buf, sizeof(buf), "%s.linux.sysfs_path", self->hal_bus_name);
00110 hal_device_property_set_string (d, buf, path);
00111
00112 parent_sysfs_path = get_parent_sysfs_path (path);
00113
00114
00115
00116
00117
00118
00119 ai = g_new0 (AsyncInfo, 1);
00120 ai->device = d;
00121 ai->handler = self;
00122
00123 hal_device_store_match_key_value_string_async (
00124 hald_get_gdl (),
00125 "linux.sysfs_path_device",
00126 parent_sysfs_path,
00127 bus_device_got_parent, ai,
00128 is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT);
00129
00130 free (parent_sysfs_path);
00131 }
00132
00140 static void
00141 bus_device_got_parent (HalDeviceStore *store, HalDevice *parent,
00142 gpointer user_data)
00143 {
00144 const char *sysfs_path = NULL;
00145 char *new_udi = NULL;
00146 HalDevice *new_d = NULL;
00147 AsyncInfo *ai = (AsyncInfo*) user_data;
00148 HalDevice *d = (HalDevice *) ai->device;
00149 BusDeviceHandler *self = (BusDeviceHandler *) ai->handler;
00150 struct sysfs_device *device;
00151
00152 g_free (ai);
00153
00154
00155 if (parent != NULL) {
00156 hal_device_property_set_string (d, "info.parent", parent->udi);
00157 }
00158
00159
00160
00161 sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path");
00162 assert (sysfs_path != NULL);
00163 device = sysfs_open_device (sysfs_path);
00164 if (device == NULL)
00165 DIE (("Coulnd't get sysfs device object for path %s",
00166 sysfs_path));
00167 self->pre_process (self, d, sysfs_path, device);
00168 sysfs_close_device (device);
00169
00170
00171
00172
00173 new_udi = rename_and_merge (d, self->compute_udi, self->hal_bus_name);
00174 if (new_udi != NULL) {
00175 new_d = hal_device_store_find (hald_get_gdl (), new_udi);
00176
00177 self->got_udi (self, new_d != NULL ? new_d : d, new_udi);
00178
00179 hal_device_store_add (hald_get_gdl (),
00180 new_d != NULL ? new_d : d);
00181 }
00182 hal_device_store_remove (hald_get_tdl (), d);
00183 g_object_unref (d);
00184 }
00185
00191 void
00192 bus_device_detection_done (BusDeviceHandler *self)
00193 {
00194 }
00195
00200 void
00201 bus_device_init (BusDeviceHandler *self)
00202 {
00203 }
00204
00209 void
00210 bus_device_shutdown (BusDeviceHandler *self)
00211 {
00212 }
00213
00214
00220 void
00221 bus_device_tick (BusDeviceHandler *self)
00222 {
00223 }
00224
00233 void
00234 bus_device_removed (BusDeviceHandler *self, const char *sysfs_path,
00235 HalDevice *d)
00236 {
00237 }
00238
00251 void
00252 bus_device_pre_process (BusDeviceHandler *self,
00253 HalDevice *d,
00254 const char *sysfs_path,
00255 struct sysfs_device *device)
00256 {
00257 }
00258
00259 void
00260 bus_device_got_udi (BusDeviceHandler *self,
00261 HalDevice *d,
00262 const char *udi)
00263 {
00264 }
00265
00266