static int rsct_usbdev_scan_serial(char **devices, int i_devices,
				   rsct_usbdev_t **usbdev_list) {
  int i;

  for (i=0; i<i_devices; i++) {
    const char *udi=devices[i];

    if (libhal_device_exists(global_hal_context->ctx, udi, &(global_hal_context->dbus_error))) {
      char *busType;

      busType=libhal_device_get_property_string(global_hal_context->ctx, udi, "info.subsystem", NULL);
      if (busType==NULL)
	busType=libhal_device_get_property_string(global_hal_context->ctx, udi, "info.bus", NULL);
      if (busType) {
	if (strcasecmp(busType, "tty")==0) {
	  char *parent_udi;
  
	  /* ttyUSB device, get USB info from parent */
	  parent_udi=libhal_device_get_property_string(global_hal_context->ctx,
						       udi,
						       "info.parent",
						       NULL);
	  if (parent_udi) {
	    rsct_usbdev_t *d;
	    char *path;

            /* find device entry for parent */
	    d=rsct_usbdev_list_findByUDI(*usbdev_list, parent_udi);
	    if (d) {
              int port;

	      port=libhal_device_get_property_int(global_hal_context->ctx,
						  udi,
						  "serial.port",
						  NULL);
	      d->port=port;

	      path=libhal_device_get_property_string(global_hal_context->ctx,
						     udi,
						     "serial.device",
						     NULL);
	      if (path) {
		strncpy(d->deviceNodePath, path, sizeof(d->deviceNodePath)-1);
		d->deviceNodePath[sizeof(d->deviceNodePath)-1]=0;
		libhal_free_string(path);
	      }
	    }
	    libhal_free_string(parent_udi);
	  }
	  else {
	    fprintf(stderr, "RSCT: Parent for serial device not found\n");
	  }
	} /* if tty */
	libhal_free_string(busType);
      } /* if bus type */
    } /* if device exists */
  } /* for */

  return 0;
}
Beispiel #2
0
static gboolean hal_get_ipod_usb_position (LibHalContext *ctx, const char *udi,
                                           int *usb_bus_number, int *usb_device_number)
{
	char *parent_udi;
	char *subsystem;
	gboolean found_ids;
	DBusError error;


	parent_udi = NULL;
	subsystem = NULL;
	found_ids = FALSE;
	dbus_error_init (&error);
	while (TRUE) {
		parent_udi = libhal_device_get_property_string (ctx, udi,
				"info.parent", &error);
		if (parent_udi == NULL || dbus_error_is_set (&error))
			goto end;
		udi = parent_udi;
		subsystem = libhal_device_get_property_string (ctx, udi,
							       "linux.subsystem",
							       &error);
		if (subsystem == NULL || dbus_error_is_set (&error)) {
			dbus_error_free (&error);
			dbus_error_init (&error);
			continue;
		}
		if (strcmp (subsystem, "usb") == 0) {
			*usb_bus_number = libhal_device_get_property_int (ctx, udi,
									  "usb.bus_number", &error);
			if (dbus_error_is_set (&error)) {
				goto end;
			}
			*usb_device_number = libhal_device_get_property_int (ctx, udi,
									     "usb.linux.device_number", &error);
			if (dbus_error_is_set (&error)) {
				goto end;
			}
			found_ids = TRUE;
			goto end;
		}
	}
end:
	libhal_free_string (parent_udi);
	libhal_free_string (subsystem);
	if (dbus_error_is_set (&error)) {
	    g_print ("Error: %s\n", error.message);
	    dbus_error_free (&error);
	}

	return found_ids;
}
static void
device_added_callback (LibHalContext *ctx, const char *udi)
{
	gchar *type_string;
	gchar *class_string;
	int type;
	const gchar *element;
	gchar *pipeline, *description;
	gboolean ignore;

	if (!libhal_device_query_capability (ctx, udi, "alsa", NULL)) {
		return;
	}

	/* filter out "digitizer", "modem", "none", "unknown" */
	class_string = libhal_device_get_property_string (ctx, udi, "alsa.pcm_class", NULL);
	ignore = class_string != NULL
		 && strcmp (class_string, "generic") != 0
		 && strcmp (class_string, "multi") != 0;
	libhal_free_string (class_string);
	if (ignore) {
		return;
	}

	type_string = libhal_device_get_property_string (ctx, udi, "alsa.type", NULL);
	if (strcmp (type_string, "playback") == 0) {
		type = AUDIO_PLAYBACK;
		element = "halaudiosink";
	} else if (strcmp (type_string, "capture") == 0) {
		type = AUDIO_CAPTURE;
		element = "halaudiosrc";
	} else {
		type = -1;
		element = NULL;
	}
	libhal_free_string (type_string);
	if (type == -1) {
		return;
	}

	pipeline = g_strdup_printf ("%s udi=%s", element, udi);
	description = libhal_device_get_property_string (ctx, udi, "alsa.device_id", NULL);

	add_device (type, pipeline, description, NULL);

	g_free (pipeline);
	libhal_free_string (description);
}
Beispiel #4
0
void CHALManager::UpdateDevice(const char *udi)
{
  CSingleLock lock(m_lock);
  char *category;
  category = libhal_device_get_property_string(m_Context, udi, "info.category", NULL);
  if (category == NULL)
    return;

  if (strcmp(category, "volume") == 0)
  {
    CStorageDevice dev(udi);
    if (!DeviceFromVolumeUdi(udi, &dev))
      return;
    for (unsigned int i = 0; i < m_Volumes.size(); i++)
    {
      if (strcmp(m_Volumes[i].UDI.c_str(), udi) == 0)
      {
        CLog::Log(LOGDEBUG, "HAL: Update - %s | %s", CHALManager::StorageTypeToString(dev.Type),  dev.toString().c_str());
        if (g_advancedSettings.m_handleMounting)  // If the device was mounted by XBMC before it's still mounted by XBMC.
            dev.MountedByXBMC = m_Volumes[i].MountedByXBMC;
        if (!dev.Mounted && m_Volumes[i].Mounted)
          CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(13023), dev.FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
        m_Volumes[i] = dev;

        break;
      }
    }
  }

  libhal_free_string(category);
}
Beispiel #5
0
// Helper function. creates a CStorageDevice from a HAL udi
bool CHALManager::DeviceFromVolumeUdi(const char *udi, CStorageDevice *device)
{
  if (g_HalManager.m_Context == NULL)
    return false;

  LibHalVolume *tempVolume;
  LibHalDrive  *tempDrive;
  bool Created = false;

  tempVolume = libhal_volume_from_udi(g_HalManager.m_Context, udi);
  if (tempVolume)
  {
    const char *DriveUdi = libhal_volume_get_storage_device_udi(tempVolume);
    tempDrive = libhal_drive_from_udi(g_HalManager.m_Context, DriveUdi);

    if (tempDrive)
    {
      char * FriendlyName   = libhal_device_get_property_string(g_HalManager.m_Context, udi, "info.product", NULL);
      device->FriendlyName  = FriendlyName;
      libhal_free_string(FriendlyName);
      char *block = libhal_device_get_property_string(g_HalManager.m_Context, udi, "block.device", NULL);
      device->DevID         = block;
      libhal_free_string(block);

      device->HotPlugged  = (bool)libhal_drive_is_hotpluggable(tempDrive);
      device->Type        = libhal_drive_get_type(tempDrive);
      device->Mounted     = (bool)libhal_volume_is_mounted(tempVolume);
      device->MountPoint  = libhal_volume_get_mount_point(tempVolume);
      if (device->Mounted)
        URIUtils::AddSlashAtEnd(device->MountPoint);
      device->Label       = libhal_volume_get_label(tempVolume);
      device->UUID        = libhal_volume_get_uuid(tempVolume);
      device->FileSystem  = libhal_volume_get_fstype(tempVolume);
      device->HalIgnore   = libhal_device_get_property_bool(g_HalManager.m_Context, udi, "volume.ignore", NULL);
      ApproveDevice(device);

      libhal_drive_free(tempDrive);
      Created = true;
    }
    else
      CLog::Log(LOGERROR, "HAL: Couldn't create a Drive even if we had a volume - %s", udi);

    libhal_volume_free(tempVolume);
  }

  return Created;
}
Beispiel #6
0
static char *
get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
{
    char *prop, *ret;

    prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL);
    DebugF(" [config/hal] getting %s on %s returned %s\n", name, udi, prop);
    if (prop) {
        ret = xstrdup(prop);
        libhal_free_string(prop);
    }
    else {
        return NULL;
    }

    return ret;
}
Beispiel #7
0
static char *
get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
{
    char *prop, *ret;

    prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL);
    LogMessageVerb(X_INFO, 10, "config/hal: getting %s on %s returned %s\n", name, udi, prop ? prop : "(null)");
    if (prop) {
        ret = xstrdup(prop);
        libhal_free_string(prop);
    }
    else {
        return NULL;
    }

    return ret;
}
Beispiel #8
0
int
open_device(LibHalContext *ctx, char *udi)
{
	char path[HAL_PATH_MAX] = "/devices";
	char *devfs_path;
	DBusError error;

	dbus_error_init(&error);
	devfs_path = libhal_device_get_property_string(ctx, udi,
	    "solaris.devfs_path", &error);
	my_dbus_error_free(&error);
	if (devfs_path == NULL) {
		return (-1);
	}
	strlcat(path, devfs_path, HAL_PATH_MAX);
	libhal_free_string(devfs_path);
	return (open(path, O_RDONLY | O_NONBLOCK));
}
Beispiel #9
0
static void hal_property_modified(LibHalContext *ctx, const char *udi,
	  const char *key, dbus_bool_t is_removed, dbus_bool_t is_added)
{

	if (!strcmp(key, "volume.is_mounted")) {
		if (libhal_device_get_property_bool(ctx, udi, "volume.is_mounted", NULL)) {
			char *mountpoint = libhal_device_get_property_string(
					ctx, udi, "volume.mount_point", NULL);
			
			if (!strncmp(MEDIA_DIR, mountpoint, strlen(MEDIA_DIR))) {
				add_mount(udi, mountpoint);
			}

			if (mountpoint)
				libhal_free_string(mountpoint);
		} else {
			remove_mount(udi);
		}

		update_status();
	}
}
Beispiel #10
0
static boolean_t
volume_should_mount(const char *udi)
{
	char	*storage_device = NULL;
	int	ret = B_FALSE;

	if (libhal_device_get_property_bool(hal_ctx, udi,
	    "volume.ignore", NULL)) {
		goto out;
	}

	/* get the backing storage device */
	if (!(storage_device = libhal_device_get_property_string(hal_ctx, udi,
	    "block.storage_device", NULL))) {
		dprintf("cannot get block.storage_device\n");
		goto out;
	}

	/* we handle either removable or hotpluggable */
	if (!libhal_device_get_property_bool(hal_ctx, storage_device,
	    "storage.removable", NULL) &&
	    !libhal_device_get_property_bool(hal_ctx, storage_device,
	    "storage.hotpluggable", NULL)) {
		goto out;
	}

	/* ignore if claimed by another volume manager */
	if (libhal_device_get_property_bool(hal_ctx, storage_device,
	    "info.claimed", NULL)) {
		goto out;
	}

	ret = B_TRUE;

out:
	libhal_free_string(storage_device);
	return (ret);
}
Beispiel #11
0
static LibHalVolume	*pusb_volume_probe(t_pusb_options *opts,
		LibHalContext *ctx)
{
	LibHalVolume	*volume = NULL;
	int				maxtries = 0;
	int				i;

	if (!*(opts->device.volume_uuid))
	{
		log_debug("No UUID configured for device\n");
		return (NULL);
	}
	log_debug("Searching for volume with uuid %s\n", opts->device.volume_uuid);
	maxtries = ((opts->probe_timeout * 1000000) / 250000);
	for (i = 0; i < maxtries; ++i)
	{
		char	*udi = NULL;

		if (i == 1)
			log_info("Probing volume (this could take a while)...\n");
		udi = pusb_hal_find_item(ctx,
				"volume.uuid", opts->device.volume_uuid,
				NULL);
		if (!udi)
		{
			usleep(250000);
			continue;
		}
		volume = libhal_volume_from_udi(ctx, udi);
		libhal_free_string(udi);
		if (!libhal_volume_should_ignore(volume))
			return (volume);
		libhal_volume_free(volume);
		usleep(250000);
	}
	return (NULL);
}
Beispiel #12
0
static void
device_added_callback( LibHalContext *ctx, const char *udi )
{
  if( libhal_device_property_exists( ctx, udi, "battery", NULL ) )
  {
    char *type = libhal_device_get_property_string( ctx, udi,
                                                    "battery.type",
                                                    NULL );

    if( type )
    {
      /* We only track 'primary' batteries (ie: to avoid monitoring
       * batteries in cordless mice or UPSes etc.)
       */
      if( !strcmp( type, "primary" ) )
        add_to_list( ctx, &batteries, udi, sizeof (struct battery_info) );

      libhal_free_string( type );
    }
  }

  if( libhal_device_property_exists( ctx, udi, "ac_adapter", NULL ) )
    add_to_list( ctx, &adaptors, udi, sizeof (struct adaptor_info) );
}
Beispiel #13
0
/* Callback function, called when a new device has been inserted. */
static void
device_added(LibHalContext *context, const char *did)
{
    const char *dudi, *fstype;
    char *dev, *mountp, *mountable, *label, *locked_reason;
    LibHalVolume *volume;
    LibHalDrive *drive;
    struct device_t *device;

    if (libhal_device_property_exists(context, did, "info.locked",
                                      (DBusError *)NULL)
            && libhal_device_get_property_bool(context, did, "info.locked",
                                               (DBusError *)NULL)) {
        if (debug_mode_flag) {
            locked_reason = libhal_device_get_property_string(
                                context, did, "info.locked.reason",
                                (DBusError *)NULL);
            if (locked_reason) {
                if (debug_mode_flag)
                    printf("%s%d: %s\n", __FILE__, __LINE__, locked_reason);
                libhal_free_string(locked_reason);
            }
        }
        return;
    }

    if (!libhal_device_query_capability(context, did, "volume",
                                        (DBusError *)NULL))
        return;
    label = libhal_device_get_property_string(context, did, "volume.label",
                                              (DBusError *)NULL);
    if (!(mountable = libhal_device_get_property_string(
                          context, did, "volume.fsusage", (DBusError *)NULL))
            || strcmp(mountable, "filesystem"))
        goto out;
    if (!(volume = libhal_volume_from_udi(context, did)))
        goto out;
    if (!(dudi = libhal_volume_get_storage_device_udi(volume)))
        goto out;
    if (!(drive = libhal_drive_from_udi(context, dudi)))
        goto out;
    if (!libhal_drive_is_hotpluggable(drive)
            && !libhal_drive_uses_removable_media(drive))
        goto out;
    if (!(fstype = libhal_volume_get_fstype(volume)))
        goto out;
    if (!(dev = libhal_device_get_property_string(context, did, "block.device",
                                                  (DBusError *)NULL)))
        goto out;
    mountp = get_mount_point(dev, label);
    if (!mountp)
        goto out;
    device = get_device(mountp, did, dev, label, fstype, volume, drive);
    if(!is_mounted(device)) {
        free_device(device);
        goto out;
    }
    if (!device)
        goto out;
    consider_fstab(device);

    device->hook = malloc(2*sizeof(char*)); 
    if(!file_exists(HOOK_PATH)) {
        device->hook[0] = get_hook(device, "mount");
        device->hook[1] = get_hook(device, "umount");
    }
    else {
        device->hook[0] = NULL;
        device->hook[1] = NULL;
    }

    if (file_exists(device->mountp) < 0)
        mkdir(device->mountp, 0750);
    do_mount(device) < 0 ? free_device(device) : add_to_device_list(device);

    if (device) {
        if (!add_fstab_entry(device))
            device->should_remove_entry = 1;
        if (debug_mode_flag)
            debug_dump_device(device);
    }

    if (device->hook[0]) run_hook(0, device);

out:
    if (mountable)
        libhal_free_string(mountable);
    if (label)
        libhal_free_string(label);
}
Beispiel #14
0
int
prt_dev_props(LibHalContext *hal_ctx, char *dev_name)
{
	LibHalPropertySet *props;
	LibHalPropertySetIterator it;
	DBusError error;
	int type;
	char *devfs_path;

	dbus_error_init(&error);

	if (!(props =
		libhal_device_get_all_properties(hal_ctx, dev_name, &error))) {
		fprintf(stderr, "%s: %s\n", error.name, error.message);
		dbus_error_free(&error);
		return (1);
	}

	devfs_path = libhal_device_get_property_string(hal_ctx,
			dev_name, "solaris.devfs_path", &error);
	if (devfs_path) {
		printf("devfs path:%s\n", devfs_path);
		libhal_free_string(devfs_path);
	}

	for (libhal_psi_init(&it, props); libhal_psi_has_more(&it);
			libhal_psi_next(&it)) {
		type = libhal_psi_get_type(&it);
		switch (type) {
			case LIBHAL_PROPERTY_TYPE_STRING:
				printf("%s:'%s'\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_string(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_INT32:
				printf("%s:%d\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_int(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_UINT64:
				printf("%s:%lld\n",
					libhal_psi_get_key(&it),
				(long long) libhal_psi_get_uint64(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_DOUBLE:
				printf("%s:%g\n",
					libhal_psi_get_key(&it),
					libhal_psi_get_double(&it));
				break;
			case LIBHAL_PROPERTY_TYPE_BOOLEAN:
				printf("%s:%s\n",
				libhal_psi_get_key(&it),
				libhal_psi_get_bool(&it) ? "true" : "false");
				break;
			case LIBHAL_PROPERTY_TYPE_STRLIST:
				{
					char **strlist;

					printf("%s:{ ",
					libhal_psi_get_key(&it));
					strlist = libhal_psi_get_strlist(&it);
					while (*strlist) {
						printf("'%s'%s",
					*strlist, strlist[1] ? ", " : "");
						strlist++;
					}
					printf(" }\n");
				}
				break;
			default:
				printf("Unknown type:%d=0x%02x\n",
					type, type);
				break;
			}
	}

	libhal_free_property_set(props);
	printf("\n");
	dbus_error_free(&error);
	return (0);
}
Beispiel #15
0
static void
get_video_devices (ofGstCamData & cam_data)
{

    int            i, fd, ok;
    int            num_udis = 0;
    char         **udis;
    DBusError      error;
    LibHalContext *hal_ctx;

    cam_data.num_webcam_devices = 0;

    g_print ("Probing devices with HAL...\n");

    dbus_error_init (&error);
    hal_ctx = libhal_ctx_new ();
    if (hal_ctx == NULL)
    {
        g_warning ("Could not create libhal context");
        dbus_error_free (&error);
        goto fallback;
    }

    if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error)))
    {
        g_warning ("libhal_ctx_set_dbus_connection: %s: %s", error.name, error.message);
        dbus_error_free (&error);
        goto fallback;
    }

    if (!libhal_ctx_init (hal_ctx, &error))
    {
        if (dbus_error_is_set (&error))
        {
            g_warning ("libhal_ctx_init: %s: %s", error.name, error.message);
            dbus_error_free (&error);
        }
        g_warning ("Could not initialise connection to hald.\n"
                   "Normally this means the HAL daemon (hald) is not running or not ready");
        goto fallback;
    }

    udis = libhal_find_device_by_capability (hal_ctx, "video4linux", &num_udis, &error);

    if (dbus_error_is_set (&error))
    {
        g_warning ("libhal_find_device_by_capability: %s: %s", error.name, error.message);
        dbus_error_free (&error);
        goto fallback;
    }

    /* Initialize webcam structures */
    cam_data.webcam_devices = new ofGstDevice[num_udis];

    for (i = 0; i < num_udis; i++)
    {
        char                   *device;
        char                   *parent_udi = NULL;
        char                   *subsystem = NULL;
        char                   *gstreamer_src, *product_name;
        struct v4l2_capability  v2cap;
        struct video_capability v1cap;
        gint vendor_id = 0;
        gint product_id = 0;
        gchar *property_name = NULL;

        parent_udi = libhal_device_get_property_string (hal_ctx, udis[i], "info.parent", &error);
        if (dbus_error_is_set (&error))
        {
            g_warning ("error getting parent for %s: %s: %s", udis[i], error.name, error.message);
            dbus_error_free (&error);
        }

        if (parent_udi != NULL) {
            subsystem = libhal_device_get_property_string (hal_ctx, parent_udi, "info.subsystem", NULL);
            if (subsystem == NULL) continue;
            property_name = g_strjoin (".", subsystem, "vendor_id", NULL);
            vendor_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name , &error);
            if (dbus_error_is_set (&error)) {
                g_warning ("error getting vendor id: %s: %s", error.name, error.message);
                dbus_error_free (&error);
            }
            g_free (property_name);

            property_name = g_strjoin (".", subsystem, "product_id", NULL);
            product_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name, &error);
            if (dbus_error_is_set (&error)) {
                g_warning ("error getting product id: %s: %s", error.name, error.message);
                dbus_error_free (&error);
            }
            g_free (property_name);
            libhal_free_string (subsystem);
            libhal_free_string (parent_udi);
        }

        g_print ("Found device %04x:%04x, getting capabilities...\n", vendor_id, product_id);

        device = libhal_device_get_property_string (hal_ctx, udis[i], "video4linux.device", &error);
        if (dbus_error_is_set (&error))
        {
            g_warning ("error getting V4L device for %s: %s: %s", udis[i], error.name, error.message);
            dbus_error_free (&error);
            continue;
        }

        /* vbi devices support capture capability too, but cannot be used,
         * so detect them by device name */
        if (strstr (device, "vbi"))
        {
            g_print ("Skipping vbi device: %s\n", device);
            libhal_free_string (device);
            continue;
        }

        if ((fd = open (device, O_RDONLY | O_NONBLOCK)) < 0)
        {
            g_warning ("Failed to open %s: %s", device, strerror (errno));
            libhal_free_string (device);
            continue;
        }
        ok = ioctl (fd, VIDIOC_QUERYCAP, &v2cap);
        if (ok < 0)
        {
            ok = ioctl (fd, VIDIOCGCAP, &v1cap);
            if (ok < 0)
            {
                g_warning ("Error while probing v4l capabilities for %s: %s",
                           device, strerror (errno));
                libhal_free_string (device);
                close (fd);
                continue;
            }
            g_print ("Detected v4l device: %s\n", v1cap.name);
            g_print ("Device type: %d\n", v1cap.type);
            gstreamer_src = "v4lsrc";
            product_name  = v1cap.name;
        }
        else
        {
            guint cap = v2cap.capabilities;
            g_print ("Detected v4l2 device: %s\n", v2cap.card);
            g_print ("Driver: %s, version: %d\n", v2cap.driver, v2cap.version);
            /* g_print ("Bus info: %s\n", v2cap.bus_info); */ /* Doesn't seem anything useful */
            g_print ("Capabilities: 0x%08X\n", v2cap.capabilities);
            if (!(cap & V4L2_CAP_VIDEO_CAPTURE))
            {
                g_print ("Device %s seems to not have the capture capability, (radio tuner?)\n"
                         "Removing it from device list.\n", device);
                libhal_free_string (device);
                close (fd);
                continue;
            }
            gstreamer_src = "v4l2src";
            product_name  = (char *) v2cap.card;
        }

        g_print ("\n");

        cam_data.webcam_devices[cam_data.num_webcam_devices].hal_udi           = g_strdup (udis[i]);
        cam_data.webcam_devices[cam_data.num_webcam_devices].video_device      = g_strdup (device);
        cam_data.webcam_devices[cam_data.num_webcam_devices].gstreamer_src     = g_strdup (gstreamer_src);
        cam_data.webcam_devices[cam_data.num_webcam_devices].product_name      = g_strdup (product_name);
        cam_data.webcam_devices[cam_data.num_webcam_devices].num_video_formats = 0;
        cam_data.webcam_devices[cam_data.num_webcam_devices].supported_resolutions =
            g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
        cam_data.num_webcam_devices++;

        libhal_free_string (device);
        close (fd);
    }
    libhal_free_string_array (udis);

    if (cam_data.num_webcam_devices == 0)
    {
        /* Create a fake device so that resolution changing stil works even if the
         * computer doesn't have a webcam. */
fallback:
        if (num_udis == 0)
        {
            cam_data.webcam_devices = new ofGstDevice;
        }
        cam_data.webcam_devices[0].num_video_formats = 0;
        cam_data.webcam_devices[0].hal_udi = g_strdup ("oF_fake_videodevice");
    }
    cam_data.bInited=true;

}
Beispiel #16
0
	std::map<int, std::pair<std::string, std::string> > SerialPortEnumerator::getPorts()
	{
		std::map<int, std::pair<std::string, std::string> > ports;
		


#ifdef MACOSX
		// use IOKit to enumerates devices
		
		// get a matching dictionary to specify which IOService class we're interested in
		CFMutableDictionaryRef classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
		if (classesToMatch == NULL)
			throw DashelException(DashelException::EnumerationError, 0, "IOServiceMatching returned a NULL dictionary");
		
		// specify all types of serial devices
		CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
		
		// get an iterator to serial port services
		io_iterator_t matchingServices;
		kern_return_t kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, classesToMatch, &matchingServices);    
		if (KERN_SUCCESS != kernResult)
			throw DashelException(DashelException::EnumerationError, kernResult, "IOServiceGetMatchingServices failed");
			
		// iterate over services
		io_object_t modemService;
		int index = 0;
		while((modemService = IOIteratorNext(matchingServices)))
		{
			// get path for device
			CFTypeRef bsdPathAsCFString = IORegistryEntryCreateCFProperty(modemService, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0);
			if (bsdPathAsCFString)
			{
				std::string path;
				char cStr[255];
				std::string name;
				
				bool res = CFStringGetCString((CFStringRef) bsdPathAsCFString, cStr, 255, kCFStringEncodingUTF8);
				if(res)
					path = cStr;
				else
					throw DashelException(DashelException::EnumerationError, 0, "CFStringGetCString failed");
				
				CFRelease(bsdPathAsCFString);
				
				CFTypeRef fn = IORegistryEntrySearchCFProperty(modemService, kIOServicePlane, CFSTR("USB Product Name"), kCFAllocatorDefault,
										kIORegistryIterateRecursively | kIORegistryIterateParents);
				if(fn) {
					res = CFStringGetCString((CFStringRef) fn, cStr, 255, kCFStringEncodingUTF8);
					if(res) 
						name = cStr;
					else
						throw DashelException(DashelException::EnumerationError, 0, "CFStringGetString failed");

					CFRelease(fn);
				} else 
					name = "Serial Port";
				name = name + " (" + path + ")";
				ports[index++] = std::make_pair<std::string, std::string>(path, name);
			}
			else
				throw DashelException(DashelException::EnumerationError, 0, "IORegistryEntryCreateCFProperty returned a NULL path");
			
			// release service
			IOObjectRelease(modemService);
		}

		IOObjectRelease(matchingServices);

			
