First cut at a C++ wrapper for libcdio libcdio++. What's not done are

audio and MMC commands. No doubt it may be a little rough and I expect
further changes.
This commit is contained in:
rocky
2005-11-10 11:11:15 +00:00
parent 5b12ddaeb4
commit d7dd4a6c8a
20 changed files with 1781 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.6 2005/11/07 07:53:40 rocky Exp $
# $Id: Makefile.am,v 1.7 2005/11/10 11:11:15 rocky Exp $
#
# Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
#
@@ -16,10 +16,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
####################################################
# Things to regression testing
####################################################
##########################################################
# Sample C++ programs using libcdio (without OO wrapper)
#########################################################
#
SUBDIRS = OO
if BUILD_CD_PARANOIA
paranoia_progs = paranoia paranoia2
endif
@@ -52,9 +54,11 @@ iso3_SOURCES = iso3.cpp
iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
mmc1_SOURCES = mmc1.cpp
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
mmc1_LDADD = $(LIBCDIO_LIBS)
mmc2_SOURCES = mmc2.cpp
mmc2_DEPENDENCIES = $(LIBCDIO_DEPS)
mmc2_LDADD = $(LIBCDIO_LIBS)
# iso programs create file "copying"

View File

@@ -0,0 +1,9 @@
.deps
.libs
Makefile
Makefile.am
Makefile.in
cdtext
device
eject
tracks

94
example/C++/OO/cdtext.cpp Normal file
View File

@@ -0,0 +1,94 @@
/*
$Id: cdtext.cpp,v 1.1 2005/11/10 11:11:15 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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 list CD-Text info of a Compact Disc using libcdio. */
#include <stdio.h>
#include <sys/types.h>
#include <cdio++/cdio.hpp>
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
#define CDDA_IMAGE_PATH "../../../test/"
#define CDDA_IMAGE CDDA_IMAGE_PATH "cdda.cue"
static void
print_cdtext_track_info(CdioDevice *device, track_t i_track,
const char *psz_msg) {
cdtext_t *cdtext = device->getCdtext(0);
if (NULL != cdtext) {
cdtext_field_t i;
int j=0;
printf("%s\n", psz_msg);
for (j=0; j < MAX_CDTEXT_FIELDS; j++) {
i = (cdtext_field_t) j;
if (cdtext->field[i]) {
printf("\t%s: %s\n", cdtext_field2str(i), cdtext->field[i]);
}
}
}
}
static void
print_disc_info(CdioDevice *device, track_t i_tracks, track_t i_first_track) {
track_t i_last_track = i_first_track+i_tracks;
discmode_t cd_discmode = device->getDiscmode();
printf("%s\n", discmode2str[cd_discmode]);
print_cdtext_track_info(device, 0, "\nCD-Text for Disc:");
for ( ; i_first_track < i_last_track; i_first_track++ ) {
char psz_msg[50];
sprintf(psz_msg, "CD-Text for Track %d:", i_first_track);
print_cdtext_track_info(device, i_first_track, psz_msg);
}
}
int
main(int argc, const char *argv[])
{
track_t i_first_track;
track_t i_tracks;
CdioDevice *device = new CdioDevice;
const char *psz_drive = NULL;
if (!device->open(CDDA_IMAGE, DRIVER_BINCUE)) {
printf("Couldn't open " CDDA_IMAGE " with BIN/CUE driver.\n");
} else {
i_first_track = device->getFirstTrackNum();
i_tracks = device->getNumTracks();
print_disc_info(device, i_tracks, i_first_track);
}
if (argc > 1) psz_drive = argv[1];
if (!device->open(psz_drive, DRIVER_DEVICE)) {
printf("Couldn't find CD\n");
return 1;
} else {
i_first_track = device->getFirstTrackNum();
i_tracks = device->getNumTracks();
print_disc_info(device, i_tracks, i_first_track);
}
delete(device);
return 0;
}

127
example/C++/OO/device.cpp Normal file
View File

