/* -*- c -*- $Id: read.swg,v 1.4 2006/11/29 01:43:28 rocky Exp $ Copyright (C) 2006 Rocky Bernstein 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* See for more extensive documentation. */ %constant long int READ_MODE_AUDIO = CDIO_READ_MODE_AUDIO; %constant long int READ_MODE_M1F1 = CDIO_READ_MODE_M1F1; %constant long int READ_MODE_M1F2 = CDIO_READ_MODE_M1F2; %constant long int READ_MODE_M2F1 = CDIO_READ_MODE_M2F1; %constant long int READ_MODE_M2F2 = CDIO_READ_MODE_M2F2; %inline %{ typedef struct { char *data; size_t size; driver_return_code_t drc; } Buf_triple_t; %} %rename cdio_lseek lseek; off_t cdio_lseek(const CdIo_t *p_cdio, off_t offset, int whence=SEEK_SET); %typemap(out) Buf_triple_t { if (!$1.data) return Qnil; else { VALUE data_triple = rb_ary_new(); rb_ary_push(data_triple, rb_str_new($1.data, $1.size)); rb_ary_push(data_triple, INT2NUM($1.size)); rb_ary_push(data_triple, INT2NUM($1.drc)); free($1.data); return data_triple; } } Buf_triple_t read_cd(const CdIo_t *p_cdio, size_t i_size); %inline %{ Buf_triple_t read_cd(const CdIo_t *p_cdio, size_t i_size) { Buf_triple_t buf; buf.data = calloc(1, i_size); buf.size = cdio_read(p_cdio, buf.data, i_size); if (buf.size == -1) { free(buf.data); buf.drc = DRIVER_OP_ERROR; buf.data = NULL; } return buf; } %} /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */ Buf_triple_t read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn, cdio_read_mode_t read_mode, size_t i_size); %inline %{ /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */ Buf_triple_t read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn, cdio_read_mode_t read_mode, size_t i_size) { Buf_triple_t buf; uint32_t i_blocks; uint16_t i_blocksize; switch (read_mode) { case CDIO_READ_MODE_AUDIO: i_blocksize = CDIO_CD_FRAMESIZE_RAW; break; case CDIO_READ_MODE_M1F1: i_blocksize = M2RAW_SECTOR_SIZE; break; case CDIO_READ_MODE_M1F2: i_blocksize = M2RAW_SECTOR_SIZE; break; case CDIO_READ_MODE_M2F1: i_blocksize = CDIO_CD_FRAMESIZE; break; case CDIO_READ_MODE_M2F2: i_blocksize = M2F2_SECTOR_SIZE; break; default: buf.data = NULL; buf.drc = DRIVER_OP_BAD_PARAMETER; buf.size = -1; return buf; } buf.data = calloc(1, i_size); i_blocks = i_size / i_blocksize; buf.drc = cdio_read_sectors(p_cdio, buf.data, i_lsn, read_mode, i_blocks); if (buf.drc < 0) { free(buf.data); buf.data = NULL; buf.size = -1; } else { buf.size = i_size; } return buf; } %} Buf_triple_t read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn, int16_t i_blocksize, size_t i_size); %inline %{ Buf_triple_t read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn, int16_t i_blocksize, size_t i_size) { uint32_t i_blocks = i_size / i_blocksize; Buf_triple_t buf; switch (i_blocksize) { case CDIO_CD_FRAMESIZE: case CDIO_CD_FRAMESIZE_RAW: case M2F2_SECTOR_SIZE: case M2RAW_SECTOR_SIZE: break; default: /* Don't know about these block sizes */ buf.data = NULL; buf.drc = DRIVER_OP_BAD_PARAMETER; buf.size = -1; return buf; } buf.data = calloc(1, i_size); #if DEBUGGING printf("p_cdio: %x, i_size: %d, lsn: %d, blocksize %d, blocks %d\n", p_cdio, i_size, i_lsn, i_blocksize, i_blocks); #endif buf.drc = cdio_read_data_sectors (p_cdio, buf.data, i_lsn, i_blocksize, i_blocks); #if DEBUGGING printf("drc: %d\n", buf.drc); #endif if (buf.drc < 0) { buf.data = NULL; buf.size = -1; } else { buf.size = i_size; } return buf; } %}