KPCMCIA::KPCMCIA(int maxSlots, const char *stabpath) : _maxSlots(maxSlots), _stabPath(stabpath) { _refreshSpeed = 750; _haveCardServices = false; _timer = new TQTimer(this); connect(_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateCardInfo())); _cards = new TQMemArray<KPCMCIACard *>(_maxSlots+1); _cardCnt = 0; /////////////////////////////////////////////////// // LINUX code /////////////////////////////////////////////////// #ifdef __linux__ servinfo_t serv; int device = lookupDevice("pcmcia"); if (device >= 0) { for (int z = 0; z < _maxSlots; z++) { int fd = openDevice((device << 8) + z); if (fd < 0) break; (*_cards)[_cardCnt] = new KPCMCIACard; (*_cards)[_cardCnt]->_stabPath = _stabPath; (*_cards)[_cardCnt]->_fd = fd; (*_cards)[_cardCnt]->_num = _cardCnt; //(*_cards)[_cardCnt]->refresh(); _cardCnt++; //kdDebug() << "Found a pcmcia slot" << endl; } if (_cardCnt > 0) { if (ioctl((*_cards)[0]->_fd, DS_GET_CARD_SERVICES_INFO, &serv) == 0) { // FIXME: what to do here? } _haveCardServices = true; } } _timer->start(_refreshSpeed, true); /////////////////////////////////////////////////// // No supported platform. /////////////////////////////////////////////////// #else #endif }
static int scanDevices() { struct libusb_device** devs; ssize_t count; ssize_t i; int rc; int needToRescan; // Check if the devices need to be rescanned. rc = freespace_hotplug_perform(&needToRescan); if (rc != FREESPACE_SUCCESS || !needToRescan) { return rc; } count = libusb_get_device_list(freespace_libusb_context, &devs); if (count < 0) { return libusb_to_freespace_error(count); } ts++; for (i = 0; i < count; i++) { struct libusb_device_descriptor desc; struct libusb_device* dev = devs[i]; struct FreespaceDeviceAPI const * api; rc = libusb_get_device_descriptor(dev, &desc); if (rc < 0) { // Can't get the device descriptor, so try the next one. continue; } // Find if this device is in the known list. api = lookupDevice(&desc); if (api != NULL) { uint8_t deviceAddress = libusb_get_device_address(dev); struct FreespaceDevice* device; device = findDeviceById(deviceAddress); if (device == NULL) { device = (struct FreespaceDevice*) malloc(sizeof(struct FreespaceDevice)); if (device == NULL) { // Out of memory. libusb_free_device_list(devs, 1); return FREESPACE_ERROR_OUT_OF_MEMORY; } memset(device, 0, sizeof(struct FreespaceDevice)); libusb_ref_device(dev); device->dev_ = dev; device->idProduct_ = desc.idProduct; device->idVendor_ = desc.idVendor; device->api_ = api; device->id_ = libusb_get_device_address(dev); device->state_ = FREESPACE_CONNECTED; device->ts_ = ts; addFreespaceDevice(device); if (hotplugCallback) { hotplugCallback(FREESPACE_HOTPLUG_INSERTION, device->id_, hotplugCookie); } } device->ts_ = ts; } } for (i = 0; i < FREESPACE_MAXIMUM_DEVICE_COUNT; i++) { struct FreespaceDevice* d = devices[i]; if (d != NULL && d->ts_ != ts) { if (hotplugCallback) { hotplugCallback(FREESPACE_HOTPLUG_REMOVAL, d->id_, hotplugCookie); } if (d->state_ == FREESPACE_OPENED) { d->state_ = FREESPACE_DISCONNECTED; } else { removeFreespaceDevice(d); } } } libusb_free_device_list(devs, 1); return FREESPACE_SUCCESS; }