@@ -0,0 +1,127 @@
/*
$Id: device.cpp,v 1.1 2005/11/10 11:11:15 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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 show drivers installed and what the default
CD-ROM drive is. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <cdio++/cdio.hpp>
#define _(x) x
/* Prints out drive capabilities */
static void
print_drive_capabilities(cdio_drive_read_cap_t i_read_cap,
cdio_drive_write_cap_t i_write_cap,
cdio_drive_misc_cap_t i_misc_cap)
{
if (CDIO_DRIVE_CAP_ERROR == i_misc_cap) {
printf("Error in getting drive hardware properties\n");
} else {
printf(_("Hardware : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_FILE
? "Disk Image" : "CD-ROM or DVD");
printf(_("Can eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_EJECT ? "Yes" : "No");
printf(_("Can close tray : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_CLOSE_TRAY ? "Yes" : "No");
printf(_("Can disable manual eject : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_LOCK ? "Yes" : "No");
printf(_("Can select juke-box disc : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_DISC ? "Yes" : "No");
printf(_("Can set drive speed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_SPEED ? "Yes" : "No");
printf(_("Can detect if CD changed : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED ? "Yes" : "No");
printf(_("Can read multiple sessions : %s\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_MULTI_SESSION ? "Yes" : "No");
printf(_("Can hard reset device : %s\n\n"),
i_misc_cap & CDIO_DRIVE_CAP_MISC_RESET ? "Yes" : "No");
}
if (CDIO_DRIVE_CAP_ERROR == i_read_cap) {
printf("Error in getting drive reading properties\n");
} else {
printf("Reading....\n");
printf(_(" Can play audio : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_AUDIO ? "Yes" : "No");
printf(_(" Can read CD-R : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_R ? "Yes" : "No");
printf(_(" Can read CD-RW : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
printf(_(" Can read DVD-ROM : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_DVD_ROM ? "Yes" : "No");
}
if (CDIO_DRIVE_CAP_ERROR == i_write_cap) {
printf("Error in getting drive writing properties\n");
} else {
printf("\nWriting....\n");
printf(_(" Can write CD-RW : %s\n"),
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
printf(_(" Can write DVD-R : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_R ? "Yes" : "No");
printf(_(" Can write DVD-RAM : %s\n"),
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_RAM ? "Yes" : "No");
}
}
int
main(int argc, const char *argv[])
{
CdioDevice device;
if (device.open(NULL)) {
char *default_device = device.getDefaultDevice();
cdio_drive_read_cap_t i_read_cap;
cdio_drive_write_cap_t i_write_cap;
cdio_drive_misc_cap_t i_misc_cap;
printf("The driver selected is %s\n", device.getDriverName());
if (default_device)
printf("The default device for this driver is %s\n", default_device);
device.getDriveCap(i_read_cap, i_write_cap, i_misc_cap);
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
free(default_device);
printf("\n");
} else {
printf("Problem in trying to find a driver.\n\n");
}
}

79
example/C++/OO/eject.cpp Normal file
View File

@@ -0,0 +1,79 @@
/*
$Id: eject.cpp,v 1.1 2005/11/10 11:11:15 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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.
*/
#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) {
psz_drive = device.getDefaultDevice(driver_id);
if (!psz_drive) {
printf("Can't find a CD-ROM to eject\n");
exit(1);
}
}
ret = device.ejectMedia(psz_drive);
switch(ret) {
case DRIVER_OP_UNSUPPORTED:
printf("Eject not supported for %s.\n", psz_drive);
break;
case DRIVER_OP_SUCCESS:
printf("CD-ROM drive %s ejected.\n", psz_drive);
break;
default:
printf("Eject of CD-ROM drive %s failed.\n", psz_drive);
break;
}
if (DRIVER_OP_SUCCESS == device.closeTray(psz_drive, driver_id)) {
printf("Closed tray of CD-ROM drive %s.\n", psz_drive);
} else {
printf("Closing tray of CD-ROM drive %s failed.\n", psz_drive);
}
free(psz_drive);
return 0;
}

65
example/C++/OO/tracks.cpp Normal file
View File

@@ -0,0 +1,65 @@
/*
$Id: tracks.cpp,v 1.1 2005/11/10 11:11:15 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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 list track numbers and logical sector numbers of
a Compact Disc using libcdio. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <cdio++/cdio.hpp>
int
main(int argc, const char *argv[])
{
CdioDevice device;
track_t i_first_track;
track_t i_tracks;
int j, i;
CdioTrack *track;
if (!device.open (NULL)) {
printf("Couldn't find a driver.. leaving.\n");
return 1;
}
i_tracks = device.getNumTracks();
i_first_track = i = device.getFirstTrackNum();
printf("CD-ROM Track List (%i - %i)\n", i_first_track, i_tracks);
printf(" #: LSN\n");
for (j = 0; j < i_tracks; i++, j++) {
track = device.getTrackFromNum(i);
lsn_t lsn = track->getLsn();
if (CDIO_INVALID_LSN != lsn)
printf("%3d: %06lu\n", (int) i, (long unsigned int) lsn);
delete(track);
}
track = device.getTrackFromNum(CDIO_CDROM_LEADOUT_TRACK);
printf("%3X: %06lu leadout\n", CDIO_CDROM_LEADOUT_TRACK,
(long unsigned int) track->getLsn());
delete(track);
return 0;
}