Debian Codegraph @

swig/read.swg

raw
1 /* -*- c -*-
2 Copyright (C) 2006, 2008, 2011 Rocky Bernstein <[email protected]>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* See <cdio/read.h> for more extensive documentation. */
18
19 %constant long int READ_MODE_AUDIO = CDIO_READ_MODE_AUDIO;
20 %constant long int READ_MODE_M1F1 = CDIO_READ_MODE_M1F1;
21 %constant long int READ_MODE_M1F2 = CDIO_READ_MODE_M1F2;
22 %constant long int READ_MODE_M2F1 = CDIO_READ_MODE_M2F1;
23 %constant long int READ_MODE_M2F2 = CDIO_READ_MODE_M2F2;
24
25 typedef int cdio_read_mode_t;
26 %inline %{
27 typedef long int my_ssize_t;
28 %}
29 %apply my_ssize_t *OUTPUT { my_ssize_t *pi_size };
30
31 %rename cdio_lseek lseek;
32 off_t cdio_lseek(const CdIo_t *p_cdio, off_t offset, int whence=SEEK_SET);
33
34 %newobject read_cd; // free malloc'd return value
35 char *read_cd(const CdIo_t *p_cdio, my_ssize_t i_size,
36 /*out*/ my_ssize_t *pi_size);
37
38 %inline %{
39 char *
40 read_cd(const CdIo_t *p_cdio, my_ssize_t i_size,
41 /*out*/ my_ssize_t *pi_size) {
42 char *p_buf = calloc(1, i_size);
43 *pi_size = cdio_read(p_cdio, p_buf, i_size);
44 return p_buf;
45 }
46 %}
47
48 typedef char * buf_t;
49 %typemap(out) buf_t {
50 /* $1 is of type buf_t */
51 ST(argvi) = sv_newmortal();
52 if (result) {
53 /* I don't yet know how to pick up arg4 another way.
54 THIS MEANS ARG4 MUST ALWAYS BE THE SIZE. */
55 sv_setpvn((SV*)ST(argvi++), (char *) result, arg4);
56 /* Don't leak memory. return value was malloc'd by libcdio. */
57 free(result);
58 } else {
59 sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
60 }
61 }
62
63 %apply long int *OUTPUT { long int *drc };
64 /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
65 buf_t read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn,
66 cdio_read_mode_t read_mode, my_ssize_t i_size,
67 /*out*/ my_ssize_t *pi_size,
68 /*out*/ long int *drc);
69
70 %inline %{
71 typedef char *buf_t;
72 /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
73 buf_t
74 read_sectors(const CdIo_t *p_cdio, lsn_t i_lsn,
75 cdio_read_mode_t read_mode, my_ssize_t i_size,
76 /*out*/ my_ssize_t *pi_size,
77 /*out*/ long int *drc)
78 {
79
80 char *p_buf;
81 uint32_t i_blocks;
82 uint16_t i_blocksize;
83 switch (read_mode) {
84 case CDIO_READ_MODE_AUDIO:
85 i_blocksize = CDIO_CD_FRAMESIZE_RAW;
86 break;
87 case CDIO_READ_MODE_M1F1:
88 i_blocksize = M2RAW_SECTOR_SIZE;
89 break;
90 case CDIO_READ_MODE_M1F2:
91 i_blocksize = M2RAW_SECTOR_SIZE;
92 break;
93 case CDIO_READ_MODE_M2F1:
94 i_blocksize = CDIO_CD_FRAMESIZE;
95 break;
96 case CDIO_READ_MODE_M2F2:
97 i_blocksize = M2F2_SECTOR_SIZE;
98 break;
99 default:
100 pi_size = NULL;
101 *drc = DRIVER_OP_BAD_PARAMETER;
102 return NULL;
103 }
104 p_buf = calloc(1, i_size);
105
106 i_blocks = i_size / i_blocksize;
107 *drc = cdio_read_sectors(p_cdio, p_buf, i_lsn, read_mode, i_blocks);
108 if (*drc < 0) {
109 pi_size = NULL;
110 return NULL;
111 }
112 *pi_size = i_size;
113 return p_buf;
114 }
115 %}
116
117 /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
118 buf_t
119 read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn, int16_t i_blocksize,
120 my_ssize_t i_size,
121 /*out*/ my_ssize_t *pi_size,
122 long int *drc);
123
124 %inline %{
125 /* NOTE: arg 4 *must* be the size of the buf for the buf_t typemap. */
126 buf_t
127 read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn,
128 int16_t i_blocksize, my_ssize_t i_size,
129 /*out*/ my_ssize_t *pi_size,
130 /*out*/ long int *drc) {
131 uint32_t i_blocks = i_size / i_blocksize;
132 char *p_buf;
133
134 switch (i_blocksize) {
135 case CDIO_CD_FRAMESIZE:
136 case CDIO_CD_FRAMESIZE_RAW:
137 case M2F2_SECTOR_SIZE:
138 case M2RAW_SECTOR_SIZE:
139 break;
140 default:
141 /* Don't know about these block sizes */
142 pi_size = NULL;
143 *drc = DRIVER_OP_BAD_PARAMETER;
144 return NULL;
145 }
146 p_buf = calloc(1, i_size);
147
148 #if DEBUGGING
149 printf("p_cdio: %x, i_size: %d, lsn: %d, blocksize %d, blocks %d\n",
150 p_cdio, i_size, i_lsn, i_blocksize, i_blocks);
151 #endif
152 *drc = cdio_read_data_sectors (p_cdio, p_buf, i_lsn,
153 i_blocksize, i_blocks);
154 #if DEBUGGING
155 printf("drc: %d\n", drc);
156 #endif
157 if (*drc < 0) {
158 pi_size = NULL;
159 return NULL;
160 }
161 *pi_size = i_size;
162 return p_buf;
163 }
164 %}
165
166 iso9660_pvd_t *cdio_read_pvd ( const CdIo_t *p_cdio );
167 %inline %{
168 iso9660_pvd_t *cdio_read_pvd ( const CdIo_t *p_cdio ) {
169 static iso9660_pvd_t pvd;
170 int rc = cdio_read_data_sectors( p_cdio, &pvd, ISO_PVD_SECTOR,
171 ISO_BLOCKSIZE, 1);
172 if (rc < 0) return NULL;
173 return &pvd;
174 }
175 %}
176