Changeset 37596 in vbox for trunk/src/VBox/Devices/Parallel
- Timestamp:
- Jun 22, 2011 7:30:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r35353 r37596 27 27 #include <iprt/assert.h> 28 28 #include <iprt/file.h> 29 #include <iprt/pipe.h> 29 30 #include <iprt/semaphore.h> 30 31 #include <iprt/stream.h> … … 64 65 char *pszDevicePath; 65 66 /** Device Handle */ 66 RTFILE FileDevice;67 RTFILE hFileDevice; 67 68 /** Thread waiting for interrupts. */ 68 69 PPDMTHREAD pMonitorThread; 69 70 /** Wakeup pipe read end. */ 70 RT FILEWakeupPipeR;71 RTPIPE hWakeupPipeR; 71 72 /** Wakeup pipe write end. */ 72 RT FILEWakeupPipeW;73 RTPIPE hWakeupPipeW; 73 74 } DRVHOSTPARALLEL, *PDRVHOSTPARALLEL; 74 75 … … 102 103 LogFlow(("%s: pvBuf=%#p cbWrite=%d\n", __FUNCTION__, pvBuf, *cbWrite)); 103 104 104 ioctl( pThis->FileDevice, PPWDATA, pBuffer);105 ioctl(RTFileToNative(pThis->hFileDevice), PPWDATA, pBuffer); 105 106 *cbWrite = 1; 106 107 … … 115 116 LogFlow(("%s: pvBuf=%#p cbRead=%d\n", __FUNCTION__, pvBuf, cbRead)); 116 117 117 ioctl( pThis->FileDevice, PPRDATA, pBuffer);118 ioctl(RTFileToNative(pThis->hFileDevice), PPRDATA, pBuffer); 118 119 *cbRead = 1; 119 120 … … 140 141 } 141 142 142 ioctl( pThis->FileDevice, PPSETMODE, &ppdev_mode);143 ioctl(RTFileToNative(pThis->hFileDevice), PPSETMODE, &ppdev_mode); 143 144 144 145 return VINF_SUCCESS; … … 150 151 151 152 LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg)); 152 153 ioctl(pThis->FileDevice, PPWCONTROL, &fReg); 153 ioctl(RTFileToNative(pThis->hFileDevice), PPWCONTROL, &fReg); 154 154 155 155 return VINF_SUCCESS; … … 159 159 { 160 160 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface); 161 uint8_t fReg; 162 163 ioctl(pThis->FileDevice, PPRCONTROL, &fReg); 164 161 162 uint8_t fReg = 0; 163 ioctl(RTFileToNative(pThis->hFileDevice), PPRCONTROL, &fReg); 165 164 LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg)); 166 167 165 *pfReg = fReg; 168 166 … … 173 171 { 174 172 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface); 175 uint8_t fReg; 176 177 ioctl(pThis->FileDevice, PPRSTATUS, &fReg); 178 173 174 uint8_t fReg = 0; 175 ioctl(RTFileToNative(pThis->hFileDevice), PPRSTATUS, &fReg); 179 176 LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg)); 180 181 177 *pfReg = fReg; 182 178 … … 196 192 int rc; 197 193 198 aFDs[0].fd = pThis->FileDevice;194 aFDs[0].fd = RTFileToNative(pThis->hFileDevice); 199 195 aFDs[0].events = POLLIN; 200 196 aFDs[0].revents = 0; 201 aFDs[1].fd = pThis->WakeupPipeR;197 aFDs[1].fd = RTPipeToNative(pThis->hWakeupPipeR); 202 198 aFDs[1].events = POLLIN | POLLERR | POLLHUP; 203 199 aFDs[1].revents = 0; … … 218 214 char ch; 219 215 size_t cbRead; 220 RT FileRead(pThis->WakeupPipeR, &ch, 1, &cbRead);216 RTPipeRead(pThis->hWakeupPipeR, &ch, 1, &cbRead); 221 217 continue; 222 218 } … … 240 236 { 241 237 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 242 243 return RT FileWrite(pThis->WakeupPipeW, "", 1, NULL);238 size_t cbIgnored; 239 return RTPipeWrite(pThis->hWakeupPipeW, "", 1, &cbIgnored); 244 240 } 245 241 … … 257 253 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance)); 258 254 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 259 260 ioctl(pThis->FileDevice, PPRELEASE); 261 262 if (pThis->WakeupPipeW != NIL_RTFILE) 263 { 264 int rc = RTFileClose(pThis->WakeupPipeW); 265 AssertRC(rc); 266 pThis->WakeupPipeW = NIL_RTFILE; 267 } 268 if (pThis->WakeupPipeR != NIL_RTFILE) 269 { 270 int rc = RTFileClose(pThis->WakeupPipeR); 271 AssertRC(rc); 272 pThis->WakeupPipeR = NIL_RTFILE; 273 } 274 if (pThis->FileDevice != NIL_RTFILE) 275 { 276 int rc = RTFileClose(pThis->FileDevice); 277 AssertRC(rc); 278 pThis->FileDevice = NIL_RTFILE; 279 } 255 int rc; 256 257 if (pThis->hFileDevice != NIL_RTFILE) 258 ioctl(RTFileToNative(pThis->hFileDevice), PPRELEASE); 259 260 rc = RTPipeClose(pThis->hWakeupPipeW); AssertRC(rc); 261 pThis->hWakeupPipeW = NIL_RTPIPE; 262 263 rc = RTPipeClose(pThis->hWakeupPipeR); AssertRC(rc); 264 pThis->hWakeupPipeR = NIL_RTPIPE; 265 266 rc = RTFileClose(pThis->hFileDevice); AssertRC(rc); 267 pThis->hFileDevice = NIL_RTFILE; 268 280 269 if (pThis->pszDevicePath) 281 270 { … … 297 286 298 287 /* 299 * Validate the config.300 */301 if (!CFGMR3AreValuesValid(pCfg, "DevicePath\0"))302 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,303 N_("Unknown host parallel configuration option, only supports DevicePath"));304 305 /*306 288 * Init basic data members and interfaces. 307 */ 289 * 290 * Must be done before returning any failure because we've got a destructor. 291 */ 292 pThis->hFileDevice = NIL_RTFILE; 293 pThis->hWakeupPipeR = NIL_RTPIPE; 294 pThis->hWakeupPipeW = NIL_RTPIPE; 308 295 309 296 /* IBase. */ … … 318 305 319 306 /* 307 * Validate the config. 308 */ 309 if (!CFGMR3AreValuesValid(pCfg, "DevicePath\0")) 310 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, 311 N_("Unknown host parallel configuration option, only supports DevicePath")); 312 313 /* 320 314 * Query configuration. 321 315 */ … … 331 325 * Open the device 332 326 */ 333 rc = RTFileOpen(&pThis-> FileDevice, pThis->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);327 rc = RTFileOpen(&pThis->hFileDevice, pThis->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 334 328 if (RT_FAILURE(rc)) 335 329 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("Parallel#%d could not open '%s'"), … … 339 333 * Try to get exclusive access to parallel port 340 334 */ 341 rc = ioctl( pThis->FileDevice, PPEXCL);335 rc = ioctl(RTFileToNative(pThis->hFileDevice), PPEXCL); 342 336 if (rc < 0) 343 337 return PDMDrvHlpVMSetError(pDrvIns, RTErrConvertFromErrno(errno), RT_SRC_POS, … … 349 343 * Claim the parallel port 350 344 */ 351 rc = ioctl( pThis->FileDevice, PPCLAIM);345 rc = ioctl(RTFileToNative(pThis->hFileDevice), PPCLAIM); 352 346 if (rc < 0) 353 347 return PDMDrvHlpVMSetError(pDrvIns, RTErrConvertFromErrno(errno), RT_SRC_POS, … … 367 361 * Create wakeup pipe. 368 362 */ 369 int aFDs[2]; 370 if (pipe(aFDs) != 0) 371 { 372 rc = RTErrConvertFromErrno(errno); 373 AssertRC(rc); 374 return rc; 375 } 376 pThis->WakeupPipeR = aFDs[0]; 377 pThis->WakeupPipeW = aFDs[1]; 363 rc = RTPipeCreate(&pThis->hWakeupPipeR, &pThis->hWakeupPipeR, 0 /*fFlags*/); 364 AssertRCReturn(rc, rc); 378 365 379 366 /*
Note:
See TracChangeset
for help on using the changeset viewer.