VirtualBox

Changeset 32142 in vbox


Ignore:
Timestamp:
Aug 31, 2010 1:00:46 PM (14 years ago)
Author:
vboxsync
Message:

Main/linux/USB: moved a vector container-based implementation detail out of the interface

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/HostHardwareLinux.h

    r31652 r32142  
    110110
    111111
    112 /** Vector type for the list of interfaces. */
    113 #define VECTOR_TYPE       char *
    114 #define VECTOR_TYPENAME   USBInterfaceList
    115 static inline void USBInterfaceListCleanup(char **ppsz)
    116 {
    117     RTStrFree(*ppsz);
    118 }
    119 #define VECTOR_DESTRUCTOR USBInterfaceListCleanup
    120 #include "vector.h"
    121 
    122112/** Structure describing a host USB device */
    123113typedef struct USBDeviceInfo
     
    128118     * method. */
    129119    char *mSysfsPath;
    130     /** Type for the list of interfaces. */
    131     USBInterfaceList mInterfaces;
     120    /** List of interfaces.  Only one simulaneous traversal is possible. */
     121    struct USBInterfaceList *mInterfaces;
    132122} USBDeviceInfo;
    133123
    134 
    135124/** Destructor. */
    136 static inline void USBDevInfoCleanup(USBDeviceInfo *pSelf)
    137 {
    138     RTStrFree(pSelf->mDevice);
    139     RTStrFree(pSelf->mSysfsPath);
    140     pSelf->mDevice = pSelf->mSysfsPath = NULL;
    141     USBInterfaceList_cleanup(&pSelf->mInterfaces);
    142 }
    143 
     125void USBDevInfoCleanup(USBDeviceInfo *pSelf);
    144126
    145127/** Constructor - the strings will be duplicated. */
    146 static inline int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
    147                                  const char *aSystemID)
    148 {
    149     pSelf->mDevice = aDevice ? RTStrDup(aDevice) : NULL;
    150     pSelf->mSysfsPath = aSystemID ? RTStrDup(aSystemID) : NULL;
    151     if (   !USBInterfaceList_init(&pSelf->mInterfaces)
    152         || (aDevice && !pSelf->mDevice) || (aSystemID && ! pSelf->mSysfsPath))
    153     {
    154         USBDevInfoCleanup(pSelf);
    155         return 0;
    156     }
    157     return 1;
    158 }
     128int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
     129                   const char *aSystemID);
     130
     131/**
     132 * Return the first in a list of USB device interfaces (that is, its sysfs
     133 * path), or NULL if there are none.
     134 */
     135char *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces);
     136
     137/**
     138 * Return the next in a list of USB device interfaces (that is, its sysfs
     139 * path), or NULL if there are none.
     140 */
     141char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces);
    159142
    160143
     
    195178 */
    196179int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf);
    197 
    198180
    199181/** Get the first element in the list of USB devices. */
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r32115 r32142  
    10081008}
    10091009
     1010/** Vector type for the list of interfaces. */
     1011#define VECTOR_TYPE       char *
     1012#define VECTOR_TYPENAME   usbInterfaceList
     1013static void usbInterfaceListCleanup(char **ppsz)
     1014{
     1015    RTStrFree(*ppsz);
     1016}
     1017#define VECTOR_DESTRUCTOR usbInterfaceListCleanup
     1018#include "vector.h"
     1019
     1020struct USBInterfaceList
     1021{
     1022    /** The vector of devices */
     1023    usbInterfaceList mList;
     1024    /** The single traversal iterator */
     1025    usbInterfaceList_iterator mIt;
     1026};
     1027
     1028void USBDevInfoCleanup(USBDeviceInfo *pSelf)
     1029{
     1030    RTStrFree(pSelf->mDevice);
     1031    RTStrFree(pSelf->mSysfsPath);
     1032    pSelf->mDevice = pSelf->mSysfsPath = NULL;
     1033    if (pSelf->mInterfaces)
     1034    {
     1035        usbInterfaceList_cleanup(&pSelf->mInterfaces->mList);
     1036        RTMemFree(pSelf->mInterfaces);
     1037    }
     1038}
     1039
     1040int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
     1041                   const char *aSystemID)
     1042{
     1043    const usbInterfaceList_iterator *pItBegin;
     1044
     1045    pSelf->mDevice = aDevice ? RTStrDup(aDevice) : NULL;
     1046    pSelf->mSysfsPath = aSystemID ? RTStrDup(aSystemID) : NULL;
     1047    pSelf->mInterfaces = (struct USBInterfaceList *) RTMemAllocZ(sizeof(struct USBInterfaceList));
     1048    if (   !pSelf->mInterfaces
     1049        || !usbInterfaceList_init(&pSelf->mInterfaces->mList)
     1050        || (aDevice && !pSelf->mDevice) || (aSystemID && ! pSelf->mSysfsPath))
     1051    {
     1052        USBDevInfoCleanup(pSelf);
     1053        return 0;
     1054    }
     1055    pItBegin = usbInterfaceList_begin(&pSelf->mInterfaces->mList);
     1056    usbInterfaceList_iter_init(&pSelf->mInterfaces->mIt, pItBegin);
     1057    return 1;
     1058}
    10101059
    10111060int USBDevInfoUpdateDevices (VBoxMainUSBDeviceInfo *pSelf)
     
    10271076    return rc;
    10281077}
     1078
     1079char *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces)
     1080{
     1081    const usbInterfaceList_iterator *pItBegin, *pItEnd;
     1082    pItBegin = usbInterfaceList_begin(&pInterfaces->mList);
     1083    pItEnd = usbInterfaceList_end(&pInterfaces->mList);
     1084    usbInterfaceList_iter_init(&pInterfaces->mIt, pItBegin);
     1085    if (usbInterfaceList_iter_eq(pItBegin, pItEnd))
     1086        return NULL;
     1087    return *usbInterfaceList_iter_target(&pInterfaces->mIt);
     1088}
     1089
     1090char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces)
     1091{
     1092    const usbInterfaceList_iterator *pItEnd;
     1093    pItEnd = usbInterfaceList_end(&pInterfaces->mList);
     1094    if (usbInterfaceList_iter_eq(&pInterfaces->mIt, pItEnd))
     1095        return NULL;
     1096    usbInterfaceList_iter_incr(&pInterfaces->mIt);
     1097    if (usbInterfaceList_iter_eq(&pInterfaces->mIt, pItEnd))
     1098        return NULL;
     1099    return *usbInterfaceList_iter_target(&pInterfaces->mIt);
     1100}
     1101
    10291102
    10301103class hotplugNullImpl : public VBoxMainHotplugWaiterImpl
     
    16441717    char *pcszDup = RTStrDup(pcszNode);
    16451718    if (pcszDup)
    1646         if (USBInterfaceList_push_back(&pSelf->mInfo->mInterfaces, &pcszDup))
     1719        if (usbInterfaceList_push_back(&pSelf->mInfo->mInterfaces->mList,
     1720                                       &pcszDup))
    16471721            return true;
    16481722    RTStrFree(pcszDup);
  • trunk/src/VBox/Main/linux/USBProxyServiceLinux.cpp

    r32080 r32142  
    13401340{
    13411341#ifdef VBOX_USB_WITH_SYSFS
    1342     USBDevInfoUpdateDevices(&mDeviceList);
    13431342    /* Add each of the devices found to the chain. */
    13441343    PUSBDEVICE pFirst = NULL;
    13451344    PUSBDEVICE pLast  = NULL;
    1346     int        rc     = VINF_SUCCESS;
     1345    int        rc     = USBDevInfoUpdateDevices(&mDeviceList);
    13471346    USBDeviceInfoList_iterator it;
    13481347    USBDeviceInfoList_iter_init(&it, USBDevInfoBegin(&mDeviceList));
     
    14421441
    14431442            /* Check the interfaces to see if we can support the device. */
    1444             USBInterfaceList_iterator it2;
     1443            char *pszIf;
    14451444            USBDeviceInfo *udi = USBDeviceInfoList_iter_target(&it);
    1446             USBInterfaceList_iter_init(&it2, USBInterfaceList_begin(&udi->mInterfaces));
    1447             for (; !USBInterfaceList_iter_eq(&it2, USBInterfaceList_end(&udi->mInterfaces));
    1448                    USBInterfaceList_iter_incr(&it2))
     1445            for (pszIf = USBDevInfoFirstInterface(udi->mInterfaces); pszIf;
     1446                 pszIf = USBDevInfoNextInterface(udi->mInterfaces))
    14491447            {
    14501448                ssize_t cb = RTLinuxSysFsGetLinkDest(szBuf, sizeof(szBuf), "%s/driver",
    1451                                                      *USBInterfaceList_iter_target(&it2));
     1449                                                     pszIf);
    14521450                if (cb > 0 && Dev->enmState != USBDEVICESTATE_UNSUPPORTED)
    14531451                    Dev->enmState = (strcmp(szBuf, "hub") == 0)
     
    14551453                                  : USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
    14561454                if (RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass",
    1457                                             *USBInterfaceList_iter_target(&it2)) == 9 /* hub */)
     1455                                            pszIf) == 9 /* hub */)
    14581456                    Dev->enmState = USBDEVICESTATE_UNSUPPORTED;
    14591457            }
  • trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp

    r31652 r32142  
    123123                  pInfo->mSysfsPath);
    124124        RTPrintf ("    interfaces:\n");
    125         USBInterfaceList_iterator it2;
    126         USBInterfaceList_iter_init(&it2, USBInterfaceList_begin(&pInfo->mInterfaces));
    127         for (; !USBInterfaceList_iter_eq(&it2, USBInterfaceList_end(&pInfo->mInterfaces));
    128                USBInterfaceList_iter_incr(&it2))
     125        char *pszIf;
     126        for (pszIf = USBDevInfoFirstInterface(pInfo->mInterfaces); pszIf;
     127             pszIf = USBDevInfoNextInterface(pInfo->mInterfaces))
    129128        {
    130129            char szDriver[RTPATH_MAX];
    131             char *pszIf = *USBInterfaceList_iter_target(&it2);
    132130            strcpy(szDriver, "none");
    133131            ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette