コード例 #1
0
ファイル: devicemanager.cpp プロジェクト: jboucquey/DSLogic
list<sr_dev_inst*> DeviceManager::driver_scan(
	struct sr_dev_driver *const driver, GSList *const drvopts)
{
	list<sr_dev_inst*> driver_devices;

	assert(driver);

	// Remove any device instances from this driver from the device
	// list. They will not be valid after the scan.
	list<sr_dev_inst*>::iterator i = _devices.begin();
	while (i != _devices.end()) {
		if ((*i)->driver == driver)
			i = _devices.erase(i);
		else
			i++;
	}

	// Release this driver and all it's attached devices
	release_driver(driver);

	// Do the scan
	GSList *const devices = sr_driver_scan(driver, drvopts);
	for (GSList *l = devices; l; l = l->next)
		driver_devices.push_back((sr_dev_inst*)l->data);
	g_slist_free(devices);
	driver_devices.sort(compare_devices);

	// Add the scanned devices to the main list
	_devices.insert(_devices.end(), driver_devices.begin(),
		driver_devices.end());
	_devices.sort(compare_devices);

	return driver_devices;
}
コード例 #2
0
ファイル: device.c プロジェクト: JenSte/sigrok-cli
GSList *device_scan(void)
{
	struct sr_dev_driver **drivers, *driver;
	GHashTable *drvargs;
	GSList *drvopts, *devices, *tmpdevs, *l;
	int i;
	char *drvname;

	if (opt_drv) {
		drvargs = parse_generic_arg(opt_drv, TRUE);
		drvname = g_strdup(g_hash_table_lookup(drvargs, "sigrok_key"));
		g_hash_table_remove(drvargs, "sigrok_key");
		driver = NULL;
		drivers = sr_driver_list();
		for (i = 0; drivers[i]; i++) {
			if (strcmp(drivers[i]->name, drvname))
				continue;
			driver = drivers[i];
		}
		if (!driver) {
			g_critical("Driver %s not found.", drvname);
			g_hash_table_destroy(drvargs);
			g_free(drvname);
			return NULL;
		}
		g_free(drvname);
		if (sr_driver_init(sr_ctx, driver) != SR_OK) {
			g_critical("Failed to initialize driver.");
			g_hash_table_destroy(drvargs);
			return NULL;
		}
		drvopts = NULL;
		if (g_hash_table_size(drvargs) > 0) {
			if (!(drvopts = hash_to_hwopt(drvargs))) {
				/* Unknown options, already logged. */
				g_hash_table_destroy(drvargs);
				return NULL;
			}
		}
		g_hash_table_destroy(drvargs);
		devices = sr_driver_scan(driver, drvopts);
		g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
	} else {
		/* No driver specified, let them all scan on their own. */
		devices = NULL;
		drivers = sr_driver_list();
		for (i = 0; drivers[i]; i++) {
			driver = drivers[i];
			if (sr_driver_init(sr_ctx, driver) != SR_OK) {
				g_critical("Failed to initialize driver.");
				return NULL;
			}
			tmpdevs = sr_driver_scan(driver, NULL);
			for (l = tmpdevs; l; l = l->next)
				devices = g_slist_append(devices, l->data);
			g_slist_free(tmpdevs);
		}
	}

	return devices;
}