Changeset 12325 in vbox
- Timestamp:
- Sep 10, 2008 5:52:01 AM (16 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Builtins.cpp
r11502 r12325 247 247 #endif 248 248 249 #if defined(RT_OS_ LINUX) || defined(RT_OS_WINDOWS)249 #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS) 250 250 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostSerial); 251 251 if (RT_FAILURE(rc)) -
trunk/src/VBox/Devices/Makefile.kmk
r12268 r12325 671 671 , $(Drivers_SOURCES)) \ 672 672 Audio/coreaudio.c 673 Drivers_SOURCES.darwin = 673 Drivers_SOURCES.darwin = \ 674 Serial/DrvHostSerial.cpp 674 675 endif # darwin 675 676 -
trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp
r12300 r12325 39 39 #include <iprt/alloc.h> 40 40 41 #if def RT_OS_LINUX41 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 42 42 # include <errno.h> 43 43 # include <termios.h> … … 51 51 # include <sys/signal.h> 52 52 53 # ifdef RT_OS_LINUX 53 54 /* 54 55 * TIOCM_LOOP is not defined in the above header files for some reason but in asm/termios.h. … … 56 57 * structs. Thatswhy it is defined here until a better solution is found. 57 58 */ 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 */ 61 63 62 64 #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" 67 69 68 70 … … 98 100 char *pszDevicePath; 99 101 100 #if def RT_OS_LINUX102 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 101 103 /** the device handle */ 102 104 RTFILE DeviceFile; … … 105 107 /** The write end of the control pipe */ 106 108 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 107 114 #elif defined(RT_OS_WINDOWS) 108 115 /** the device handle */ … … 188 195 { 189 196 PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface); 190 #if def RT_OS_LINUX197 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 191 198 struct termios *termiosSetup; 192 199 int baud_rate; … … 197 204 LogFlow(("%s: Bps=%u chParity=%c cDataBits=%u cStopBits=%u\n", __FUNCTION__, Bps, chParity, cDataBits, cStopBits)); 198 205 199 #if def RT_OS_LINUX206 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 200 207 termiosSetup = (struct termios *)RTMemTmpAllocZ(sizeof(struct termios)); 201 208 … … 441 448 unsigned cbProcessed = 1; 442 449 443 #if defined(RT_OS_LINUX) 450 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 444 451 445 452 rc = RTFileWrite(pThis->DeviceFile, &pThis->aSendQueue[pThis->iSendQueueTail], cbProcessed, NULL); … … 545 552 /* Get a block of data from the host serial device. */ 546 553 547 #if defined(RT_OS_LINUX) 554 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 548 555 549 556 size_t cbRead; … … 696 703 { 697 704 PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL); 698 #if def RT_OS_LINUX705 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 699 706 return RTFileWrite(pThis->WakeupPipeW, "", 1, NULL); 700 707 #elif defined(RT_OS_WINDOWS) … … 707 714 } 708 715 709 #if defined(RT_OS_LINUX) 716 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 710 717 /* -=-=-=-=- Monitor thread -=-=-=-=- */ 711 718 … … 736 743 unsigned int statusLines; 737 744 745 # ifdef RT_OS_LINUX 738 746 /* 739 747 * Wait for status line change. … … 754 762 if (rc < 0) 755 763 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 */ 756 782 757 783 if (statusLines & TIOCM_CAR) … … 769 795 } 770 796 797 798 # ifdef RT_OS_LINUX 799 /** Signal handler for SIGUSR2. 800 * Used to interrupt ioctl(TIOCMIWAIT). */ 771 801 static void drvHostSerialSignalHandler(int iSignal) 772 802 { … … 774 804 return; 775 805 } 806 # endif 776 807 777 808 /** … … 786 817 static DECLCALLBACK(int) drvHostSerialWakeupMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) 787 818 { 819 # ifdef RT_OS_LINUX 788 820 PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL); 789 821 int rc = VINF_SUCCESS; 790 # if 0822 # if 0 791 823 unsigned int uSerialLineFlags; 792 824 unsigned int uSerialLineStatus; 793 825 unsigned int uIoctl; 794 # endif826 # endif 795 827 796 828 /* … … 812 844 */ 813 845 814 # if 0 /* Disabled because it does not work for all. */846 # if 0 /* Disabled because it does not work for all. */ 815 847 /* Get current status of control lines. */ 816 848 rc = ioctl(pThis->DeviceFile, TIOCMGET, &uSerialLineStatus); … … 853 885 N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"), 854 886 pThis->pszDevicePath, RTErrConvertFromErrno(errno)); 855 # endif856 857 # if 0887 # endif 888 889 # if 0 858 890 /* Close file to make ioctl return. */ 859 891 RTFileClose(pData->DeviceFile); … … 866 898 N_("Opening failed for serial host device '%s' (%Vrc). The device will not work"), 867 899 pData->pszDevicePath, rc); 868 # endif900 # endif 869 901 870 902 pthread_t ThreadId = (pthread_t)RTThreadGetNative(pThread->Thread); … … 891 923 sigaction(SIGUSR2, &SigactionThreadOld, NULL); 892 924 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 893 932 return VINF_SUCCESS; 894 933 } 895 #endif /* RT_OS_LINUX */934 #endif /* RT_OS_LINUX || RT_OS_DARWIN */ 896 935 897 936 /** … … 907 946 PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface); 908 947 909 #if def RT_OS_LINUX948 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 910 949 int modemStateSet = 0; 911 950 int modemStateClear = 0; … … 963 1002 * Init basic data members and interfaces. 964 1003 */ 965 #if def RT_OS_LINUX1004 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 966 1005 pThis->DeviceFile = NIL_RTFILE; 967 1006 pThis->WakeupPipeR = NIL_RTFILE; … … 974 1013 pThis->IChar.pfnSetParameters = drvHostSerialSetParameters; 975 1014 pThis->IChar.pfnSetModemLines = drvHostSerialSetModemLines; 1015 1016 /** @todo Initialize all members with NIL values!! The destructor is ALWAYS called. */ 976 1017 977 1018 /* … … 1034 1075 case VERR_ACCESS_DENIED: 1035 1076 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 1036 #if def RT_OS_LINUX1077 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 1037 1078 N_("Cannot open host device '%s' for read/write access. Check the permissions " 1038 1079 "of that device ('/bin/ls -l %s'): Most probably you need to be member " … … 1052 1093 1053 1094 /* Set to non blocking I/O */ 1054 #if def RT_OS_LINUX1095 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 1055 1096 1056 1097 fcntl(pThis->DeviceFile, F_SETFL, O_NONBLOCK); … … 1087 1128 return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_("HostSerial#%d has no char port interface above"), pDrvIns->iInstance); 1088 1129 1130 /* 1131 * Create the receive, send and monitor threads pluss the related send semaphore. 1132 */ 1089 1133 rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pRecvThread, pThis, drvHostSerialRecvThread, drvHostSerialWakeupRecvThread, 0, RTTHREADTYPE_IO, "SerRecv"); 1090 1134 if (RT_FAILURE(rc)) … … 1098 1142 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance); 1099 1143 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 1102 1149 rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostSerialMonitorThread, drvHostSerialWakeupMonitorThread, 0, RTTHREADTYPE_IO, "SerMon"); 1103 1150 if (RT_FAILURE(rc)) … … 1105 1152 #endif 1106 1153 1154 /* 1155 * Register release statistics. 1156 */ 1107 1157 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes written", "/Devices/HostSerial%d/Written", pDrvIns->iInstance); 1108 1158 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes read", "/Devices/HostSerial%d/Read", pDrvIns->iInstance); … … 1132 1182 pThis->SendSem = NIL_RTSEMEVENT; 1133 1183 1134 #if defined(RT_OS_LINUX) 1184 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 1135 1185 1136 1186 if (pThis->WakeupPipeW != NIL_RTFILE)
Note:
See TracChangeset
for help on using the changeset viewer.