VirtualBox

Changeset 6185 in vbox


Ignore:
Timestamp:
Dec 26, 2007 7:40:48 PM (17 years ago)
Author:
vboxsync
Message:

Add status line monitoring for windows hosts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp

    r6088 r6185  
    605605            if (pThread->enmState != PDMTHREADSTATE_RUNNING)
    606606                break;
    607             if (!ReadFile(pData->hDeviceFile, abBuffer, sizeof(abBuffer), &dwNumberOfBytesTransferred, &pData->overlappedRecv))
    608             {
    609                 LogRel(("HostSerial#%d: Read failed with error %Vrc; terminating the worker thread.\n", pDrvIns->iInstance, RTErrConvertFromWin32(GetLastError())));
    610                 break;
    611             }
    612             cbRemaining = dwNumberOfBytesTransferred;
    613 
     607
     608            /* Check the event */
     609            if (dwEventMask & EV_RXCHAR)
     610            {
     611                if (!ReadFile(pData->hDeviceFile, abBuffer, sizeof(abBuffer), &dwNumberOfBytesTransferred, &pData->overlappedRecv))
     612                {
     613                    LogRel(("HostSerial#%d: Read failed with error %Vrc; terminating the worker thread.\n", pDrvIns->iInstance, RTErrConvertFromWin32(GetLastError())));
     614                    break;
     615                }
     616                cbRemaining = dwNumberOfBytesTransferred;
     617            }
     618            else
     619            {
     620                /* The status lines have changed. Notify the device. */
     621                DWORD dwNewStatusLinesState = 0;
     622                uint8_t uNewStatusLinesState = 0;
     623
     624                /* Get the new state */
     625                if (GetModemStatus(pData->hDeviceFile, &dwNewStatusLinesState))
     626                {
     627                    if (dwNewStatusLinesState & MS_RLSD_ON)
     628                        uNewStatusLinesState |= PDM_ICHAR_STATUS_LINES_DCD;
     629                    if (dwNewStatusLinesState & MS_RING_ON)
     630                        uNewStatusLinesState |= PDM_ICHAR_STATUS_LINES_RI;
     631                    if (dwNewStatusLinesState & MS_DSR_ON)
     632                        uNewStatusLinesState |= PDM_ICHAR_STATUS_LINES_DSR;
     633                    if (dwNewStatusLinesState & MS_CTS_ON)
     634                        uNewStatusLinesState |= PDM_ICHAR_STATUS_LINES_CTS;
     635                    rc = pData->pDrvCharPort->pfnNotifyStatusLinesChanged(pData->pDrvCharPort, uNewStatusLinesState);
     636                    if (VBOX_FAILURE(rc))
     637                    {
     638                        /* Notifying device failed, continue but log it */
     639                        LogRel(("HostSerial#%d: Notifying device failed with error %Vrc; continuing.\n", pDrvIns->iInstance, rc);
     640                    }
     641                }
     642                else
     643                {
     644                    /* Getting new state failed, continue but log it */
     645                    LogRel(("HostSerial#%d: Getting status lines state failed with error %Vrc; continuing.\n", pDrvIns->iInstance, RTErrConvertFromWin32(GetLastError())));
     646                }
     647            }
    614648#endif
    615649
     
    667701}
    668702
     703#if defined(RT_OS_LINUX)
    669704/* -=-=-=-=- Monitor thread -=-=-=-=- */
    670705
     
    683718    PDRVHOSTSERIAL pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL);
    684719    int rc = VINF_SUCCESS;
    685 
    686 #if defined (RT_OS_LINUX)
    687720    unsigned uStatusLinesToCheck = 0;
    688721
    689722    uStatusLinesToCheck = TIOCM_CAR | TIOCM_RNG | TIOCM_LE | TIOCM_CTS;
    690 #endif
    691723
    692724    if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
     
    696728    {
    697729        uint32_t newStatusLine = 0;
    698 
    699 #if defined(RT_OS_LINUX)
    700730        unsigned int statusLines;
    701731
     
    718748            newStatusLine |= PDM_ICHAR_STATUS_LINES_CTS;
    719749        rc = pData->pDrvCharPort->pfnNotifyStatusLinesChanged(pData->pDrvCharPort, newStatusLine);
    720 #endif
    721750    }
    722751
     
    735764    PDRVHOSTSERIAL pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL);
    736765    int rc = VINF_SUCCESS;
    737 #if defined(RT_OS_LINUX)
     766
    738767    /*
    739768     * Linux is a bit difficult as the thread is sleeping in an ioctl call.
     
    758787        AssertMsgFailed(("%s: Setting device into normal mode failed. Device is not in a working state!!\n", __FUNCTION__));
    759788
    760 #elif defined(RT_OS_WINDOWS)
    761     /** @todo */
    762 #else
    763 # error adapt me!
    764 #endif
    765 
    766789    return rc;
    767790}
     791#endif /* RT_OS_LINUX */
    768792
    769793/**
     
    885909        pData->hDeviceFile = hFile;
    886910        /* for overlapped read */
    887         if (!SetCommMask(hFile, EV_RXCHAR))
     911        if (!SetCommMask(hFile, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING | EV_RLSD))
    888912        {
    889913            LogRel(("HostSerial#%d: SetCommMask failed with error %d.\n", pDrvIns->iInstance, GetLastError()));
     
    971995
    972996#if defined(RT_OS_LINUX)
     997    /* Linux needs a separate thread which monitors the status lines. */
    973998    rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pData->pMonitorThread, pData, drvHostSerialMonitorThread, drvHostSerialWakeupMonitorThread, 0, RTTHREADTYPE_IO, "Serial Monitor");
    974999    if (VBOX_FAILURE(rc))
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