Logo Search packages:      
Sourcecode: hal version File versions

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.

Definition at line 465 of file common.c.

References di_search_and_merge(), hal_device_print(), HAL_ERROR, and HAL_INFO.

Referenced by bus_device_got_parent(), and detect_media().

{
      int append_num;
      char *computed_udi;
      HalDevice *computed_d;

      /* udi is a temporary udi */

      append_num = -1;
tryagain:
      /* compute the udi for the device */
      computed_udi = (*naming_func) (d, append_num);

      /* See if a device with the computed udi already exist. It can exist
       * because the device-list is (can be) persistent across invocations 
       * of hald.
       *
       * The name can also be taken already as the UDI computation methods
       * may not yield perfectly unique names; an interesting example is
       * multiple USB adapters - they show up as multiple PCI devices with
       * exactly the same characteristics expect slot location. And the
       * UDI computation method cannot depend on things like slot location
       * etc. 
       *
       * If it does exist, note that it's udi is computed from only the same 
       * information as our just computed udi.. So if we match, and it's
       * unplugged, it's the same device!
       *
       * (of course assuming that our udi computing algorithm actually works!
       *  Which it might not, see discussions - but we can get close enough
       *  for it to be practical)
       */
      computed_d = hal_device_store_find (hald_get_gdl (), computed_udi);

      /* Ok, see if it's in the TDL as we may process several identical
       * devices at the same time (see above example with multiple USB
       * adapters)
       */
      if (computed_d == NULL) {

            computed_d = hal_device_store_find (hald_get_tdl (), 
                                        computed_udi);
      }

      if (computed_d != NULL) {

            if (hal_device_property_get_bool (computed_d,
                                      "info.not_available")) {
                  /* Danger, Will Robinson! Danger!
                   *
                   * Ok, this means that either
                   *
                   * a) The user plugged in two instances of the kind of
                   *    of device; or
                   *
                   * b) The agent is invoked with --probe for the second
                   *    time during the life of the HAL daemon
                   *
                   * We want to support b) otherwise we end up adding a
                   * lot of devices which is a nuisance.. We also want to
                   * be able to do b) when developing HAL agents.
                   *
                   * So, therefore we check if the non-unplugged device 
                   * has the same bus information as our newly hotplugged
                   * one.
                   */
                  if (hal_device_matches (computed_d, d, namespace)) {
                        HAL_ERROR (("Found device already present "
                                  "as '%s'!\n", computed_d->udi));
                        hal_device_print (d);
                        hal_device_print (computed_d);
                        /* indeed a match, must be b) ;ignore device */
                        hal_device_store_remove (hald_get_tdl (), d);
                        g_object_unref (d);
                        /* and return */
                        return NULL;
                  }
                  
                  /** Not a match, must be case a). Choose next 
                   *  computed_udi and try again! */
                  append_num++;
                  goto tryagain;
            } else {
                  /* must be another instance of this type of device */
                  append_num++;
                  goto tryagain;
            }

            /* It did exist! Merge our properties from the probed device
             * since some of the bus-specific properties are likely to be
             * different 
             *
             * (user may have changed port, #Dev is different etc.)
             *
             * Note that the probed device only contain bus-specific
             * properties - the other properties will remain..
             */
            hal_device_merge (computed_d, d);

            /* Set that we are back in business! */
            hal_device_property_set_bool (computed_d, "info.not_available",
                                    FALSE);

            HAL_INFO (("Device %s is plugged in again",
                     computed_d->udi));

      } else {
            /* Device is not in list... */

            /* assign the computed device name */
            /*HAL_INFO ((" ##### computed_udi=%s", computed_udi));*/
            hal_device_set_udi (d, computed_udi);
            hal_device_property_set_string (d, "info.udi", computed_udi);

            /* Search for device information file and attempt merge */
            if (di_search_and_merge (d)) {
                  HAL_INFO (("Found a .fdi file for %s", d->udi));
            }

            /* add possible saved properties for this udi from disk*/
            if (hald_get_conf ()->persistent_device_list)
                  hal_pstore_load_device (hald_get_pstore_sys (), d);
      }

      return computed_udi;
}


Generated by  Doxygen 1.6.0   Back to index