// Called by PollLoop() and CDVDgetTrayStatus() s32 DeviceTrayStatus() { s32 s32result; errno = 0; #ifdef VERBOSE_FUNCTION_DEVICE PrintLog("CDVD device: DeviceTrayStatus()"); #endif /* VERBOSE_FUNCTION_DEVICE */ if (devicehandle == -1) return (-1); // ENDIF- Someone forget to open the device? if ((devicecapability & CDC_DRIVE_STATUS) != 0) { s32result = ioctl(devicehandle, CDROM_DRIVE_STATUS); if (s32result < 0) { #ifdef VERBOSE_WARNINGS PrintLog("CDVD device: Trouble reading Drive Status!"); PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ s32result = CDS_TRAY_OPEN; } // ENDIF- Failure to get status? Assume it's open. errno = 0; } else { s32result = ioctl(devicehandle, CDROM_DISC_STATUS); if (errno != 0) { #ifdef VERBOSE_WARNINGS PrintLog("CDVD device: Trouble detecting Disc Status presense!"); PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno)); #endif /* VERBOSE_WARNINGS */ s32result = CDS_TRAY_OPEN; errno = 0; } // ENDIF- Trouble? if (s32result == CDS_NO_DISC) s32result = CDS_TRAY_OPEN; // ENDIF- Is there no disc in the device? Guess the tray is open } // ENDIF- Can we poll the tray directly? (Or look at disc status instead?) if (s32result == CDS_TRAY_OPEN) { traystatus = CDVD_TRAY_OPEN; if (disctype != CDVD_TYPE_NODISC) { DeviceClose(); // Kind of severe way of flushing all buffers. DeviceOpen(); InitDisc(); } // ENDIF- Tray just opened... clear disc info } else { traystatus = CDVD_TRAY_CLOSE; if (disctype == CDVD_TYPE_NODISC) DeviceGetDiskType(); // ENDIF- Tray just closed? Get disc information } // ENDIF- Do we detect an open tray? return (traystatus); } // END CDVD_getTrayStatus()
s32 DeviceTrayStatus() { BOOL boolresult; if(devicehandle == NULL) return(-1); if(devicehandle == INVALID_HANDLE_VALUE) return(-1); #ifdef VERBOSE_FUNCTION_DEVICE PrintLog("CDVDlinuz device: DeviceTrayStatus()"); #endif /* VERBOSE_FUNCTION_DEVICE */ switch(traystatusmethod) { case 1: boolresult = DeviceTrayStatusStorage(); break; case 2: boolresult = DeviceTrayStatusCDRom(); break; case 3: boolresult = DeviceTrayStatusDisk(); break; default: boolresult = FALSE; break; } // ENDSWITCH traystatusmethod- One method already working? Try it again. if(boolresult == FALSE) { traystatusmethod = 0; boolresult = DeviceTrayStatusStorage(); if(boolresult == TRUE) { traystatusmethod = 1; } else { boolresult = DeviceTrayStatusCDRom(); if(boolresult == TRUE) { traystatusmethod = 2; } else { boolresult = DeviceTrayStatusDisk(); if(boolresult == TRUE) traystatusmethod = 3; } // ENDIF- Did we succeed with CDRom? } // ENDIF- Did we succeed with Storage? } // Single call to already working test just failed? Test them all. if(boolresult == FALSE) { if(traystatus == CDVD_TRAY_CLOSE) { #ifdef VERBOSE_FUNCTION_DEVICE PrintLog("CDVDlinuz device: Tray just opened!"); #endif /* VERBOSE_FUNCTION_DEVICE */ traystatus = CDVD_TRAY_OPEN; DeviceClose(); DeviceOpen(); InitDisc(); } // ENDIF- Just opened? clear disc info return(traystatus); } // ENDIF- Still failed? Assume no disc in drive then. if(traystatus == CDVD_TRAY_OPEN) { traystatus = CDVD_TRAY_CLOSE; #ifdef VERBOSE_FUNCTION_DEVICE PrintLog("CDVDlinuz device: Tray just closed!"); #endif /* VERBOSE_FUNCTION_DEVICE */ DeviceGetDiskType(); return(traystatus); } // ENDIF- Just closed? Get disc information return(traystatus); } // END DeviceTrayStatus()