#elif defined(USE_LIBUDEV)

		struct udev *udev;
		struct udev_enumerate *enumerate;
		struct udev_list_entry *devices, *dev_list_entry;
		struct udev_device *dev;
		int index = 0;

		udev = udev_new();
		if(!udev)
			throw DashelException(DashelException::EnumerationError, 0, "Cannot create udev context");

		enumerate = udev_enumerate_new(udev);
		udev_enumerate_add_match_subsystem(enumerate, "tty");
		udev_enumerate_scan_devices(enumerate);
		devices = udev_enumerate_get_list_entry(enumerate);

		udev_list_entry_foreach(dev_list_entry, devices) {
			const char *sysfs_path;
			struct udev_device *usb_dev;
			const char * path;
			struct stat st;
			unsigned int maj,min;

			/* Get sysfs path and create the udev device */
			sysfs_path = udev_list_entry_get_name(dev_list_entry);
			dev = udev_device_new_from_syspath(udev, sysfs_path);

			// Some sanity check
			path = udev_device_get_devnode(dev);
			if(stat(path, &st)) 
				throw DashelException(DashelException::EnumerationError, 0, "Cannot stat serial port");
			
			if(!S_ISCHR(st.st_mode))
				throw DashelException(DashelException::EnumerationError, 0, "Serial port is not character device");

			// Get the major/minor number
			maj = major(st.st_rdev);
			min = minor(st.st_rdev);

			// Ignore all the non physical ports
			if(!(maj == 2 || (maj == 4 && min < 64) || maj == 3 || maj == 5)) {
				ostringstream oss;

				// Check if usb, if yes get the device name
				usb_dev = udev_device_get_parent_with_subsystem_devtype(dev,"usb","usb_device");
				if(usb_dev)
					oss << udev_device_get_sysattr_value(usb_dev,"product");
				else
					oss << "Serial Port";

				oss << " (" << path << ")";

				ports[index++] = std::make_pair<std::string, std::string>(path,oss.str());
			}
			udev_device_unref(dev);
		}
		
		udev_enumerate_unref(enumerate);

		udev_unref(udev);

