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; }
void __connman_agent_cleanup(void) { DBG(""); if (!connection) return; g_hash_table_destroy(agent_hash); release_driver(); dbus_connection_unref(connection); connection = NULL; }
void update(void* instance) { InstancePtr inst = (InstancePtr) instance; MyInstancePtr my = inst->my; int device = trim_int(inst->in_device->number, 0, 256); const char* driver_name = inst->in_driver->text; try { if (my->driver_name == 0 || my->drv == 0 || strcmp(driver_name, my->driver_name) != 0) { delete[] my->driver_name; my->driver_name = strcopy(driver_name); if (my->drv != 0) release_driver(my->drv, my->driver_name, my->device); my->drv = get_driver(my->driver_name, my->device); } assert(my->drv != 0); if (device != my->device || !my->drv->is_open()) { my->device = device; if (my->drv->is_open()) my->drv->close(); assert(!my->drv->is_open()); try { my->drv->open(device); } catch (std::exception& e) { char buf[128]; snprintf(buf, sizeof(buf), "Error while opening: %s", e.what()); s_log(0, buf); throw; } assert(my->drv->is_open()); } assert(my->drv->is_open()); try { static const int MAX_MSG_LEN = 1024; unsigned char buffer[MAX_MSG_LEN]; int len = my->drv->read(buffer, sizeof(buffer)); midi_set_buffer(inst->out_r, buffer, len); } catch (std::exception& e) { char buf[128]; snprintf(buf, sizeof(buf), "Error while reading: %s", e.what()); s_log(0, buf); throw; } } catch (std::exception& e) { midi_set_buffer(inst->out_r, 0, 0); } }