当前位置: 首页>>代码示例>>C++>>正文


C++ USBDevice::getDevice方法代码示例

本文整理汇总了C++中USBDevice::getDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ USBDevice::getDevice方法的具体用法?C++ USBDevice::getDevice怎么用?C++ USBDevice::getDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在USBDevice的用法示例。


在下文中一共展示了USBDevice::getDevice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: usbDeviceLeft

void FCServer::usbDeviceLeft(libusb_device *device)
{
    /*
     * Is this a device we recognize? If so, delete it.
     */

    for (std::vector<USBDevice*>::iterator i = mUSBDevices.begin(), e = mUSBDevices.end(); i != e; ++i) {
        USBDevice *dev = *i;
        if (dev->getDevice() == device) {
            usbDeviceLeft(i);
            break;
        }
    }
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:14,代码来源:fcserver.cpp

示例2: usbHotplugPoll

bool FCServer::usbHotplugPoll()
{
    /*
     * For platforms without libusbx hotplug support,
     * see if we can fake it by polling for new devices. This can
     * happen on a different thread, and it probably should.
     *
     * We also use this for recovering from transient errors when opening
     * devices. E.g. a device is reported as added by the hotplug system
     * but it isn't actually ready to use in userspace yet.
     *
     * Returns true on success.
     */

    libusb_device **list;
    ssize_t listSize;

    listSize = libusb_get_device_list(mUSB, &list);
    if (listSize < 0) {
        std::clog << "Error polling for USB devices: " << libusb_strerror(libusb_error(listSize)) << "\n";
        return false;
    }

    // Take the lock after get_device_list completes
    mEventMutex.lock();

    // Look for devices that were added
    for (ssize_t listItem = 0; listItem < listSize; ++listItem) {
        bool isNew = true;

        for (std::vector<USBDevice*>::iterator i = mUSBDevices.begin(), e = mUSBDevices.end(); i != e; ++i) {
            USBDevice *dev = *i;
            if (dev->getDevice() == list[listItem]) {
                isNew = false;
            }
        }

        if (isNew) {
            usbDeviceArrived(list[listItem]);
        }
    }

    // Look for devices that were removed
    for (std::vector<USBDevice*>::iterator i = mUSBDevices.begin(), e = mUSBDevices.end(); i != e; ++i) {
        USBDevice *dev = *i;
        libusb_device *usbdev = dev->getDevice();
        bool isRemoved = true;

        for (ssize_t listItem = 0; listItem < listSize; ++listItem) {
            if (list[listItem] == usbdev) {
                isRemoved = false;
            }
        }

        if (isRemoved) {
            usbDeviceLeft(i);
        }
    }

    mEventMutex.unlock();
    libusb_free_device_list(list, true);
    return true;
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:63,代码来源:fcserver.cpp


注:本文中的USBDevice::getDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。