#elif defined(USE_HAL)

		// use HAL to enumerates devices
		DBusConnection* dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, 0);
		if (!dbusConnection)
			throw DashelException(DashelException::EnumerationError, 0, "cannot connect to D-BUS.");
		
		LibHalContext* halContext = libhal_ctx_new();
		if (!halContext)
			throw DashelException(DashelException::EnumerationError, 0, "cannot create HAL context: cannot create context");
		if (!libhal_ctx_set_dbus_connection(halContext, dbusConnection))
			throw DashelException(DashelException::EnumerationError, 0, "cannot create HAL context: cannot connect to D-BUS");
		if (!libhal_ctx_init(halContext, 0))
			throw DashelException(DashelException::EnumerationError, 0, "cannot create HAL context: cannot init context");
		
		int devicesCount;
		char** devices = libhal_find_device_by_capability(halContext, "serial", &devicesCount, 0);
		for (int i = 0; i < devicesCount; i++)
		{
			char* devFileName = libhal_device_get_property_string(halContext, devices[i], "serial.device", 0);
			char* info = libhal_device_get_property_string(halContext, devices[i], "info.product", 0);
			int port = libhal_device_get_property_int(halContext, devices[i], "serial.port", 0);
			
			ostringstream oss;
			oss << info << " " << port;
			ports[devicesCount - i] = std::make_pair<std::string, std::string>(devFileName, oss.str());
			
			libhal_free_string(info);
			libhal_free_string(devFileName);
		}
		
		libhal_free_string_array(devices);
		libhal_ctx_shutdown(halContext, 0);
		libhal_ctx_free(halContext);
#endif
		
		return ports;
	};
