ext/CdIo_Cd.c in rb_cdio-0.1.0 vs ext/CdIo_Cd.c in rb_cdio-0.1.1
- old
+ new
@@ -6,62 +6,33 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
- * Definici?n de funciones para CdIo::Cd
+ * Implementation of CdIo::Cd
*/
#include "CdIo.h"
// Libera el puntero al objeto CdIo creado en Cd.new
+/**
+* Free resources for CdIo* in CdIo::Cd
+*/
static void
_cdio_cd_destroy(void *p)
{
+
/*
- static int i;
- printf("\nDestruyendo cdio %d\n",i++);
- */
+ * static int i; printf("\nDestruyendo cdio %d\n",i++);
+ */
cdio_destroy(p);
}
-// lanza true si el tipo de disco es un ISO9660
-static bool
-_cdio_cd_is_iso(CdIo * p_cdio, track_t track)
-{
- cdio_fs_anal_t fs;
- cdio_iso_analysis_t iso_analysis;
- fs = cdio_guess_cd_type(p_cdio, 0, track, &iso_analysis);
- switch (CDIO_FSTYPE(fs)) {
- case CDIO_FS_ISO_9660:
- case CDIO_FS_ISO_9660_INTERACTIVE:
- case CDIO_FS_ISO_HFS:
- case CDIO_FS_ISO_UDF:
- return true;
- default:
- return false;
- }
-}
-/*
- * Devuelve un objeto CdIo::Track o de una subclase, a partir de un objeto
- * Cd y un n?mero de pista
- */
-static VALUE
-_track_by_type(VALUE obj, track_t i)
-{
- GET_CDIO(obj, p_cdio);
- VALUE track;
- if (_cdio_cd_is_iso(p_cdio, i)) {
- track = rb_cdio_trackiso9660_new(obj, i);
- } else {
- track = rb_cdio_track_new(obj, i);
- }
- return track;
-}
+
/**
* CDDB
* Extraido desde cd-info.
**/
@@ -108,12 +79,16 @@
return ((n % 0xff) << 24 | t << 8 | i_tracks);
}
/**
-* Constructor
-* CdIo::Cd.new
+ Create a new Cd::CdIo object.
+ The first argument is an String for a device or a cue/bin/toc/nrg file
+ The seconf argument is the constant for a Driver (default CdIo::DRIVER_UNKNOWN)
+ * CdIo::Cd.new()
+ * CdIo::Cd.new("/dev/cdrom")
+ * CdIo::Cd.new("/dev/cdrom", CdIo::DRIVER_UNKNOWN)
*/
VALUE
rb_cdio_cd_new(int argc, VALUE * argv, VALUE class)
{
@@ -140,11 +115,11 @@
}
}
p_cdio = cdio_open(device, driver);
if (p_cdio == NULL) {
- rb_raise(rb_eException, "I can't create a pointer");
+ rb_raise(rb_eException, "I can't create a pointer");
return Qnil;
} else {
VALUE c_argv[2];
VALUE tdata =
Data_Wrap_Struct(class, 0, _cdio_cd_destroy, p_cdio);
@@ -154,11 +129,14 @@
return tdata;
}
}
/**
-* CdIo::Cd.initialize
+CdIo::Cd.initialize
+Initialize the CdIo::Cd object
+ The first argument is an String for a device or a cue/bin/toc/nrg file
+ The seconf argument is the constant for a driver
*/
VALUE
rb_cdio_cd_init(VALUE self, VALUE device, VALUE driver)
{
@@ -200,15 +178,19 @@
}
return self;
}
/**
-* CdIo::Cd.get_tracks
+* Returns an array with the tracks of the cd
+* cd.get_tracks #=> [<CdIo::Track>,<CdIo::Track>]
*/
VALUE
rb_cdio_cd_get_tracks(VALUE self)
{
+ VALUE argv[1];
+ argv[0] = self;
+ return rb_class_new_instance(1, argv, cCdIoTracks);
VALUE aTracks;
aTracks = rb_ary_new();
GET_CDIO(self, p_cdio);
track_t first_track_num;
track_t num_tracks;
@@ -217,11 +199,11 @@
// printf("C->Primera pista: %d\n",first_track_num);
// printf("C->Numero pistas: %d\n",num_tracks);
int j,
i = first_track_num;
for (j = 0; j < num_tracks; i++, j++) {
- rb_ary_push(aTracks, _track_by_type(self, i));
+ rb_ary_push(aTracks, get_track(self, i));
}
return aTracks;
}
/**
@@ -230,11 +212,11 @@
VALUE
rb_cdio_cd_get_first_track(VALUE self)
{
GET_CDIO(self, p_cdio);
track_t first_track_num = cdio_get_first_track_num(p_cdio);
- return _track_by_type(self, first_track_num);
+ return get_track(self, first_track_num);
}
/**
* CdIo::Cd.get_arg
*/
@@ -262,21 +244,21 @@
{
GET_CDIO(obj, p_cdio);
return (discmode_is_dvd(cdio_get_discmode(p_cdio))) ? Qtrue : Qfalse;
}
-static VALUE
+static VALUE
_get_freedb(VALUE obj)
{
rb_require("freedb");
VALUE cFreeDb =
rb_const_get(rb_mKernel, rb_intern("Freedb"));
return rb_funcall(cFreeDb, rb_intern("new"), 1,
rb_iv_get(obj, "@device"));
}
-static VALUE
+static VALUE
_get_freedb_error(VALUE obj, VALUE error_info)
{
rb_raise(rb_eLoadError,
"Please, install ruby-freedb to use this function");
return Qnil;
@@ -329,17 +311,18 @@
}
VALUE
rb_cdio_cd_close(VALUE obj)
{
- /*
- * Nothing to do
- */
+ rb_gc_start();
+ obj = Qnil;
return Qnil;
}
-VALUE rb_cdio_cd_get_cdtext(VALUE obj) {
- GET_CDIO(obj,p_cdio);
- const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
+VALUE
+rb_cdio_cd_get_cdtext(VALUE obj)
+{
+ GET_CDIO(obj, p_cdio);
+ const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
return get_cdtext(cdtext);
}