VirtualBox

Changeset 42152 in vbox for trunk


Ignore:
Timestamp:
Jul 13, 2012 7:31:42 PM (13 years ago)
Author:
vboxsync
Message:

DrvHostParallel.cpp: Some cleanups and todos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp

    r40707 r42152  
    6060
    6161#if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0)
    62 # include <Wdm.h>
    63 # include <parallel.h>
    6462# include <iprt/asm-amd64-x86.h>
    6563#endif
    6664
    6765#if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING3)
    68 # include <stdio.h>
    69 # include <windows.h>
    70 # include <devguid.h>
     66# include <Windows.h>
    7167# include <setupapi.h>
    72 # include <regstr.h>
    73 # include <string.h>
    7468# include <cfgmgr32.h>
    7569# include <iprt/mem.h>
    76 # define CTRL_REG_OFFSET 2
    77 # define STATUS_REG_OFFSET  1
     70# include <iprt/string.h>
    7871#endif
    7972
     
    130123    uint8_t                       u8ReadInStatus;
    131124        /** Parallel port name */
     125    /** @todo r=bird: This is an array, they start with 'a'. However, this seems
     126     * to be a string, and they are not uint8_t but char and are prefixed with 'sz'
     127     * in char array form.
     128     *
     129     * Also, the use of tabs as indentation in anything but Makefiles is
     130     * forbidden.  That is not a guideline, it's the law. :-) (See above line.) */
    132131    uint8_t                       u8ParportName[6];
    133132    /** Whether the parallel port is available or not. */
     
    163162#define PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface) ( (PDRVHOSTPARALLEL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector))) )
    164163
     164
     165/*******************************************************************************
     166*   Defined Constants And Macros                                               *
     167*******************************************************************************/
     168#define CTRL_REG_OFFSET                 2
     169#define STATUS_REG_OFFSET               1
     170#define LPT_CONTROL_ENABLE_BIDIRECT     0x20
     171
     172
     173
    165174#ifdef VBOX_WITH_WIN_PARPORT_SUP
    166 #ifdef IN_RING0
     175# ifdef IN_RING0
     176
    167177/**
    168178 * R0 mode function to write byte value to data port.
     
    262272    {
    263273       u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
    264        u8WriteControlVal = u8ReadControlVal | DCR_DIRECTION; /* enable input direction */
     274       u8WriteControlVal = u8ReadControlVal | LPT_CONTROL_ENABLE_BIDIRECT; /* enable input direction */
    265275       ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
    266276    }
     
    268278    {
    269279        u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
    270         u8WriteControlVal = u8ReadControlVal & ~DCR_DIRECTION; /* disable input direction */
     280        u8WriteControlVal = u8ReadControlVal & ~LPT_CONTROL_ENABLE_BIDIRECT; /* disable input direction */
    271281        ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
    272282    }
     
    309319    return rc;
    310320}
    311 #endif /* IN_RING0 */
     321
     322# endif /* IN_RING0 */
    312323#endif /* VBOX_WITH_WIN_PARPORT_SUP */
    313324
    314325#ifdef IN_RING3
    315326# ifdef VBOX_WITH_WIN_PARPORT_SUP
     327
    316328/**
    317329 * Find IO port range for the parallel port and return the lower address.
     
    411423    for (u32Idx = 0; SetupDiEnumDeviceInfo(hDevInfo, u32Idx, &DeviceInfoData); u32Idx++)
    412424    {
    413         uint32_t u32DataType;
     425        uint32_t u32DataType; /** @todo r=bird: why do you use uint32_t here when the function wants a DWORD? */
    414426        uint8_t *pBuf = NULL;
    415         uint32_t u32BufSize = 0;
    416 
    417         while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, (PDWORD)&u32DataType, (uint8_t *)pBuf,
    418                                                  u32BufSize, (PDWORD)&u32BufSize))
     427        uint32_t u32BufSize = 0; /** @todo r=bird: ditto */
     428
     429        while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME,
     430                                                 (PDWORD)&u32DataType, (uint8_t *)pBuf,
     431                                                 u32BufSize, (PDWORD)&u32BufSize)
     432               && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    419433        {
    420             if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    421             {
    422                 if (pBuf)
    423                      RTMemFree(pBuf);
    424                 /* Max size will never be more than 2048 bytes */
    425                 pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2);
    426             }
    427             else
    428                 break;
     434            if (pBuf)
     435                 RTMemFree(pBuf);
     436            /* Max size will never be more than 2048 bytes */
     437            pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2);
    429438        }
    430439
    431440        if (pBuf) /** @todo r=bird: You're not checking errors here. */
    432441        {
     442            /** @todo r=bird: The indent of the block is wrong... More importantely, the
     443             * scope and purpose of the two variables would be clearer if you moved them
     444             * to the RTStrStr calls further down. */
    433445             char *pCh = NULL;
    434446             char* pTmpCh = NULL;
     
    449461                     }
    450462                     if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
    451                          LogFlowFunc(("Parallel port string not properly formatted. \n"));
     463                         LogFlowFunc(("Parallel port string not properly formatted.\n"));
    452464                         return VERR_NOT_FOUND;
    453465                     }
     
    456468                                      pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
    457469                     {
    458                          LogFlowFunc(("Parallel Port Not Found. \n"));
     470                         LogFlowFunc(("Parallel Port Not Found.\n"));
    459471                         return VERR_NOT_FOUND;
    460472                     }
     
    463475                     /* checking again to make sure that we have got a valid name and in valid format too. */
    464476                     if (RTStrNCmp((char *)pThis->u8ParportName, "LPT", 3)) {
    465                          LogFlowFunc(("Parallel Port name \"LPT\" Not Found. \n"));
     477                         LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n"));
    466478                         return VERR_NOT_FOUND;
    467479                     }
    468480
     481                     /** @todo r=bird: Multiline expressions starts the next line with the
     482                      * operator, (instead of the previous line ending with an operator like you do
     483                      * here).
     484                      *
     485                      * Also, note that the opening curly brackets have it's own line in this
     486                      * file, so you do the same as the original author(s) of the file. */
    469487                     if (!RTStrStr((char *)pThis->u8ParportName, "LPT") ||
    470488                          !(pThis->u8ParportName[3] >= '0' && pThis->u8ParportName[3] <= '9')) {
    471489                         RT_BZERO(pThis->u8ParportName, sizeof(pThis->u8ParportName));
    472                          LogFlowFunc(("Printer Port Name Not Found. \n"));
     490                         LogFlowFunc(("Printer Port Name Not Found.\n"));
    473491                         return VERR_NOT_FOUND;
    474492                     }
    475                      pThis->fParportAvail = true;
    476                      pThis->u32LptAddr = u32ParportAddr;
     493                     pThis->fParportAvail     = true;
     494                     pThis->u32LptAddr        = u32ParportAddr;
    477495                     pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET;
    478                      pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET;
     496                     pThis->u32LptAddrStatus  = pThis->u32LptAddr + STATUS_REG_OFFSET;
    479497                 }
    480498                 if (pThis->fParportAvail)
     
    9831001#else /* VBOX_WITH_WIN_PARPORT_SUP */
    9841002    HANDLE hPort;
    985     pThis->fParportAvail = false;
    986     pThis->u32LptAddr = 0L;
    987     pThis->u32LptAddrControl = 0L;
    988     pThis->u32LptAddrStatus = 0L;
     1003    pThis->fParportAvail     = false;
     1004    pThis->u32LptAddr        = 0;
     1005    pThis->u32LptAddrControl = 0;
     1006    pThis->u32LptAddrStatus  = 0;
    9891007    rc = drvWinHostGetparportAddr(pThis);
    9901008
     
    9921010       Read and write will be done only if addresses are available
    9931011    */
    994     if (pThis->u8ParportName) {
     1012    if (pThis->u8ParportName)
     1013    {
    9951014        LogFlowFunc(("Get the Handle to Printer Port =%s\n", (char *)pThis->u8ParportName));
    9961015        /** @todo r=klaus convert to IPRT */
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