Beispiel #17
0
static void
force_unmount (LibHalContext *ctx, const char *udi)
{
	DBusError error;
	DBusMessage *msg = NULL;
	DBusMessage *reply = NULL;
	char **options = NULL;
	unsigned int num_options = 0;
	DBusConnection *dbus_connection;
	char *device_file;

	dbus_error_init (&error);

	dbus_connection = libhal_ctx_get_dbus_connection (ctx);

	msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
					    "org.freedesktop.Hal.Device.Volume",
					    "Unmount");
	if (msg == NULL) {
		HAL_DEBUG (("Could not create dbus message for %s", udi));
		goto out;
	}


	options = calloc (1, sizeof (char *));
	if (options == NULL) {
		HAL_DEBUG (("Could not allocate options array"));
		goto out;
	}

	device_file = libhal_device_get_property_string (ctx, udi, "block.device", &error);
	if (device_file != NULL) {
		libhal_free_string (device_file);
	}
	dbus_error_free (&error);

	if (!dbus_message_append_args (msg, 
				       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options,
				       DBUS_TYPE_INVALID)) {
		HAL_DEBUG (("Could not append args to dbus message for %s", udi));
		goto out;
	}
	
	if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) {
		HAL_DEBUG (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message));
		goto out;
	}

	if (dbus_error_is_set (&error)) {
		HAL_DEBUG (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message));
		goto out;
	}

	HAL_DEBUG (("Succesfully unmounted udi '%s'", udi));

out:
	dbus_error_free (&error);
	if (options != NULL)
		free (options);
	if (msg != NULL)
		dbus_message_unref (msg);
	if (reply != NULL)
		dbus_message_unref (reply);
}
Beispiel #18
0
static void
battery_dynamic_update(LibHalContext *ctx, const char *udi, int fd)
{
	int reporting_rate;
	int reporting_current;
	int reporting_lastfull;
	int design_voltage;
	int present_voltage;
	char *reporting_unit;
	int remaining_time;
	int remaining_percentage;
	gboolean charging;
	gboolean discharging;
	acpi_bst_t bst;
	LibHalChangeSet *cs;
	DBusError error;
	static int counter = 0;

	HAL_DEBUG(("battery_dynamic_update() enter"));
	bzero(&bst, sizeof (bst));
	if (ioctl(fd, BATT_IOC_STATUS, &bst) < 0) {
		return;
	}

	charging = bst.bst_state & BATT_BST_CHARGING ? TRUE : FALSE;
	discharging = bst.bst_state & BATT_BST_DISCHARGING ? TRUE : FALSE;
	/* No need to continue if battery is essentially idle. */
	if (counter && !charging && !discharging) {
		return;
	}
	dbus_error_init(&error);
	libhal_device_set_property_bool(ctx, udi, "battery.is_rechargeable",
	    TRUE, &error);
	my_dbus_error_free(&error);
	if (libhal_device_property_exists(ctx, udi,
	    "battery.charge_level.percentage", &error)) {
		remaining_percentage = libhal_device_get_property_int(ctx, udi,
		    "battery.charge_level.percentage", &error);
		if ((remaining_percentage == 100) && charging) {
			charging = FALSE;
		}
	}
	libhal_device_set_property_bool(ctx, udi,
	    "battery.rechargeable.is_charging", charging, &error);
	my_dbus_error_free(&error);
	libhal_device_set_property_bool(ctx, udi,
	    "battery.rechargeable.is_discharging", discharging, &error);
	my_dbus_error_free(&error);
	reporting_current = bst.bst_rem_cap;
	libhal_device_set_property_int(ctx, udi, "battery.reporting.current",
	    bst.bst_rem_cap, &error);
	my_dbus_error_free(&error);
	reporting_rate = bst.bst_rate;
	libhal_device_set_property_int(ctx, udi, "battery.reporting.rate",
	    bst.bst_rate, &error);
	my_dbus_error_free(&error);
	present_voltage = bst.bst_voltage;
	libhal_device_set_property_int(ctx, udi, "battery.voltage.present",
	    bst.bst_voltage, &error);
	/* get all the data we know */
	my_dbus_error_free(&error);
	reporting_unit = libhal_device_get_property_string(ctx, udi,
	    "battery.reporting.unit", &error);
	my_dbus_error_free(&error);
	reporting_lastfull = libhal_device_get_property_int(ctx, udi,
	    "battery.reporting.last_full", &error);

	/*
	 * Convert mAh to mWh since util_compute_time_remaining() works
	 * for mWh.
	 */
	if (reporting_unit && strcmp(reporting_unit, "mAh") == 0) {
		my_dbus_error_free(&error);
		design_voltage = libhal_device_get_property_int(ctx, udi,
		    "battery.voltage.design", &error);
		/*
		 * If the present_voltage is inaccurate, set it to the
		 * design_voltage.
		 */
		if (((present_voltage * 10) < design_voltage) ||
		    (present_voltage <= 0) ||
		    (present_voltage > design_voltage)) {
			present_voltage = design_voltage;
		}
		reporting_rate = (reporting_rate * present_voltage) / 1000;
		reporting_lastfull = (reporting_lastfull * present_voltage) /
		    1000;
		reporting_current = (reporting_current * present_voltage) /
		    1000;
	}

	/* Make sure the current charge does not exceed the full charge */
	if (reporting_current > reporting_lastfull) {
		reporting_current = reporting_lastfull;
	}
	if (!charging && !discharging) {
		counter++;
		reporting_rate = 0;
	}

	if ((cs = libhal_device_new_changeset(udi)) == NULL) {
		HAL_DEBUG(("Cannot allocate changeset"));
		libhal_free_string(reporting_unit);
		my_dbus_error_free(&error);
		return;
	}

	libhal_changeset_set_property_int(cs, "battery.charge_level.rate",
	    reporting_rate);
	libhal_changeset_set_property_int(cs,
	    "battery.charge_level.last_full", reporting_lastfull);
	libhal_changeset_set_property_int(cs,
	    "battery.charge_level.current", reporting_current);

	remaining_percentage = util_compute_percentage_charge(udi,
	    reporting_current, reporting_lastfull);
	remaining_time = util_compute_time_remaining(udi, reporting_rate,
	    reporting_current, reporting_lastfull, discharging, charging, 0);
	/*
	 * Some batteries give bad remaining_time estimates relative to
	 * the charge level.
	 */
	if (charging && ((remaining_time < 30) || ((remaining_time < 300) &&
	    (remaining_percentage < 95)) || (remaining_percentage > 97))) {
		remaining_time = util_compute_time_remaining(udi,
		    reporting_rate, reporting_current, reporting_lastfull,
		    discharging, charging, 1);
	}

	if (remaining_percentage > 0) {
		libhal_changeset_set_property_int(cs,
		    "battery.charge_level.percentage", remaining_percentage);
	} else {
		my_dbus_error_free(&error);
		libhal_device_remove_property(ctx, udi,
		    "battery.charge_level.percentage", &error);
	}
	if ((remaining_percentage == 100) && charging) {
		battery_last_full(cs, fd);
	}
	/*
	 * remaining_percentage is more accurate so we handle cases
	 * where the remaining_time cannot be correct.
	 */
	if ((!charging && !discharging) || ((remaining_percentage == 100) &&
	    !discharging)) {
		remaining_time = 0;
	}
	if (remaining_time < 0) {
		my_dbus_error_free(&error);
		libhal_device_remove_property(ctx, udi,
		    "battery.remaining_time", &error);
	} else if (remaining_time >= 0) {
		libhal_changeset_set_property_int(cs,
		    "battery.remaining_time", remaining_time);
	}

	my_dbus_error_free(&error);
	libhal_device_commit_changeset(ctx, cs, &error);
	libhal_device_free_changeset(cs);
	libhal_free_string(reporting_unit);
	my_dbus_error_free(&error);
	HAL_DEBUG(("battery_dynamic_update() exit"));
}
static void
get_device_info (RBGenericPlayerSource *source)
{
	RBGenericPlayerSourcePrivate *priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source);
	GMount *mount;
	GFile *is_audio_player;
	GError *error = NULL;
#ifdef HAVE_HAL
	LibHalContext *ctx;
#endif
	g_object_get (source, "mount", &mount, NULL);

#ifdef HAVE_HAL
	ctx = get_hal_context ();
	if (ctx != NULL) {
		char *udi;

		udi = get_hal_udi_for_player (ctx, mount);

		if (udi != NULL) {
			DBusError error;
			char *prop;
			char **proplist;
			int value;

			/* get audio folders */
			dbus_error_init (&error);
			proplist = libhal_device_get_property_strlist (ctx, udi, "portable_audio_player.audio_folders", &error);
			if (proplist) {
				if (!dbus_error_is_set (&error)) {
					priv->audio_folders = g_strdupv (proplist);
				}
				libhal_free_string_array (proplist);
			}
			free_dbus_error ("getting audio folder list", &error);

			/* get supported mime-types */
			dbus_error_init (&error);
			proplist = libhal_device_get_property_strlist (ctx, udi, "portable_audio_player.output_formats", &error);
			if (proplist) {
				if (!dbus_error_is_set (&error)) {
					priv->output_mime_types = g_strdupv (proplist);
				}
				libhal_free_string_array (proplist);
			}
			free_dbus_error ("getting supported mime-type list", &error);

			/* get playlist format */
			dbus_error_init (&error);
			proplist = libhal_device_get_property_strlist (ctx, udi, "portable_audio_player.playlist_format", &error);
			if (proplist) {
				if (!dbus_error_is_set (&error)) {
					set_playlist_formats (source, proplist);
				}
				libhal_free_string_array (proplist);
			}
			free_dbus_error ("getting playlist format", &error);

			/* get playlist path - in current hal-info packages, this is sometimes a string
			 * and sometimes a strlist, so try both. 
			 * http://bugs.freedesktop.org/show_bug.cgi?id=19961
			 */
			dbus_error_init (&error);
			proplist = libhal_device_get_property_strlist (ctx, udi, "portable_audio_player.playlist_path", &error);
			if (proplist && !dbus_error_is_set (&error)) {
				set_playlist_path (source, proplist[0]);
				libhal_free_string_array (proplist);
			}
			free_dbus_error ("getting playlist path (strlist)", &error);
			
			dbus_error_init (&error);
			prop = libhal_device_get_property_string (ctx, udi, "portable_audio_player.playlist_path", &error);
			if (prop && !dbus_error_is_set (&error)) {
				set_playlist_path (source, prop);
				libhal_free_string (prop);
			}
			free_dbus_error ("getting playlist path (string)", &error);

			/* get max folder depth */
			dbus_error_init (&error);
			value = libhal_device_get_property_int (ctx, udi, "portable_audio_player.folder_depth", &error);
			if (!dbus_error_is_set (&error)) {
				priv->folder_depth = value;
			}
			free_dbus_error ("getting max folder depth", &error);

			debug_device_info (source, mount, "HAL");
		} else {
			rb_debug ("no player info available (HAL doesn't recognise it as a player");
		}
		g_free (udi);
	}
	cleanup_hal_context (ctx);
