VirtualBox

Changeset 12325 in vbox


Ignore:
Timestamp:
Sep 10, 2008 5:52:01 AM (16 years ago)
Author:
vboxsync
Message:

DrvHostSerial: Ported to darwin (untested).

Location:
trunk/src/VBox/Devices
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Builtins.cpp

    r11502 r12325  
    247247#endif
    248248
    249 #if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
     249#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
    250250    rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostSerial);
    251251    if (RT_FAILURE(rc))
  • trunk/src/VBox/Devices/Makefile.kmk

    r12268 r12325  
    671671        , $(Drivers_SOURCES)) \
    672672        Audio/coreaudio.c
    673 Drivers_SOURCES.darwin =
     673Drivers_SOURCES.darwin = \
     674        Serial/DrvHostSerial.cpp
    674675endif # darwin
    675676
  • trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp

    r12300 r12325  
    3939#include <iprt/alloc.h>
    4040
    41 #ifdef RT_OS_LINUX
     41#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    4242# include <errno.h>
    4343# include <termios.h>
     
    5151# include <sys/signal.h>
    5252
     53# ifdef RT_OS_LINUX
    5354/*
    5455 * TIOCM_LOOP is not defined in the above header files for some reason but in asm/termios.h.
     
    5657 * structs. Thatswhy it is defined here until a better solution is found.
    5758 */
    58 #ifndef TIOCM_LOOP
    59 # define TIOCM_LOOP 0x8000
    60 #endif
     59#  ifndef TIOCM_LOOP
     60#   define TIOCM_LOOP 0x8000
     61#  endif
     62# endif /* linux */
    6163
    6264#elif defined(RT_OS_WINDOWS)
    63 # include <windows.h>
    64 #endif
    65 
    66 #include "Builtins.h"
     65# include <Windows.h>
     66#endif
     67
     68#include "../Builtins.h"
    6769
    6870
     
    98100    char                        *pszDevicePath;
    99101
    100 #ifdef RT_OS_LINUX
     102#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    101103    /** the device handle */
    102104    RTFILE                      DeviceFile;
     
    105107    /** The write end of the control pipe */
    106108    RTFILE                      WakeupPipeW;
     109# ifndef RT_OS_LINUX
     110    /** The current line status.
     111     * Used by the polling version of drvHostSerialMonitorThread.  */
     112    int                         fStatusLines;
     113# endif
    107114#elif defined(RT_OS_WINDOWS)
    108115    /** the device handle */
     
    188195{
    189196    PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
    190 #ifdef RT_OS_LINUX
     197#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    191198    struct termios *termiosSetup;
    192199    int baud_rate;
     
    197204    LogFlow(("%s: Bps=%u chParity=%c cDataBits=%u cStopBits=%u\n", __FUNCTION__, Bps, chParity, cDataBits, cStopBits));
    198205
    199 #ifdef RT_OS_LINUX
     206#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    200207    termiosSetup = (struct termios *)RTMemTmpAllocZ(sizeof(struct termios));
    201208
     
    441448            unsigned cbProcessed = 1;
    442449
    443 #if defined(RT_OS_LINUX)
     450#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    444451
    445452            rc = RTFileWrite(pThis->DeviceFile, &pThis->aSendQueue[pThis->iSendQueueTail], cbProcessed, NULL);
     
    545552            /* Get a block of data from the host serial device. */
    546553
    547 #if defined(RT_OS_LINUX)
     554#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    548555
    549556            size_t cbRead;
     
    696703{
    697704    PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
    698 #ifdef RT_OS_LINUX
     705#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    699706    return RTFileWrite(pThis->WakeupPipeW, "", 1, NULL);
    700707#elif defined(RT_OS_WINDOWS)
     
    707714}
    708715
    709 #if defined(RT_OS_LINUX)
     716#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    710717/* -=-=-=-=- Monitor thread -=-=-=-=- */
    711718
     
    736743        unsigned int statusLines;
    737744
     745# ifdef RT_OS_LINUX
    738746        /*
    739747         * Wait for status line change.
     
    754762        if (rc < 0)
    755763            goto ioctl_error;
     764# else  /* !RT_OS_LINUX */
     765        /*
     766         * Poll for the status line change.
     767         */
     768        rc = ioctl(pThis->DeviceFile, TIOCMGET, &statusLines);
     769        if (rc < 0)
     770        {
     771            PDMDrvHlpVMSetRuntimeError(pDrvIns, false, "DrvHostSerialFail",
     772                                       N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"),
     773                                       pThis->pszDevicePath, RTErrConvertFromErrno(errno));
     774            break;
     775        }
     776        if ((statusLines ^ pThis->fStatusLines) & uStatusLinesToCheck)
     777        {
     778            PDMR3ThreadSleep(pThread, 1000); /* 1 sec */
     779            continue;
     780        }
     781# endif /* !RT_OS_LINUX */
    756782
    757783        if (statusLines & TIOCM_CAR)
     
    769795}
    770796
     797
     798# ifdef RT_OS_LINUX
     799/** Signal handler for SIGUSR2.
     800 * Used to interrupt ioctl(TIOCMIWAIT). */
    771801static void drvHostSerialSignalHandler(int iSignal)
    772802{
     
    774804    return;
    775805}
     806# endif
    776807
    777808/**
     
    786817static DECLCALLBACK(int) drvHostSerialWakeupMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
    787818{
     819# ifdef RT_OS_LINUX
    788820    PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
    789821    int rc = VINF_SUCCESS;
    790 #if 0
     822#  if 0
    791823     unsigned int uSerialLineFlags;
    792824     unsigned int uSerialLineStatus;
    793825     unsigned int uIoctl;
    794 #endif
     826#  endif
    795827
    796828    /*
     
    812844     */
    813845
    814 #if 0 /* Disabled because it does not work for all. */
     846#  if 0 /* Disabled because it does not work for all. */
    815847    /* Get current status of control lines. */
    816848    rc = ioctl(pThis->DeviceFile, TIOCMGET, &uSerialLineStatus);
     
    853885                                N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"),
    854886                                pThis->pszDevicePath, RTErrConvertFromErrno(errno));
    855 #endif
    856 
    857 #if 0
     887#  endif
     888
     889#  if 0
    858890    /* Close file to make ioctl return. */
    859891    RTFileClose(pData->DeviceFile);
     
    866898                                    N_("Opening failed for serial host device '%s' (%Vrc). The device will not work"),
    867899                                    pData->pszDevicePath, rc);
    868 #endif
     900#  endif
    869901
    870902    pthread_t        ThreadId = (pthread_t)RTThreadGetNative(pThread->Thread);
     
    891923    sigaction(SIGUSR2, &SigactionThreadOld, NULL);
    892924
     925# else  /* !RT_OS_LINUX*/
     926    /* In polling mode there is nobody to wake up (PDMThread will cancel the sleep). */
     927    NOREF(pDrvIns);
     928    NOREF(pThread);
     929
     930# endif /* RT_OS_LINUX */
     931
    893932    return VINF_SUCCESS;
    894933}
    895 #endif /* RT_OS_LINUX */
     934#endif /* RT_OS_LINUX || RT_OS_DARWIN */
    896935
    897936/**
     
    907946    PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
    908947
    909 #ifdef RT_OS_LINUX
     948#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    910949    int modemStateSet = 0;
    911950    int modemStateClear = 0;
     
    9631002     * Init basic data members and interfaces.
    9641003     */
    965 #ifdef RT_OS_LINUX
     1004#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    9661005    pThis->DeviceFile  = NIL_RTFILE;
    9671006    pThis->WakeupPipeR = NIL_RTFILE;
     
    9741013    pThis->IChar.pfnSetParameters           = drvHostSerialSetParameters;
    9751014    pThis->IChar.pfnSetModemLines           = drvHostSerialSetModemLines;
     1015
     1016/** @todo Initialize all members with NIL values!! The destructor is ALWAYS called. */
    9761017
    9771018    /*
     
    10341075            case VERR_ACCESS_DENIED:
    10351076                return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    1036 #ifdef RT_OS_LINUX
     1077#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    10371078                                           N_("Cannot open host device '%s' for read/write access. Check the permissions "
    10381079                                              "of that device ('/bin/ls -l %s'): Most probably you need to be member "
     
    10521093
    10531094    /* Set to non blocking I/O */
    1054 #ifdef RT_OS_LINUX
     1095#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    10551096
    10561097    fcntl(pThis->DeviceFile, F_SETFL, O_NONBLOCK);
     
    10871128        return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_("HostSerial#%d has no char port interface above"), pDrvIns->iInstance);
    10881129
     1130    /*
     1131     * Create the receive, send and monitor threads pluss the related send semaphore.
     1132     */
    10891133    rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pRecvThread, pThis, drvHostSerialRecvThread, drvHostSerialWakeupRecvThread, 0, RTTHREADTYPE_IO, "SerRecv");
    10901134    if (RT_FAILURE(rc))
     
    10981142        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
    10991143
    1100 #if defined(RT_OS_LINUX)
    1101     /* Linux needs a separate thread which monitors the status lines. */
     1144#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
     1145    /* Linux & darwin needs a separate thread which monitors the status lines. */
     1146# ifndef RT_OS_LINUX
     1147    ioctl(pThis->DeviceFile, TIOCMGET, &pThis->fStatusLines);
     1148# endif
    11021149    rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostSerialMonitorThread, drvHostSerialWakeupMonitorThread, 0, RTTHREADTYPE_IO, "SerMon");
    11031150    if (RT_FAILURE(rc))
     
    11051152#endif
    11061153
     1154    /*
     1155     * Register release statistics.
     1156     */
    11071157    PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesWritten,    STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes written",         "/Devices/HostSerial%d/Written", pDrvIns->iInstance);
    11081158    PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesRead,       STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes read",            "/Devices/HostSerial%d/Read", pDrvIns->iInstance);
     
    11321182    pThis->SendSem = NIL_RTSEMEVENT;
    11331183
    1134 #if defined(RT_OS_LINUX)
     1184#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
    11351185
    11361186    if (pThis->WakeupPipeW != NIL_RTFILE)
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