Exemple #1
0
int
main(int argc, const char *argv[])
{
  char **ppsz_cd_drives=NULL, **c;
  
  cdio_log_set_handler (log_handler);

  /* Print out a list of CD-drives */
  printf("All CD-ROM/DVD drives...\n");
  ppsz_cd_drives = getDevices();
  if (NULL != ppsz_cd_drives) 
    for( c = ppsz_cd_drives; *c != NULL; c++ ) {
      printf("Drive %s\n", *c);
    }

  freeDeviceList(ppsz_cd_drives);

  print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL);
  print_drive_class("CD-ROM drives with a CD-DA loaded...", CDIO_FS_AUDIO);
  print_drive_class("CD-ROM drives with some sort of ISO 9660 filesystem...", 
		    CDIO_FS_ANAL_ISO9660_ANY, true);
  print_drive_class("(S)VCD drives...", CDIO_FS_ANAL_VCD_ANY, true);
  return 0;
  
}
/*
 * Return a list of devices found by libftdi together with a number of fields
 * describing the corresponding USB device.
 * The list is internally cached. To free it, call freeDeviceList().
 *
 * Returns: a vector pointer containing 0 or more devices, or NULL if an error
 * occured while retrieving the list. When NULL is returned, this is guaranteed
 * to be an ftdi error.
 */
const FtdiDevice::vec_deviceInfo* FtdiDevice::getDeviceList( ftdi_context* c )
{
	ftdi_context* context = c ? c : ftdi_new();
	if ( context == 0 ) return 0;
	
	if ( s_deviceList != 0 ) freeDeviceList();
	
	int r = ftdi_usb_find_all( context, &s_ftdiDeviceList, USB_VENDOR_ID, USB_PRODUCT_ID );
	s_deviceList = new vec_deviceInfo();
	if ( r >= 0 ) {
		struct ftdi_device_list* openDev = s_ftdiDeviceList;
		while ( openDev ) {
			struct deviceInfo info;
			info.ftdiDevice = openDev->dev;
			info.usbInfo = fetchUsbInformation( context, info.ftdiDevice );
			s_deviceList->push_back( info );
			
			openDev = openDev->next;
		}
	}
	
	//Only free the context if it has been allocated locally.
	if ( c == 0 ) ftdi_free( context );
	return s_deviceList;
}
/**
 * Resets the receive state to the idle state.
 *
 * @returns nothing.
 */
void USBProxyBackendUsbIp::resetRecvState()
{
    freeDeviceList(m->pHead);
    m->pHead          = NULL;
    m->ppNext         = &m->pHead;
    m->cDevicesCur    = 0;
    m->enmRecvState   = kUsbIpRecvState_None;
    m->cbResidualRecv = 0;
    m->pbRecvBuf      = &m->Scratch.abRecv[0];
    m->cDevicesLeft   = 0;
}
Exemple #4
0
static void 
print_drive_class(const char *psz_msg, cdio_fs_anal_t bitmask, 
		  bool b_any=false) {
  char **ppsz_cd_drives=NULL, **c;

  printf("%s...\n", psz_msg);
  ppsz_cd_drives = getDevices(NULL,  bitmask, b_any);
  if (NULL != ppsz_cd_drives) 
    for( c = ppsz_cd_drives; *c != NULL; c++ ) {
      printf("Drive %s\n", *c);
    }

  freeDeviceList(ppsz_cd_drives);
  printf("-----\n");
}
int USBProxyBackendUsbIp::wait(RTMSINTERVAL aMillies)
{
    int rc = VINF_SUCCESS;
    bool fDeviceListChangedOrWokenUp = false;

    /* Try to reconnect once when we enter if we lost the connection earlier. */
    if (m->hSocket == NIL_RTSOCKET)
        rc = reconnect();

    /* Query a new device list upon entering. */
    if (m->enmRecvState == kUsbIpRecvState_None)
    {
        rc = startListExportedDevicesReq();
        if (RT_FAILURE(rc))
            disconnect();
    }

    /*
     * Because the USB/IP protocol doesn't specify a way to get notified about
     * new or removed exported devices we have to poll the host periodically for
     * a new device list and compare it with the previous one notifying the proxy
     * service about changes.
     */
    while (   !fDeviceListChangedOrWokenUp
           && (aMillies == RT_INDEFINITE_WAIT || aMillies > 0)
           && RT_SUCCESS(rc))
    {
        RTMSINTERVAL msWait = aMillies;
        uint64_t msPollStart = RTTimeMilliTS();
        uint32_t uIdReady = 0;
        uint32_t fEventsRecv = 0;

        /* Limit the waiting time to 1sec so we can either reconnect or get a new device list. */
        if (m->hSocket == NIL_RTSOCKET || m->enmRecvState == kUsbIpRecvState_None)
            msWait = RT_MIN(1000, aMillies);

        rc = RTPoll(m->hPollSet, msWait, &fEventsRecv, &uIdReady);
        if (RT_SUCCESS(rc))
        {
            if (uIdReady == USBIP_POLL_ID_PIPE)
            {
                /* Drain the wakeup pipe. */
                char bRead = 0;
                size_t cbRead = 0;

                rc = RTPipeRead(m->hWakeupPipeR, &bRead, 1, &cbRead);
                Assert(RT_SUCCESS(rc) && cbRead == 1);
                fDeviceListChangedOrWokenUp = true;
            }
            else if (uIdReady == USBIP_POLL_ID_SOCKET)
            {
                if (fEventsRecv & RTPOLL_EVT_ERROR)
                    rc = VERR_NET_SHUTDOWN;
                else
                    rc = receiveData();
                if (RT_SUCCESS(rc))
                {
                    /*
                     * If we are in the none state again we received the previous request
                     * and have a new device list to compare the old against.
                     */
                    if (m->enmRecvState == kUsbIpRecvState_None)
                    {
                        if (hasDevListChanged(m->pHead))
                            fDeviceListChangedOrWokenUp = true;

                        /* Update to the new list in any case now that we have it anyway. */
                        RTSemFastMutexRequest(m->hMtxDevices);
                        freeDeviceList(m->pUsbDevicesCur);
                        m->cUsbDevicesCur = m->cDevicesCur;
                        m->pUsbDevicesCur = m->pHead;
                        RTSemFastMutexRelease(m->hMtxDevices);

                        m->pHead = NULL;
                        resetRecvState();
                    }
                }
                else if (rc == VERR_NET_SHUTDOWN || rc == VERR_BROKEN_PIPE)
                {
                    LogRelMax(10, ("USB/IP: Lost connection to host \"%s\", trying to reconnect...\n", m->pszHost));
                    disconnect();
                    rc = VINF_SUCCESS;
                }
            }
            else
            {
                AssertMsgFailed(("Invalid poll ID returned\n"));
                rc = VERR_INVALID_STATE;
            }
            aMillies -= (RTTimeMilliTS() - msPollStart);
        }
        else if (rc == VERR_TIMEOUT)
        {
            aMillies -= msWait;
            if (aMillies)
            {
                /* Try to reconnect and start a new request if we lost the connection before. */
                if (m->hSocket == NIL_RTSOCKET)
                    rc = reconnect();

                if (RT_SUCCESS(rc))
                    rc = startListExportedDevicesReq();
            }
        }
    }

    return rc;
}