#endif

	/* allow HAL info to be overridden with .is_audio_player file */
	is_audio_player = get_is_audio_player_file (mount);
	if (is_audio_player != NULL) {
		char *data = NULL;
		gsize data_size = 0;

		rb_debug ("reading .is_audio_player file");

		g_file_load_contents (is_audio_player, NULL, &data, &data_size, NULL, &error);
		if (error != NULL) {
			/* can we sensibly report this anywhere? */
			rb_debug ("error reading .is_audio_player file: %s", error->message);
			g_clear_error (&error);
		} else {
			GKeyFile *keyfile;
			GError *error = NULL;
			char *munged;
			gsize munged_size;
			const char *fake_group = "[x-rb-data]\n";
			char *group;

			/* prepend a group name to the file contents */
			munged_size = data_size + strlen (fake_group);
			munged = g_malloc0 (munged_size + 1);
			strcpy (munged, fake_group);
			memcpy (munged + strlen (fake_group), data, data_size);

			keyfile = g_key_file_new ();
			g_key_file_set_list_separator (keyfile, ',');
			if (g_key_file_load_from_data (keyfile, munged, munged_size, G_KEY_FILE_NONE, &error) == FALSE) {
				/* and this */
				rb_debug ("error loading .is_audio_player file: %s", error->message);
				g_error_free (error);
			} else {
				char *value;
				char **list;

				group = g_key_file_get_start_group (keyfile);
				
				list = g_key_file_get_string_list (keyfile, group, "audio_folders", NULL, NULL);
				if (list != NULL) {
					g_strfreev (priv->audio_folders);
					priv->audio_folders = list;
				}

				list = g_key_file_get_string_list (keyfile, group, "output_formats", NULL, NULL);
				if (list != NULL) {
					g_strfreev (priv->output_mime_types);
					priv->output_mime_types = list;
				}
				
				list = g_key_file_get_string_list (keyfile, group, "playlist_format", NULL, NULL);
				if (list != NULL) {
					set_playlist_formats (source, list);
					g_strfreev (list);
				}

				value = g_key_file_get_string (keyfile, group, "playlist_path", NULL);
				if (value != NULL) {
					set_playlist_path (source, value);
					g_free (value);
				}

				if (g_key_file_has_key (keyfile, group, "folder_depth", NULL)) {
					priv->folder_depth = g_key_file_get_integer (keyfile, group, "folder_depth", NULL);
				}
				g_free (group);
			}

			g_key_file_free (keyfile);
			g_free (munged);
			
			debug_device_info (source, mount, ".is_audio_player file");
		}
		g_free (data);

		g_object_unref (is_audio_player);
	} else {
		rb_debug ("no .is_audio_player file found on this device");
	}

	g_object_unref (mount);
}
Beispiel #20
0
gboolean
check_libhal (const char *server_addr)
{
	pid_t child_pid;

	child_pid = fork ();
	if (child_pid == -1) {
		printf ("Cannot fork\n");
		exit (1);
	} else if (child_pid == 0) {
		DBusError error;
		DBusConnection *conn;
		LibHalContext *ctx;
		dbus_bool_t passed;

		printf ("server address='%s'\n", server_addr);

		dbus_error_init (&error);
		if ((conn = dbus_connection_open (server_addr, &error)) == NULL) {
			printf ("Error connecting to server: %s\n", error.message);
			goto fail;
		}

		dbus_connection_setup_with_g_main (conn, NULL);

		if ((ctx = libhal_ctx_new ()) == NULL) {
			printf ("Error getting libhal context\n");
			goto fail;
		}

		
		libhal_ctx_set_dbus_connection (ctx, conn);

		libhal_ctx_init (ctx, &error);

		if (dbus_error_is_set (&error)) {
			printf ("FAILED98: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS98\n");

		libhal_device_print (ctx, "/org/freedesktop/Hal/devices/testobj1", &error);


		if (dbus_error_is_set (&error)) {
			printf ("FAILED99: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS99\n");

		passed = FALSE;

		{
			char *val;
			
			val = libhal_device_get_property_string (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.string", &error);

			if (val == NULL || strcmp (val, "fooooobar22") != 0 || dbus_error_is_set (&error)) {
				libhal_free_string (val);
				printf ("FAILED100\n");			
				goto fail;
			}
			printf ("SUCCESS100\n");
			libhal_free_string (val);
		}

		{
			char *val;
			val = libhal_device_get_property_string (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.string2", &error);
			if (val == NULL || strcmp (val, "fooøةמ") != 0 || dbus_error_is_set (&error)) {
				libhal_free_string (val);
				printf ("FAILED101: %s\n", error.message);			
				goto fail;
			}
			libhal_free_string (val);
			printf ("SUCCESS101\n");
		}

		{
			dbus_bool_t b;
			b = libhal_device_get_property_bool (
			    ctx, "/org/freedesktop/Hal/devices/testobj1", 
			    "test.bool", &error);
			    
			if (!b || dbus_error_is_set (&error)) {
				printf ("FAILED102: %s, %i\n", error.message, b);			
				goto fail;
			}
			printf ("SUCCESS102\n");
		}

		{
			double val;
			double expected_val = 0.53434343;

			val = libhal_device_get_property_double (ctx, "/org/freedesktop/Hal/devices/testobj1", 
								 "test.double", &error);
			if ( memcmp (&val, &expected_val, sizeof (double)) != 0 || dbus_error_is_set (&error)) {
				printf ("FAILED103\n");
				goto fail;
			}
			printf ("SUCCESS103\n");
		}

		if (libhal_device_get_property_uint64 (
			    ctx, "/org/freedesktop/Hal/devices/testobj1", "test.uint64", &error) != 
		    ((((dbus_uint64_t)1)<<35) + 5) ||
		    dbus_error_is_set (&error)) {
			printf ("FAILED104: %s\n", error.message);			
			goto fail;
		}
		printf ("SUCCESS104\n");
		
		{
			char **val;
			val = libhal_device_get_property_strlist (ctx, "/org/freedesktop/Hal/devices/testobj1", "test.strlist", &error);
			if (val == NULL ||  dbus_error_is_set (&error)) {
				libhal_free_string_array (val);
				printf ("FAILED105: %s\n", error.message);			
				goto fail;
			}
			printf ("SUCCESS105\n");
			
			if (libhal_string_array_length (val) != 2) {
				libhal_free_string_array (val);
				printf ("FAILED106\n");			
				goto fail;
			}
			printf ("SUCCESS106\n");

			if (strcmp (val[0], "foostrlist2") != 0 ||
			    strcmp (val[1], "foostrlist3") != 0) {
				libhal_free_string_array (val);
				printf ("FAILED107\n");			
				goto fail;
			}
			printf ("SUCCESS107\n");

			libhal_free_string_array (val);
		}

		if (libhal_device_get_property_int (
			    ctx, "/org/freedesktop/Hal/devices/testobj1", "test.int", &error) != 42 ||
		    dbus_error_is_set (&error)) {
			printf ("FAILED108\n");			
			goto fail;
		}
		printf ("SUCCESS108\n");
	
		/* tests for libhal_psi */
		{
			int type;
			char *key;
			LibHalPropertySet *pset;
			LibHalPropertySetIterator it;
			unsigned int psi_num_passed;
			unsigned int psi_num_elems;

			if ((pset = libhal_device_get_all_properties (ctx, "/org/freedesktop/Hal/devices/testobj1", 
								      &error)) == NULL)
				return FALSE;
			printf ("SUCCESS110\n");

			psi_num_passed = 0;
			psi_num_elems = libhal_property_set_get_num_elems (pset);

			for (libhal_psi_init (&it, pset); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
				type = libhal_psi_get_type (&it);
				key = libhal_psi_get_key (&it);

				switch (type) {
				case LIBHAL_PROPERTY_TYPE_STRING:
					if (strcmp (key, "info.udi") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "/org/freedesktop/Hal/devices/testobj1") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					} else if (strcmp (key, "test.string") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "fooooobar22") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					} else if (strcmp (key, "test.string2") == 0) {
						if (strcmp (libhal_psi_get_string (&it), 
							    "fooøةמ") == 0) {
							psi_num_passed++;
						} else {
							printf ("fail on %s\n", key);
						}
					}
					break;

				case LIBHAL_PROPERTY_TYPE_INT32:
					if (strcmp (key, "test.int") == 0) {
						if (libhal_psi_get_int (&it) == 42)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_UINT64:
					if (strcmp (key, "test.uint64") == 0) {
						if (libhal_psi_get_uint64 (&it) == ((((dbus_uint64_t)1)<<35) + 5))
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_BOOLEAN:
					if (strcmp (key, "test.bool") == 0) {
						if (libhal_psi_get_bool (&it) == TRUE)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_DOUBLE:
					if (strcmp (key, "test.double") == 0) {
						double val = 0.53434343;
						double val2;

						val2 = libhal_psi_get_double (&it);
						if (memcmp (&val, &val2, sizeof (double)) == 0)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				case LIBHAL_PROPERTY_TYPE_STRLIST:
					if (strcmp (key, "test.strlist") == 0) {
						char **val;
					
						val = libhal_psi_get_strlist (&it);
						if (libhal_string_array_length (val) == 2 &&
						    strcmp (val[0], "foostrlist2") == 0 &&
						    strcmp (val[1], "foostrlist3") == 0 &&
						    val[2] == NULL)
							psi_num_passed++;
						else
							printf ("fail on %s\n", key);
					}
					break;

				default:
					printf ("    *** unknown type for key %s\n", key);
					break;
				}
			}
			libhal_free_property_set (pset);

			if (psi_num_passed != psi_num_elems) {
				printf ("FAILED111\n");			
				goto fail;
			}
			printf ("SUCCESS111\n");			


		} /* end libhal_test_psi */

	
		printf ("Passed all libhal tests\n");
		passed = TRUE;
		
	fail:
		if (dbus_error_is_set (&error))
			dbus_error_free (&error);
			
		send_tests_done (conn, passed);
		exit (1);

	} else {
		printf ("child pid=%d\n", child_pid);
	}
	return TRUE;
}
Beispiel #21
0
char *
battstat_hal_initialise (void (*callback) (void))
{
  DBusConnection *connection;
  LibHalContext *ctx;
  DBusError error;
  char *error_str;
  char **devices;
  int i, num;

  status_updated_callback = callback;

  if( battstat_hal_ctx != NULL )
    return g_strdup( "Already initialised!" );

  dbus_error_init( &error );

  if( (connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error )) == NULL )
    goto error_out;

  dbus_connection_setup_with_g_main( connection, g_main_context_default() );

  if( (ctx = libhal_ctx_new()) == NULL )
  {
    dbus_set_error( &error, _("HAL error"), _("Could not create libhal_ctx") );
    goto error_out;
  }

  libhal_ctx_set_device_property_modified( ctx, property_callback );
  libhal_ctx_set_device_added( ctx, device_added_callback );
  libhal_ctx_set_device_removed( ctx, device_removed_callback );
  libhal_ctx_set_dbus_connection( ctx, connection );

  if( libhal_ctx_init( ctx, &error ) == 0 )
    goto error_freectx;
  
  devices = libhal_find_device_by_capability( ctx, "battery", &num, &error );

  if( devices == NULL )
    goto error_shutdownctx;

  /* FIXME: for now, if 0 battery devices are present on first scan, then fail.
   * This allows fallover to the legacy (ACPI, APM, etc) backends if the
   * installed version of HAL doesn't know about batteries.  This check should
   * be removed at some point in the future (maybe circa MATE 2.13..).
   */
  if( num == 0 )
  {
    dbus_free_string_array( devices );
    dbus_set_error( &error, _("HAL error"), _("No batteries found") );
    goto error_shutdownctx;
  }

  for( i = 0; i < num; i++ )
  {
    char *type = libhal_device_get_property_string( ctx, devices[i],
                                                    "battery.type",
                                                    &error );

    if( type )
    {
      /* We only track 'primary' batteries (ie: to avoid monitoring
       * batteries in cordless mice or UPSes etc.)
       */
      if( !strcmp( type, "primary" ) )
        add_to_list( ctx, &batteries, devices[i],
                     sizeof (struct battery_info) );

      libhal_free_string( type );
    }
  }
  dbus_free_string_array( devices );

  devices = libhal_find_device_by_capability( ctx, "ac_adapter", &num, &error );

  if( devices == NULL )
  {
    batteries = free_entire_list( batteries );
    goto error_shutdownctx;
  }

  for( i = 0; i < num; i++ )
    add_to_list( ctx, &adaptors, devices[i], sizeof (struct adaptor_info) );
  dbus_free_string_array( devices );

  dbus_error_free( &error );

  battstat_hal_ctx = ctx;

  return NULL;

error_shutdownctx:
  libhal_ctx_shutdown( ctx, NULL );

error_freectx:
  libhal_ctx_free( ctx );

error_out:
  error_str = g_strdup_printf( _("Unable to initialise HAL: %s: %s"),
                               error.name, error.message );
  dbus_error_free( &error );
  return error_str;
}
static void
thunar_vfs_volume_hal_update (ThunarVfsVolumeHal *volume_hal,
                              LibHalContext      *context,
                              LibHalVolume       *hv,
                              LibHalDrive        *hd)
{
  gchar *desired_mount_point;
  gchar *mount_root;
  gchar *basename;
  gchar *filename;

  _thunar_vfs_return_if_fail (THUNAR_VFS_IS_VOLUME_HAL (volume_hal));
  _thunar_vfs_return_if_fail (hd != NULL);

  /* reset the volume status */
  volume_hal->status = 0;

  /* determine the new device file */
  g_free (volume_hal->device_file);
  volume_hal->device_file = g_strdup ((hv != NULL) ? libhal_volume_get_device_file (hv) : libhal_drive_get_device_file (hd));

  /* compute a usable display name for the volume/drive */
  g_free (volume_hal->device_label);
  volume_hal->device_label = (hv == NULL)
    ? exo_hal_drive_compute_display_name (context, hd)
    : exo_hal_volume_compute_display_name (context, hv, hd);
  if (G_UNLIKELY (volume_hal->device_label == NULL))
    {
      /* use the basename of the device file as label */
      volume_hal->device_label = g_path_get_basename (volume_hal->device_file);
    }

  /* compute a usable list of icon names for the volume/drive */
  g_list_foreach (volume_hal->icon_list, (GFunc) g_free, NULL);
  g_list_free (volume_hal->icon_list);
  volume_hal->icon_list = (hv == NULL)
    ? exo_hal_drive_compute_icon_list (context, hd)
    : exo_hal_volume_compute_icon_list (context, hv, hd);

  /* release the previous mount point (if any) */
  if (G_LIKELY (volume_hal->mount_point != NULL))
    {
      thunar_vfs_path_unref (volume_hal->mount_point);
      volume_hal->mount_point = NULL;
    }

  /* determine the type of the volume */
  switch (libhal_drive_get_type (hd))
    {
    case LIBHAL_DRIVE_TYPE_CDROM:
      /* check if we have a pure audio CD without any data track */
      if (libhal_volume_disc_has_audio (hv) && !libhal_volume_disc_has_data (hv))
        {
          /* special treatment for pure audio CDs */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_CD;
        }
      else
        {
          /* check which kind of CD-ROM/DVD we have */
          switch (libhal_volume_get_disc_type (hv))
            {
            case LIBHAL_VOLUME_DISC_TYPE_CDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRAM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRAM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSRW;
              break;

            default:
              /* unsupported disc type */
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_UNKNOWN;
              break;
            }
        }
      break;

    case LIBHAL_DRIVE_TYPE_FLOPPY:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_FLOPPY;
      break;

    case LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_PLAYER;
      break;

    case LIBHAL_DRIVE_TYPE_SMART_MEDIA:
    case LIBHAL_DRIVE_TYPE_SD_MMC:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_MEMORY_CARD;
      break;

    default:
      /* check if the drive is connected to the USB bus */
      if (libhal_drive_get_bus (hd) == LIBHAL_DRIVE_BUS_USB)
        {
          /* we consider the drive to be an USB stick */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_USBSTICK;
        }
      else if (libhal_drive_uses_removable_media (hd)
            || libhal_drive_is_hotpluggable (hd))
        {
          /* fallback to generic removable disk */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_REMOVABLE_DISK;
        }
      else
        {
          /* fallback to harddisk drive */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_HARDDISK;
        }
      break;
    }

  /* either we have a volume, which means we have media, or
   * a drive, which means non-pollable then, so it's present
   */
  volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_PRESENT;
  
  /* figure out if the volume is mountable */
  if(hv != NULL && libhal_volume_get_fsusage (hv) == LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
    volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTABLE;

  /* check if the drive requires eject */
  volume_hal->requires_eject = libhal_drive_requires_eject (hd);

  /* check if the volume is currently mounted */
  if (hv != NULL && libhal_volume_is_mounted (hv))
    {
      /* try to determine the new mount point */
      volume_hal->mount_point = thunar_vfs_path_new (libhal_volume_get_mount_point (hv), NULL);

      /* we only mark the volume as mounted if we have a valid mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }
  else
    {
      /* we don't trust HAL, so let's see what the kernel says about the volume */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);

      /* we must have been mounted successfully if we have a mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }

  /* check if we have to figure out the mount point ourself */
  if (G_UNLIKELY (volume_hal->mount_point == NULL))
    {
      /* ask HAL for the default mount root (falling back to /media otherwise) */
      mount_root = libhal_device_get_property_string (context, "/org/freedesktop/Hal/devices/computer", "storage.policy.default.mount_root", NULL);
      if (G_UNLIKELY (mount_root == NULL || !g_path_is_absolute (mount_root)))
        {
          /* fallback to /media (seems to be sane) */
          g_free (mount_root);
          mount_root = g_strdup ("/media");
        }

      /* lets see, maybe /etc/fstab knows where to mount */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_fstab_mount_point (volume_hal);

      /* if we still don't have a mount point, ask HAL */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* determine the desired mount point and prepend the mount root */
          desired_mount_point = libhal_device_get_property_string (context, volume_hal->udi, "volume.policy.desired_mount_point", NULL);
          if (G_LIKELY (desired_mount_point != NULL && *desired_mount_point != '\0'))
            {
              filename = g_build_filename (mount_root, desired_mount_point, NULL);
              volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
              g_free (filename);
            }
          libhal_free_string (desired_mount_point);
        }

      /* ok, last fallback, just use <mount-root>/<device> */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* <mount-root>/<device> looks like a good idea */
          basename = g_path_get_basename (volume_hal->device_file);
          filename = g_build_filename (mount_root, basename, NULL);
          volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
          g_free (filename);
          g_free (basename);
        }

      /* release the mount root */
      g_free (mount_root);
    }

  /* if we get here, we must have a valid mount point */
  g_assert (volume_hal->mount_point != NULL);

  /* emit the "changed" signal */
  thunar_vfs_volume_changed (THUNAR_VFS_VOLUME (volume_hal));
}
gboolean
rb_generic_player_is_mount_player (GMount *mount)
{
	gboolean result = FALSE;
#ifdef HAVE_HAL
	LibHalContext *ctx;

	ctx = get_hal_context ();
	if (ctx != NULL) {
		char *udi = get_hal_udi_for_player (ctx, mount);
		if (udi != NULL) {
			DBusError error;
			char **proplist;
			char *prop;

			rb_debug ("Checking udi %s", udi);
			/* check that it can be accessed as mass-storage */
			dbus_error_init (&error);
			proplist = libhal_device_get_property_strlist (ctx, udi, "portable_audio_player.access_method.protocols", &error);
			if (proplist != NULL && !dbus_error_is_set (&error)) {
				int i;
				for (i = 0; proplist[i] != NULL; i++) {
					rb_debug ("device access method: %s", proplist[i]);
					if (strcmp (proplist[i], "storage") == 0) {
						result = TRUE;
						break;
					}
				}

				libhal_free_string_array (proplist);
			}
			free_dbus_error ("checking device access method", &error);

			if (result == FALSE) {
				dbus_error_init (&error);
				prop = libhal_device_get_property_string (ctx, udi, "portable_audio_player.access_method", &error);
				if (prop != NULL && strcmp (prop, "storage") == 0 && !dbus_error_is_set (&error)) {
					/* the device has passed all tests, so it should be a usable player */
					result = TRUE;
				}

				libhal_free_string (prop);
				free_dbus_error ("checking device access method", &error);
			}

			if (result == FALSE) {
				rb_debug ("device cannot be accessed via storage");
			}

		} else {
			rb_debug ("device is not an audio player");
		}
		g_free (udi);
	}
	cleanup_hal_context (ctx);

#endif /* HAVE_HAL */

	/* treat as audio player if ".is_audio_player" exists in the root of the volume  */
	if (!result) {
		GFile *is_audio_player;
		is_audio_player = get_is_audio_player_file (mount);
		if (is_audio_player != NULL) {
			result = TRUE;
			g_object_unref (is_audio_player);
		}
	}

	return result;
}
Beispiel #24
0
/* Parse newly found device and add it to our remembered devices */
void CHALManager::AddDevice(const char *udi)
{
  CSingleLock lock(m_lock);
  char *category;
  category = libhal_device_get_property_string(m_Context, udi, "info.category", NULL);
  if (category == NULL)
    return;

  if (strcmp(category, "volume") == 0)
  {
    CStorageDevice dev(udi);
    if (DeviceFromVolumeUdi(udi, &dev))
    {
      CLog::Log(LOGDEBUG, "HAL: Added - %s | %s", CHALManager::StorageTypeToString(dev.Type),  dev.toString().c_str());
      HandleNewVolume(&dev);
      m_Volumes.push_back(dev);
    }
  }
#if defined(HAS_SDL_JOYSTICK)
  // Scan input devices
  else if (strcmp(category, "input") == 0)
  {
    DBusError dbusError;
    dbus_error_init(&dbusError);

    char **capability;
    capability =libhal_device_get_property_strlist (m_Context, udi, "info.capabilities", &dbusError);
    for(char **ptr = capability; *ptr != NULL;ptr++)
    {
      // Reload joysticks
      if(strcmp(*ptr, "input.joystick") == 0)
      {
        CLog::Log(LOGINFO, "HAL: Joystick plugged in");
        CHALDevice dev = CHALDevice(udi);
        dev.FriendlyName = libhal_device_get_property_string(m_Context, udi, "info.product", &m_Error);
        m_Joysticks.push_back(dev);

        if(m_Joysticks.size() < 2 || m_bMultipleJoysticksSupport)
        {
          // Restart SDL joystick subsystem
          if (!g_Joystick.Reinitialize())
            break;

          if (m_Notifications)
            CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(13024), dev.FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
        }
      }
    }
    libhal_free_string_array(capability);
  }
#endif
/*
  else if (strcmp(category, "camera") == 0)
  { // PTP-Devices }
  else if (strcmp(category, "bluetooth_hci") == 0)
  { // Bluetooth-Devices }
  else if (strcmp(category, "portable audio player") == 0)
  { // MTP-Devices }
  else if (strcmp(category, "alsa") == 0)
  { //Alsa Devices }
*/

  libhal_free_string(category);
}
Beispiel #25
0
static int rsct_usbdev_scan_nonserial(char **devices, int i_devices,
				      rsct_usbdev_t **usbdev_list) {
  int i;

  for (i=0; i<i_devices; i++) {
    const char *udi=devices[i];

    if (libhal_device_exists(global_hal_context->ctx, udi, &(global_hal_context->dbus_error))) {
      char *busType;

      busType=libhal_device_get_property_string(global_hal_context->ctx, udi, "info.subsystem", NULL);
      if (busType && (strcasecmp(busType, "usb")!=0)) {
	libhal_free_string(busType);
	busType=NULL; /* non-USB devices are handled below */
      }

      if (busType==NULL)
	busType=libhal_device_get_property_string(global_hal_context->ctx, udi, "info.bus", NULL);
      if (busType) {
	if (strcasecmp(busType, "usb")==0) {
	  /* USB device, look for LibUSB info */
	  if (libhal_device_property_exists(global_hal_context->ctx, udi, "usb.bus_number", NULL) &&
	      libhal_device_property_exists(global_hal_context->ctx, udi, "usb.linux.device_number", NULL)){
	    int busId;
	    int busPos;
	    int vendorId;
	    int productId;
	    char pbuff[256];
	    struct stat st;
	    int havePath=0;

	    busId=libhal_device_get_property_int(global_hal_context->ctx,
						 udi,
						 "usb.bus_number",
						 NULL);
	    busPos=libhal_device_get_property_int(global_hal_context->ctx,
						  udi,
						  "usb.linux.device_number",
						  NULL);
	    vendorId=libhal_device_get_property_int(global_hal_context->ctx,
						    udi,
						    "usb.vendor_id",
						    NULL);
	    productId=libhal_device_get_property_int(global_hal_context->ctx,
						     udi,
						     "usb.product_id",
						     NULL);

	    if (vendorId==0xc4b && rsct_usbdev_list_findByBus(*usbdev_list, busId, busPos)==NULL) {
	      rsct_usbdev_t *d;
	      char *serial=NULL;
	      char *productName=NULL;

	      d=rsct_usbdev_new();

	      d->busId=busId;
	      d->busPos=busPos;
	      d->vendorId=vendorId;
	      d->productId=productId;

	      snprintf(d->halPath, sizeof(d->halPath)-1,
		       "usb:%04x/%04x:libhal:%s",
		       d->vendorId,
		       d->productId,
		       udi);
	      d->halPath[sizeof(d->halPath)-1]=0;

	      /* set HAL UDI */
	      strncpy(d->halUDI, udi, sizeof(d->halUDI)-1);
	      d->halUDI[sizeof(d->halUDI)-1]=0;

	      /* determine path for LibUSB */
	      snprintf(pbuff, sizeof(pbuff)-1,
		       "/dev/bus/usb/%03d/%03d",
		       busId, busPos);
	      pbuff[sizeof(pbuff)-1]=0;
	      if (stat(pbuff, &st)==0) {
		havePath=1;
	      }
	      else {
		snprintf(pbuff, sizeof(pbuff)-1,
			 "/proc/bus/usb/%03d/%03d",
			 busId, busPos);
		pbuff[sizeof(pbuff)-1]=0;
		if (stat(pbuff, &st)==0) {
		  havePath=1;
		}
	      }

	      if (havePath) {
		strncpy(d->usbPath, pbuff, sizeof(d->usbPath)-1);
		d->usbPath[sizeof(d->usbPath)-1]=0;

		strncpy(d->deviceNodePath, pbuff, sizeof(d->deviceNodePath)-1);
		d->deviceNodePath[sizeof(d->deviceNodePath)-1]=0;
	      }

	      /* generate path for CTAPI/IFD */
	      snprintf(d->path, sizeof(d->path)-1,
		       "usb:%04x/%04x:libusb:%03d:%03d",
		       d->vendorId,
		       d->productId,
		       d->busId,
		       d->busPos);

	      serial=libhal_device_get_property_string(global_hal_context->ctx,
						       udi,
						       "usb.serial",
						       NULL);
	      if (serial) {
		strncpy(d->serial, serial, sizeof(d->serial)-1);
		d->serial[sizeof(d->serial)-1]=0;
		libhal_free_string(serial);
	      }

	      /* get product name from parent.
	       * Please note: This udi refers to the *_ifX HAL device, and it's product name
	       * is the product name of the interface ("USB Vendor Specific Interface") rather than
	       * that of the device itself.
	       * Therefore we must access the parent in order to find the product name of the device.
	       */
	      if (1) {
		char *parent_udi;

		/* ttyUSB device, get USB info from parent */
		parent_udi=libhal_device_get_property_string(global_hal_context->ctx,
							     udi,
							     "info.parent",
							     NULL);
		if (parent_udi) {
		  productName=libhal_device_get_property_string(global_hal_context->ctx,
								parent_udi,
								"usb_device.product",
								NULL);
		  libhal_free_string(parent_udi);
		}
	      }

	      if (productName) {
		strncpy(d->productName, productName, sizeof(d->productName)-1);
		d->productName[sizeof(d->productName)-1]=0;
		libhal_free_string(productName);
	      }

	      /* all set, add device */
	      rsct_usbdev_list_add(usbdev_list, d);
	    }
	  }
	} /* if USB */
	libhal_free_string(busType);
      } /* if bus type */
    } /* if device exists */
  } /* for */

  return 0;
}
Beispiel #26
0
/*
 * gst_hal_get_oss_element:
 * @ctx: a #LibHalContext which should be used for querying HAL.
 * @udi: a #gchar corresponding to the UDI you want to get.
 * @device_type: a #GstHalDeviceType specifying the wanted device type.
 *
 * Get Hal UDI @udi's string value.
 *
 * Returns: a newly allocated #gchar string containing the appropriate pipeline
 * for UDI @udi, or NULL in the case of an error..
 */
static gchar *
gst_hal_get_oss_element (LibHalContext * ctx, const gchar * udi,
    GstHalDeviceType device_type)
{
  char *type, *element = NULL, *string = NULL;
  DBusError error;

  dbus_error_init (&error);

  if (!libhal_device_query_capability (ctx, udi, "oss", &error)) {
    if (dbus_error_is_set (&error)) {
      GST_DEBUG ("Failed querying %s for oss capability: %s: %s", udi,
          error.name, error.message);
      LIBHAL_FREE_DBUS_ERROR (&error);
    } else {
      GST_DEBUG ("UDI %s has no oss capability", udi);
    }
    return NULL;
  }

  type = libhal_device_get_property_string (ctx, udi, "oss.type", &error);
  if (dbus_error_is_set (&error)) {
    GST_DEBUG ("UDI %s has oss capabilities but no oss.type property: %s, %s",
        udi, error.name, error.message);
    LIBHAL_FREE_DBUS_ERROR (&error);
    return NULL;
  } else if (!type) {
    GST_DEBUG ("UDI %s has empty oss.type property", udi);
    return NULL;
  }

  if (strcmp (type, "pcm") == 0) {
    if (device_type == GST_HAL_AUDIOSINK)
      element = "osssink";
    else if (device_type == GST_HAL_AUDIOSRC)
      element = "osssrc";
  }
  libhal_free_string (type);

  if (element) {
    char *device = NULL;

    device =
        libhal_device_get_property_string (ctx, udi, "oss.device_file", &error);
    if (dbus_error_is_set (&error)) {
      GST_DEBUG
          ("UDI %s has oss capabilities but no oss.device_file property: %s, %s",
          udi, error.name, error.message);
      LIBHAL_FREE_DBUS_ERROR (&error);
      return NULL;
    } else if (!device) {
      GST_DEBUG ("UDI %s has empty oss.device_file property", udi);
      return NULL;
    }

    string = g_strdup_printf ("%s device=%s", element, device);
    libhal_free_string (device);
  }

  return string;
}
Beispiel #27
0
/** Entry point
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 *  @return                     Return code
 */
int
main (int argc, char *argv[])
{
	char *udi = NULL;
	char *key = NULL;
	int type;
	dbus_bool_t is_hex = FALSE;
	dbus_bool_t is_verbose = FALSE;
	dbus_bool_t is_version = FALSE;
	char *str;
	DBusError error;

	if (argc <= 1) {
		usage (argc, argv);
		return 1;
	}

	while (1) {
		int c;
		int option_index = 0;
		const char *opt;
		static struct option long_options[] = {
			{"udi", 1, NULL, 0},
			{"key", 1, NULL, 0},
			{"hex", 0, NULL, 0},
			{"verbose", 0, NULL, 0},
			{"version", 0, NULL, 0},
			{"help", 0, NULL, 0},
			{NULL, 0, NULL, 0}
		};

		c = getopt_long (argc, argv, "",
				 long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
		case 0:
			opt = long_options[option_index].name;

			if (strcmp (opt, "help") == 0) {
				usage (argc, argv);
				return 0;
			} else if (strcmp (opt, "hex") == 0) {
				is_hex = TRUE;
			} else if (strcmp (opt, "verbose") == 0) {
				is_verbose = TRUE;
			} else if (strcmp (opt, "version") == 0) {
				is_version = TRUE;
			} else if (strcmp (opt, "key") == 0) {
				key = strdup (optarg);
			} else if (strcmp (opt, "udi") == 0) {
				udi = strdup (optarg);
			}
			break;

		default:
			usage (argc, argv);
			return 1;
			break;
		}
	}

	if (is_version) {
		printf ("hal-get-property " PACKAGE_VERSION "\n");
		return 0;
	}

	if (udi == NULL || key == NULL) {
		usage (argc, argv);
		return 1;
	}

	dbus_error_init (&error);	
	if ((hal_ctx = libhal_ctx_new ()) == NULL) {
		fprintf (stderr, "error: libhal_ctx_new\n");
		return 1;
	}
	if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
		fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
		LIBHAL_FREE_DBUS_ERROR (&error);
		return 1;
	}
	if (!libhal_ctx_init (hal_ctx, &error)) {
		if (dbus_error_is_set(&error)) {
			fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
			LIBHAL_FREE_DBUS_ERROR (&error);
		}
		fprintf (stderr, "Could not initialise connection to hald.\n"
				 "Normally this means the HAL daemon (hald) is not running or not ready.\n");
		return 1;
	}

	type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
	if (type == LIBHAL_PROPERTY_TYPE_INVALID) {
		fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message);
		LIBHAL_FREE_DBUS_ERROR (&error);
		return 1;
	}
	/* emit the value to stdout */
	switch (type) {
	case LIBHAL_PROPERTY_TYPE_STRING:
		str = libhal_device_get_property_string (hal_ctx, udi, key, &error);
		if (is_verbose)
			printf ("Type is string\n");
		printf ("%s\n", str);
		libhal_free_string (str);
		break;
	case LIBHAL_PROPERTY_TYPE_INT32:
		if (is_verbose)
			printf ("Type is integer (shown in %s)\n",
				(is_hex ? "hexadecimal" : "decimal"));
		printf ((is_hex ? "%x\n" : "%d\n"),
			libhal_device_get_property_int (hal_ctx, udi, key, &error));
		break;
	case LIBHAL_PROPERTY_TYPE_UINT64:
		if (is_verbose)
			printf ("Type is uint64 (shown in %s)\n",
				(is_hex ? "hexadecimal" : "decimal"));
		printf ((is_hex ? "%llx\n" : "%llu\n"),
			(long long unsigned int) libhal_device_get_property_uint64 (hal_ctx, udi, key, &error));
		break;
	case LIBHAL_PROPERTY_TYPE_DOUBLE:
		if (is_verbose)
			printf ("Type is double\n");
		printf ("%f\n",
			libhal_device_get_property_double (hal_ctx, udi, key, &error));
		break;
	case LIBHAL_PROPERTY_TYPE_BOOLEAN:
		if (is_verbose)
			printf ("Type is boolean\n");
		printf ("%s\n",
			libhal_device_get_property_bool (hal_ctx, udi, key, &error) ? "true" : "false");
		break;

	case LIBHAL_PROPERTY_TYPE_STRLIST:
	{
		unsigned int i;
		char **strlist;
		
		if ((strlist = libhal_device_get_property_strlist (hal_ctx, udi, key, &error)) != NULL) {
			
			for (i = 0; strlist[i] != 0; i++) {
				printf ("%s", strlist[i]);
				if (strlist[i+1] != NULL)
					printf (" ");
			}
		} 
		break;
	}
	default:
		printf ("Unknown type %d='%c'\n", type, type);
		return 1;
		break;
	}

	if (dbus_error_is_set (&error)) {
		fprintf (stderr, "error: %s: %s\n", error.name, error.message);
		dbus_error_free (&error);
		return 1;
	}


	return 0;
}
Beispiel #28
0
/*
 * gst_hal_get_alsa_element:
 * @ctx: a #LibHalContext which should be used for querying HAL.
 * @udi: a #gchar corresponding to the UDI you want to get.
 * @device_type: a #GstHalDeviceType specifying the wanted device type.
 *
 * Get Hal UDI @udi's string value.
 *
 * Returns: a newly allocated #gchar string containing the appropriate pipeline
 * for UDI @udi, or NULL in the case of an error..
 */
static gchar *
gst_hal_get_alsa_element (LibHalContext * ctx, const gchar * udi,
    GstHalDeviceType device_type)
{
  char *type, *element = NULL, *string = NULL;
  DBusError error;

  dbus_error_init (&error);

  if (!libhal_device_query_capability (ctx, udi, "alsa", &error)) {
    if (dbus_error_is_set (&error)) {
      GST_DEBUG ("Failed querying %s for alsa capability: %s: %s",
          udi, error.name, error.message);
      LIBHAL_FREE_DBUS_ERROR (&error);
    } else {
      GST_DEBUG ("UDI %s has no alsa capability", udi);
    }
    return NULL;
  }

  type = libhal_device_get_property_string (ctx, udi, "alsa.type", &error);

  if (dbus_error_is_set (&error)) {
    GST_DEBUG ("UDI %s has alsa capabilities but no alsa.type property: %s, %s",
        udi, error.name, error.message);
    LIBHAL_FREE_DBUS_ERROR (&error);
    return NULL;
  } else if (!type) {
    GST_DEBUG ("UDI %s has empty alsa.type property", udi);
    return NULL;
  }

  if (strcmp (type, "playback") == 0 && device_type == GST_HAL_AUDIOSINK)
    element = "alsasink";
  else if (strcmp (type, "capture") == 0 && device_type == GST_HAL_AUDIOSRC)
    element = "alsasrc";

  libhal_free_string (type);

  if (element) {
    int card, device;

    card = libhal_device_get_property_int (ctx, udi, "alsa.card", &error);
    if (dbus_error_is_set (&error)) {
      GST_DEBUG ("UDI %s has no alsa.card property: %s: %s", udi, error.name,
          error.message);
      LIBHAL_FREE_DBUS_ERROR (&error);
      return NULL;
    } else if (card == -1) {
      GST_DEBUG ("UDI %s has no alsa.card property", udi);
      return NULL;
    }

    device = libhal_device_get_property_int (ctx, udi, "alsa.device", &error);
    if (dbus_error_is_set (&error)) {
      GST_DEBUG ("UDI %s has no alsa.device property: %s: %s", udi, error.name,
          error.message);
      LIBHAL_FREE_DBUS_ERROR (&error);
      return NULL;
    } else if (device == -1) {
      GST_DEBUG ("UDI %s has no alsa.device property", udi);
      return NULL;
    }

    /* This is a bit dodgy, since it makes lots of assumptions about the way
     * alsa is set up. In any case, only munge the device string for playback */
    if (strcmp (element, "alsasink") == 0 && device == 0) {
      /* handle default device specially to use
       * dmix, dsnoop, and softvol if appropriate */
      string = g_strdup_printf ("%s device=default:%d", element, card);
    } else {
      string =
          g_strdup_printf ("%s device=plughw:%d,%d", element, card, device);
    }
  }

  return string;
}
Beispiel #29
0
static int
hal_device_is_pda (LibHalContext *ctx, const char *udi, gchar **ret_ifname)
{
  int result = 0;

  DBusError error;
  dbus_error_init (&error);

  /* Be sure it is a network interface */
  gchar *ifname = libhal_device_get_property_string (ctx, udi, "net.interface",
      &error);
  if (ifname == NULL) goto DONE;
  if (ret_ifname != NULL) *ret_ifname = g_strdup(ifname);
  libhal_free_string (ifname);

  /* We'll then check some properties of its parent */
  gchar *parentname = libhal_device_get_property_string (ctx, udi,
      "info.parent", &error);
  if (parentname == NULL) goto DONE;

  /* Check the parent's device driver name (for usb-rndis-lite) */
  gchar *drvname = libhal_device_get_property_string (ctx, parentname,
      "info.linux.driver", &error);
  if (drvname != NULL)
    {
      if (strncmp ("rndis_host", drvname, 11) == 0) result = 1;
      libhal_free_string (drvname);
    }
  else
    {
      g_debug("%s: drvname not set", G_STRFUNC);
      if (dbus_error_is_set(&error))
	{
	  g_warning ("%s: failed with D-Bus error %s: %s\n", G_STRFUNC, error.name, error.message);
	  dbus_error_free(&error);
	}
    }

  /* Check pda.platform property (for usb-rndis-ng) */
  gchar *pdaplatform = libhal_device_get_property_string (ctx, parentname,
      "pda.platform", &error);
  if (pdaplatform != NULL)
    {
      if (strncmp ("pocketpc", pdaplatform, 8) == 0) result = 1;
      libhal_free_string (pdaplatform);
    }
  else
    {
      g_debug("%s: pdaplatform not set", G_STRFUNC);
      if (dbus_error_is_set(&error))
	{
	  g_warning ("%s: failed with D-Bus error %s: %s\n", G_STRFUNC, error.name, error.message);
	  dbus_error_free(&error);
	}
    }

  libhal_free_string (parentname);

DONE:
  if (dbus_error_is_set(&error))
    dbus_error_free (&error);
  /*g_debug ("%s: udi='%s', result=%d", G_STRFUNC, udi, result);*/
  return result;
}