ext/CdIo_Common.c in rb_cdio-0.1.1 vs ext/CdIo_Common.c in rb_cdio-0.2.0
- old
+ new
@@ -22,10 +22,11 @@
misc = rb_hash_new();
ret = rb_hash_new();
rb_hash_aset(ret, rb_str_new2("read"), read);
rb_hash_aset(ret, rb_str_new2("write"), write);
rb_hash_aset(ret, rb_str_new2("misc"), misc);
+ // read
CAP(read, "audio", read_cap, CDIO_DRIVE_CAP_READ_AUDIO);
CAP(read, "cd-da", read_cap, CDIO_DRIVE_CAP_READ_CD_DA);
CAP(read, "cd+g", read_cap, CDIO_DRIVE_CAP_READ_CD_G);
CAP(read, "cd-r", read_cap, CDIO_DRIVE_CAP_READ_CD_R);
CAP(read, "cd-rw", read_cap, CDIO_DRIVE_CAP_READ_CD_RW);
@@ -34,10 +35,16 @@
CAP(read, "dvd-ram", read_cap, CDIO_DRIVE_CAP_READ_DVD_RAM);
CAP(read, "dvd-rom", read_cap, CDIO_DRIVE_CAP_READ_DVD_ROM);
CAP(read, "dvd-rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RW);
CAP(read, "dvd+rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RPW);
CAP(read, "c2_errs", read_cap, CDIO_DRIVE_CAP_READ_C2_ERRS);
+ CAP(read, "mode2_form1", read_cap, CDIO_DRIVE_CAP_READ_MODE2_FORM1);
+ CAP(read, "mode2_form2", read_cap, CDIO_DRIVE_CAP_READ_MODE2_FORM2);
+ CAP(read, "mcn", read_cap, CDIO_DRIVE_CAP_READ_MCN);
+ CAP(read, "isrc", read_cap, CDIO_DRIVE_CAP_READ_ISRC);
+
+ // write
CAP(write, "cd-r", write_cap, CDIO_DRIVE_CAP_WRITE_CD_R);
CAP(write, "cd-rw", write_cap, CDIO_DRIVE_CAP_WRITE_CD_RW);
CAP(write, "dvd-r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_R);
CAP(write, "dvd+r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_PR);
CAP(write, "dvd-ram", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RAM);
@@ -46,22 +53,21 @@
CAP(write, "mount_rainier", write_cap,
CDIO_DRIVE_CAP_WRITE_MT_RAINIER);
CAP(write, "burn_proof", write_cap, CDIO_DRIVE_CAP_WRITE_BURN_PROOF);
CAP(write, "cd", write_cap, CDIO_DRIVE_CAP_WRITE_CD);
CAP(write, "dvd", write_cap, CDIO_DRIVE_CAP_WRITE_DVD);
+ // misc
CAP(misc, "close_tray", misc_cap, CDIO_DRIVE_CAP_MISC_CLOSE_TRAY);
CAP(misc, "eject", misc_cap, CDIO_DRIVE_CAP_MISC_EJECT);
CAP(misc, "lock", misc_cap, CDIO_DRIVE_CAP_MISC_LOCK);
CAP(misc, "select_speed", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_SPEED);
CAP(misc, "select_disk", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_DISC);
CAP(misc, "multi_session", misc_cap,
CDIO_DRIVE_CAP_MISC_MULTI_SESSION);
CAP(misc, "media_changed", misc_cap,
CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED);
- CAP(misc, "misc_reset", misc_cap, CDIO_DRIVE_CAP_MISC_RESET);
- CAP(misc, "mcn", misc_cap, CDIO_DRIVE_CAP_MCN);
- CAP(misc, "isrc", misc_cap, CDIO_DRIVE_CAP_ISRC);
+ CAP(misc, "reset", misc_cap, CDIO_DRIVE_CAP_MISC_RESET);
CAP(misc, "file", misc_cap, CDIO_DRIVE_CAP_MISC_FILE);
return ret;
}
#undef CAP
@@ -113,16 +119,55 @@
* @param track
* @return CdIo::Track
*/
VALUE
-get_track(VALUE obj, track_t i)
+get_track(VALUE cd, track_t i)
{
- GET_CDIO(obj, p_cdio);
+ GET_CDIO(cd, p_cdio);
+ // printf("get_track 1:%d\n",i);
VALUE track;
+ track_format_t format = cdio_get_track_format(p_cdio, i);
+ VALUE argv[2];
+ argv[0] = cd;
+ argv[1] = INT2FIX(i);
+ // printf("get_track 2:%d\n",FIX2INT(argv[1]));
+
if (_cdio_cd_is_iso(p_cdio, i)) {
- track = rb_cdio_trackiso9660_new(obj, i);
+ return rb_class_new_instance(2, argv, cCdIoTrackIso9660);
+ } else if (TRACK_FORMAT_AUDIO == format) {
+ return rb_class_new_instance(2, argv, cCdIoTrackCdda);
} else {
- track = rb_cdio_track_new(obj, i);
+ return rb_class_new_instance(2, argv, cCdIoTrack);
}
- return track;
+}
+void
+verify_return_code(driver_return_code_t rc)
+{
+ switch (rc) {
+ case DRIVER_OP_SUCCESS:
+ break;
+ case DRIVER_OP_ERROR:
+ rb_raise(eCdIoError, "Operation returned an error");
+ break;
+ case DRIVER_OP_UNSUPPORTED:
+ rb_raise(eCdIoUnsupported, "Driver doesn't support feature");
+ break;
+ case DRIVER_OP_UNINIT:
+ rb_raise(eCdIoUnitit, "driver hasn't been initialized");
+ break;
+ case DRIVER_OP_NOT_PERMITTED:
+ rb_raise(eCdIoNotPermitted, "Operation not permitted.");
+ break;
+ case DRIVER_OP_BAD_PARAMETER:
+ rb_raise(eCdIoBadParameter,
+ "Bad parameter (library bug, probably)");
+ break;
+ case DRIVER_OP_BAD_POINTER:
+ rb_raise(eCdIoBadPointer, "Bad pointer (library bug, probably)");
+ break;
+ case DRIVER_OP_NO_DRIVER:
+ rb_raise(eCdIoNoDriver,
+ "Operaton called on a driver not available on this OS");
+ break;
+ }
}