2005-11-10 11:11:15 +00:00
|
|
|
/*
|
2006-01-25 07:21:52 +00:00
|
|
|
$Id: eject.cpp,v 1.6 2006/01/25 07:21:52 rocky Exp $
|
2005-11-10 11:11:15 +00:00
|
|
|
|
2006-01-18 20:58:53 +00:00
|
|
|
Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
|
2005-11-10 11:11:15 +00:00
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Simple program to eject a CD-ROM drive door and then close it again.
|
|
|
|
|
|
|
|
|
|
If a single argument is given, it is used as the CD-ROM device to
|
|
|
|
|
eject/close. Otherwise a CD-ROM drive will be scanned for.
|
2005-11-11 12:26:57 +00:00
|
|
|
|
|
|
|
|
See also corresponding C program of a similar name.
|
2005-11-10 11:11:15 +00:00
|
|
|
*/
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <cdio++/cdio.hpp>
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
|
{
|
|
|
|
|
driver_return_code_t ret;
|
|
|
|
|
driver_id_t driver_id = DRIVER_DEVICE;
|
|
|
|
|
char *psz_drive = NULL;
|
|
|
|
|
CdioDevice device;
|
|
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
|
psz_drive = strdup(argv[1]);
|
|
|
|
|
|
|
|
|
|
if (!psz_drive) {
|
2006-01-25 07:21:52 +00:00
|
|
|
psz_drive = getDefaultDevice(driver_id);
|
2005-11-10 11:11:15 +00:00
|
|
|
if (!psz_drive) {
|
2006-01-15 10:39:15 +00:00
|
|
|
printf("Can't find a CD-ROM to perform eject operation\n");
|
2005-11-10 11:11:15 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-15 10:39:15 +00:00
|
|
|
try {
|
2006-01-25 07:21:52 +00:00
|
|
|
ejectMedia(psz_drive);
|
2006-01-15 10:39:15 +00:00
|
|
|
printf("CD in CD-ROM drive %s ejected.\n", psz_drive);
|
2005-11-10 11:11:15 +00:00
|
|
|
}
|
2006-01-25 07:21:52 +00:00
|
|
|
catch ( DriverOpUninit e ) {
|
2006-01-18 20:58:53 +00:00
|
|
|
printf("Can't Eject CD from CD-ROM drive: driver is not initialized.\n",
|
2006-01-17 02:09:32 +00:00
|
|
|
psz_drive);
|
|
|
|
|
}
|
2006-01-25 07:21:52 +00:00
|
|
|
catch ( DriverOpException e ) {
|
2006-01-15 10:39:15 +00:00
|
|
|
printf("Ejecting CD from CD-ROM drive %s operation error:\n\t%s.\n",
|
|
|
|
|
psz_drive, e.get_msg());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2006-01-25 07:21:52 +00:00
|
|
|
closeTray(psz_drive);
|
2006-01-18 20:58:53 +00:00
|
|
|
printf("Closed CD-ROM %s tray.\n", psz_drive);
|
2006-01-15 10:39:15 +00:00
|
|
|
}
|
2006-01-25 07:21:52 +00:00
|
|
|
catch ( DriverOpException e ) {
|
2006-01-15 10:39:15 +00:00
|
|
|
printf("Closing CD-ROM %s tray operation error error:\n\t%s.\n",
|
|
|
|
|
psz_drive, e.get_msg());
|
2005-11-10 11:11:15 +00:00
|
|
|
}
|
|
|
|
|
free(psz_drive);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|