Debian Codegraph @

swig/device.swg

raw
1 /* -*- c -*-
2 Copyright (C) 2006, 2008, 2011, 2012 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/device.h> for more extensive documentation. */
18
19 %include "device_const.swg"
20
21 /* Set up to allow functions to return device lists of type "char
22 *". We'll use a typedef so we can make sure to isolate this. I
23 *don't think we need to in this program, but it I think it makes
24 *thing clearer.
25 */
26 %inline %{
27 typedef char ** DeviceList_t;
28 %}
29
30 %typemap(out) DeviceList_t {
31 /* char ** to array SVp*/
32 /*
33 AV *myav;
34 SV **svs;
35 int i = 0,len = 0;
36 */
37 /* Figure out how many elements we have */
38 /*
39 while ($1[len])
40 len++;
41 svs = (SV **) malloc(len*sizeof(SV *));
42 for (i = 0; i < len ; i++) {
43 svs[i] = sv_newmortal();
44 sv_setpv((SV*)svs[i],$1[i]);
45 //svs[i] = sv_2mortal((SV*)newSVpv($1[i], 0));
46 };
47 myav = av_make(len,svs);
48 free(svs);
49 $result = newRV_noinc((SV*)myav);
50 sv_2mortal($result);
51 */
52 // or: shorter version
53 AV *myav;
54 int i =0;
55 myav = newAV();
56 char **p = $1;
57 while (*p) {
58 av_store(myav, i, (SV*)newSVpv(*p, 0));
59 i++;p++;
60 }
61 $result = newRV_noinc((SV*)myav);
62 sv_2mortal($result);
63 argvi++;
64 cdio_free_device_list($1);
65 }
66
67 /*
68 close_tray(drive=undef, driver_id=DRIVER_UNKNOWN) -> [status, driver_id]
69
70 close media tray in CD drive if there is a routine to do so.
71 */
72 %apply driver_id_t *OUTPUT { driver_id_t *p_out_driver_id };
73 driver_return_code_t close_tray(const char *psz_drive,
74 driver_id_t p_driver_id,
75 driver_id_t *p_out_driver_id);
76 %inline %{
77 driver_return_code_t
78 close_tray(const char *psz_drive, driver_id_t p_driver_id,
79 driver_id_t *p_out_driver_id)
80 {
81 *p_out_driver_id = p_driver_id;
82 return cdio_close_tray(psz_drive, p_out_driver_id);
83 }
84 %}
85
86
87 %rename cdio_destroy close;
88 /*
89 destroy(p_cdio)
90 ree resources associated with p_cdio. Call this when done using
91 sing CD reading/control operations for the current device.
92 */
93 void cdio_destroy(CdIo_t *p_cdio);
94
95 /* cdio_driver_errmsg first appears in 0.77 code
96 */
97 %rename cdio_driver_errmsg driver_errmsg;
98 /*!
99 @param drc the return code you want interpreted.
100 @return the string information about drc
101 */
102 const char *cdio_driver_errmsg(driver_return_code_t drc);
103 /*
104 eject_media(cdio)->return_code
105
106 Eject media in CD drive if there is a routine to do so.
107 */
108 driver_return_code_t eject_media (CdIo_t *p_cdio);
109 %inline %{
110 driver_return_code_t
111
112 eject_media (CdIo_t *p_cdio)
113 {
114 /* libcdio routines uses a Cdio_t **p_cdio, so we have to pass in
115 something it can clobber.
116 */
117 CdIo_t **pp_cdio = &p_cdio;
118 return cdio_eject_media (pp_cdio);
119 }
120 %}
121
122
123 %rename cdio_eject_media_drive eject_media_drive;
124 /*
125 eject_media_drive(drive=None)->return_code
126 Eject media in CD drive if there is a routine to do so.
127
128 psz_drive: the name of the device to be acted upon.
129 The operation status is returned.
130 */
131 driver_return_code_t cdio_eject_media_drive (const char *psz_drive=NULL);
132
133 %rename cdio_get_arg get_arg;
134 /*
135 get_arg(p_cdio, key)->string
136
137 Get the value associatied with key.
138 */
139 const char *cdio_get_arg (const CdIo_t *p_cdio, const char key[]);
140
141 %newobject cdio_get_default_device; // free malloc'd return value
142 %rename cdio_get_default_device get_device;
143 /*
144 get_device(cdio)->str
145
146 Get the CD device associated with cdio.
147 If cdio is NULL (we haven't initialized a specific device driver),
148 then find a suitable one and return the default device for that.
149
150 In some situations of drivers or OS's we can't find a CD device if
151 there is no media in it and it is possible for this routine to return
152 None even though there may be a hardware CD-ROM.
153 */
154 char *cdio_get_default_device (const CdIo_t *p_cdio=NULL);
155
156 %newobject get_default_device_driver; // free malloc'd return value
157 /*
158 get_default_device_driver(driver_id=None)->[device, driver]
159 Return a string containing the default CD device if none is specified.
160 if p_driver_id is DRIVER_UNKNOWN or DRIVER_DEVICE then find a suitable
161 one set the default device for that.
162
163 undef is returned as the device if we couldn't get a default device.
164 */
165 char *get_default_device_driver (driver_id_t p_driver_id,
166 driver_id_t *p_out_driver_id);
167 %inline %{
168 char *
169 get_default_device_driver(driver_id_t driver_id, driver_id_t *p_out_driver_id)
170 {
171 *p_out_driver_id = driver_id;
172 return cdio_get_default_device_driver(p_out_driver_id);
173 }
174 %}
175
176 //%rename cdio_get_devices get_devices;
177 /*! Return an array of device names. If you want a specific
178 devices for a driver, give that device. If you want hardware
179 devices, give DRIVER_DEVICE and if you want all possible devices,
180 image drivers and hardware drivers give DRIVER_UNKNOWN.
181
182 NULL is returned if we couldn't return a list of devices.
183
184 In some situations of drivers or OS's we can't find a CD device if
185 there is no media in it and it is possible for this routine to return
186 NULL even though there may be a hardware CD-ROM.
187 */
188 DeviceList_t cdio_get_devices (driver_id_t driver_id);
189
190 DeviceList_t get_devices(driver_id_t driver_id);
191
192
193 %inline %{
194 DeviceList_t get_devices(driver_id_t driver_id) {
195 return cdio_get_devices(driver_id);
196 }
197 %}
198 /* Like cdio_get_devices, but we may change the p_driver_id if we
199 were given DRIVER_DEVICE or DRIVER_UNKNOWN. This is because
200 often one wants to get a drive name and then *open* it
201 afterwards. Giving the driver back facilitates this, and speeds
202 things up for libcdio as well.
203 */
204
205 DeviceList_t get_devices_ret (driver_id_t driver_id,
206 driver_id_t *p_out_driver_id);
207 %inline %{
208 DeviceList_t get_devices_ret (driver_id_t driver_id,
209 driver_id_t *p_out_driver_id) {
210 *p_out_driver_id = driver_id;
211 return cdio_get_devices_ret (p_out_driver_id);
212 }
213 %}
214
215 /*
216 Get an array of device names in search_devices that have at least
217 the capabilities listed by the capabities parameter.
218
219 If "b_any" is set false then every capability listed in the
220 extended portion of capabilities (i.e. not the basic filesystem)
221 must be satisfied. If "any" is set true, then if any of the
222 capabilities matches, we call that a success.
223
224 To find a CD-drive of any type, use the mask CDIO_FS_MATCH_ALL.
225
226 The array of device names is returned or NULL if we couldn't get a
227 default device. It is also possible to return a non NULL but after
228 dereferencing the the value is NULL. This also means nothing was
229 found.
230 */
231 DeviceList_t get_devices_with_cap (unsigned int capabilities, bool b_any);
232 %inline %{
233 DeviceList_t
234 get_devices_with_cap (unsigned int capabilities, bool b_any) {
235 return cdio_get_devices_with_cap (NULL, (cdio_fs_anal_t) capabilities,
236 b_any);
237 }
238 %}
239
240 %apply driver_id_t *OUTPUT { driver_id_t *p_out_driver_id };
241 /*
242 Like cdio_get_devices_with_cap but we return the driver we found
243 as well. This is because often one wants to search for kind of drive
244 and then *open* it afterwards. Giving the driver back facilitates this,
245 and speeds things up for libcdio as well.
246 */
247 DeviceList_t get_devices_with_cap_ret (unsigned int capabilities, bool b_any,
248 driver_id_t *p_out_driver_id);
249 %inline %{
250 DeviceList_t
251 get_devices_with_cap_ret (unsigned int capabilities, bool b_any,
252 driver_id_t *p_out_driver_id) {
253 return cdio_get_devices_with_cap_ret (NULL,
254 (cdio_fs_anal_t) capabilities, b_any,
255 p_out_driver_id);
256 }
257 %}
258
259 %rename cdio_get_drive_cap get_drive_cap;
260 %feature("autodoc",
261 "get_drive_cap()->(read_cap, write_cap, misc_cap)
262
263 Get drive capabilities of device.
264
265 In some situations of drivers or OS's we can't find a CD device if
266 there is no media in it. In this situation capabilities will show up as
267 empty even though there is a hardware CD-ROM.");
268 %apply uint32_t *OUTPUT { uint32_t *p_read_cap,
269 uint32_t *p_write_cap,
270 uint32_t *p_misc_cap };
271 void cdio_get_drive_cap (const CdIo_t *p_cdio,
272 uint32_t *p_read_cap,
273 uint32_t *p_write_cap,
274 uint32_t *p_misc_cap);
275
276 %rename cdio_get_drive_cap_dev get_drive_cap;
277 %feature("autodoc",
278 "get_drive_cap_dev()->(read_cap, write_cap, misc_cap)
279
280 Get drive capabilities of device.
281
282 In some situations of drivers or OS's we can't find a CD device if
283 there is no media in it. In this situation capabilities will show up as
284 empty even though there is a hardware CD-ROM.");
285
286 void cdio_get_drive_cap_dev(const char *device=NULL,
287 uint32_t *p_read_cap,
288 uint32_t *p_write_cap,
289 uint32_t *p_misc_cap);
290
291 %rename cdio_get_driver_name get_driver_name;
292 %feature("autodoc",
293 "get_driver_name(cdio)-> string
294
295 return a string containing the name of the driver in use.
296 ");
297 const char *cdio_get_driver_name (const CdIo_t *p_cdio);
298
299 %rename cdio_get_driver_id get_driver_id;
300 %feature("autodoc",
301 "get_driver_id(cdio)-> int
302
303 Return the driver id of the driver in use.
304 if cdio has not been initialized or is None,
305 return pycdio.DRIVER_UNKNOWN.");
306 driver_id_t cdio_get_driver_id (const CdIo_t *p_cdio);
307
308 %rename cdio_get_last_session get_last_session;
309 %apply int32_t *OUTPUT { lsn_t *i_last_session };
310 driver_return_code_t cdio_get_last_session (CdIo_t *p_cdio,
311 lsn_t *i_last_session);
312
313 %feature("autodoc",
314 "have_driver(driver_id) -> int
315
316 Return 1 if we have driver driver_id, 0 if not.");
317 %inline %{
318 int
319 have_driver (unsigned int driver_id)
320 {
321 if (cdio_have_driver(driver_id)) return 1;
322 return 0;
323 }
324 %}
325
326 %feature("autodoc",
327 "have_ATAPI(CdIo_t *p_cdio)->bool
328 return True if CD-ROM understand ATAPI commands.");
329 %inline %{
330 /*! True if CD-ROM understand ATAPI commands. */
331 bool
332 have_ATAPI (CdIo_t *p_cdio)
333 {
334 return cdio_have_atapi(p_cdio) == yep;
335 }
336 %}
337
338 %newobject cdio_is_binfile; // free malloc'd return value
339 %rename cdio_is_binfile is_binfile;
340 char *cdio_is_binfile(const char *bin_name);
341
342 %newobject cdio_is_cuefile; // free malloc'd return value
343 %rename cdio_is_cuefile is_cuefile;
344 char *cdio_is_cuefile(const char *cue_name);
345
346 %rename cdio_is_device is_device;
347 bool cdio_is_device(const char *psz_source,
348 driver_id_t driver_id=DRIVER_UNKNOWN);
349
350 %rename cdio_is_nrg is_nrg;
351 bool cdio_is_nrg(const char *nrg_name);
352
353 %rename cdio_is_tocfile is_tocfile;
354 %feature("autodoc",
355 "is_tocfile(tocfile_name)->bool
356
357 Determine if tocfile_name is a cdrdao CD disc image");
358 bool cdio_is_tocfile(const char *tocfile_name);
359
360 %rename cdio_get_media_changed get_media_changed;
361 %feature("autodoc",
362 "get_media_changed(cdio) -> int
363
364 Find out if media has changed since the last call.
365 Return 1 if media has changed since last call, 0 if not. Error
366 return codes are the same as driver_return_code_t");
367 int cdio_get_media_changed(CdIo_t *p_cdio);
368
369 /* Set up to allow returning hardware info. We'll use a typedef so we
370 can make sure to isolate this.
371 */
372 %inline %{
373 typedef char ** HWInfo_t;
374 %}
375 %typemap(out) HWInfo_t {
376 /* char ** to array SVp*/
377 AV *myav;
378 SV **svs;
379 int i = 0,len = 0;
380 /* no test
381 if(!$1) {
382 $result = newSV(0);
383 }
384 */
385 /* Figure out how many elements we have */
386 while ($1[len])
387 len++;
388 svs = (SV **) malloc(len*sizeof(SV *));
389 for (i = 0; i < len ; i++) {
390 svs[i] = sv_newmortal();
391 sv_setpv((SV*)svs[i],$1[i]);
392 };
393 myav = av_make(len,svs);
394 free(svs);
395 $result = newRV_noinc((SV*)myav);
396 sv_2mortal($result);
397 argvi++;
398 }
399
400 /*
401 get_hwinfo(p_cdio)->[vendor, model, release]
402 Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
403 An exception is raised if we had an error.
404 */
405 %apply int *OUTPUT { int *drc };
406 const HWInfo_t get_hwinfo ( const CdIo_t *p_cdio, int *drc);
407
408 %inline %{
409 static cdio_hwinfo_t hw_info;
410 const
411 HWInfo_t get_hwinfo ( const CdIo_t *p_cdio, int *drc)
412 {
413 static const char *hwinfo[4] = {
414 hw_info.psz_vendor,
415 hw_info.psz_model,
416 hw_info.psz_revision,
417 NULL
418 };
419 bool b_got_hwinfo = cdio_get_hwinfo(p_cdio, &hw_info);
420
421 *drc = b_got_hwinfo;
422 return (const HWInfo_t) hwinfo;
423 }
424 %}
425
426 #include <cdio/mmc.h>
427 %inline %{
428 extern int mmc_get_tray_status(const CdIo_t *p_cdio);
429 %}
430 %rename mmc_get_tray_status get_tray_status;
431
432 %rename cdio_set_blocksize set_blocksize;
433 %feature("autodoc",
434 "set_blocksize(cdio, blocksize)->return_status
435
436 Set the blocksize for subsequent reads.");
437 driver_return_code_t cdio_set_blocksize ( const CdIo_t *p_cdio,
438 int i_blocksize );
439
440 %rename cdio_set_speed set_speed;
441 %feature("autodoc",
442 "cdio_set_speed(cdio, speed)->return_status
443 Set the drive speed.");
444 driver_return_code_t cdio_set_speed ( const CdIo_t *p_cdio, int i_speed );
445
446
447 /**** Using the name open() conflicts with some C routine.
448 So we use open_cd() instead.
449 ***/
450 %rename cdio_open_am open_cd;
451 %feature("autodoc",
452 "open_cd(source=NULL, driver_id=None, access_mode=None)
453
454 Sets up to read from place specified by source, driver_id and
455 access mode. This should be called before using any other routine
456 except those that act on a CD-ROM drive by name.
457
458 If None is given as the source, we'll use the default driver device.
459 If None is given as the driver_id, we'll find a suitable device driver.
460
461 Return the a pointer than can be used in subsequent operations or
462 None on error or no device.");
463 CdIo_t *cdio_open_am(const char *psz_source=NULL,
464 driver_id_t driver_id=DRIVER_UNKNOWN,
465 const char *psz_access_mode=NULL);