~ubuntu-branches/ubuntu/maverick/libcdio/maverick

« back to all changes in this revision

Viewing changes to include/cdio++/device.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Boullis
  • Date: 2007-10-04 00:52:35 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071004005235-4e3gdi4x2q2d14jx
Tags: 0.78.2+dfsg1-1
* Repack the source tarball to remove non-DFSG-free
  documentation. Thanks to Joerg Jaspert for pointing this.
* Also update debian/copyright to reflect the status of the removed
  documentation.
* Add libncurses5-dev | libncurses-dev to the build-dependencies, for
  cdda-player.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- C++ -*-
 
2
    $Id: device.hpp,v 1.6 2006/03/05 06:52:15 rocky Exp $
 
3
 
 
4
    Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
*/
 
20
 
 
21
/** \file device.hpp
 
22
 *
 
23
 *  \brief C++ header for driver- or device-related libcdio calls.  
 
24
 *         ("device" includes CD-image reading devices.)
 
25
 */
 
26
 
 
27
/*! 
 
28
  Free resources associated with CD-ROM Device/Image. After this we 
 
29
  must do another open before any more reading.
 
30
*/
 
31
bool 
 
32
close()
 
33
{
 
34
  cdio_destroy(p_cdio);
 
35
  p_cdio = (CdIo_t *) NULL;
 
36
  return true;
 
37
}
 
38
 
 
39
/*!
 
40
  Eject media in CD drive if there is a routine to do so. 
 
41
  
 
42
  If the CD is ejected, object is destroyed.
 
43
*/
 
44
void
 
45
ejectMedia () 
 
46
{
 
47
  driver_return_code_t drc = cdio_eject_media(&p_cdio);
 
48
  possible_throw_device_exception(drc);
 
49
}
 
50
 
 
51
/*!
 
52
  Free device list returned by GetDevices
 
53
  
 
54
  @param device_list list returned by GetDevices
 
55
  
 
56
  @see GetDevices
 
57
  
 
58
*/
 
59
void 
 
60
freeDeviceList (char * device_list[]) 
 
61
{
 
62
  cdio_free_device_list(device_list);
 
63
}
 
64
 
 
65
/*!
 
66
    Get the value associatied with key. 
 
67
    
 
68
    @param key the key to retrieve
 
69
    @return the value associatd with "key" or NULL if p_cdio is NULL
 
70
    or "key" does not exist.
 
71
  */
 
72
const char * 
 
73
getArg (const char key[]) 
 
74
{
 
75
  return cdio_get_arg (p_cdio, key);
 
76
}
 
77
 
 
78
/*!  
 
79
  Return an opaque CdIo_t pointer for the given track object.
 
80
*/
 
81
CdIo_t *getCdIo()
 
82
{
 
83
  return p_cdio;
 
84
}
 
85
 
 
86
/*!  
 
87
  Return an opaque CdIo_t pointer for the given track object.
 
88
*/
 
89
cdtext_t *getCdtext(track_t i_track)
 
90
{
 
91
  return cdio_get_cdtext (p_cdio, i_track);
 
92
}
 
93
 
 
94
/*!
 
95
  Get the CD device name for the object.
 
96
  
 
97
  @return a string containing the CD device for this object or NULL is
 
98
  if we couldn't get a device anme.
 
99
  
 
100
  In some situations of drivers or OS's we can't find a CD device if
 
101
  there is no media in it and it is possible for this routine to return
 
102
  NULL even though there may be a hardware CD-ROM.
 
103
*/
 
104
char *
 
105
getDevice () 
 
106
{
 
107
  return cdio_get_default_device(p_cdio);
 
108
}
 
109
 
 
110
/*!
 
111
  Get the what kind of device we've got.
 
112
  
 
113
  @param p_read_cap pointer to return read capabilities
 
114
  @param p_write_cap pointer to return write capabilities
 
115
  @param p_misc_cap pointer to return miscellaneous other capabilities
 
116
  
 
117
  In some situations of drivers or OS's we can't find a CD device if
 
118
  there is no media in it and it is possible for this routine to return
 
119
  NULL even though there may be a hardware CD-ROM.
 
120
*/
 
121
void 
 
122
getDriveCap (cdio_drive_read_cap_t  &read_cap,
 
123
             cdio_drive_write_cap_t &write_cap,
 
124
             cdio_drive_misc_cap_t  &misc_cap) 
 
125
{
 
126
  cdio_get_drive_cap(p_cdio, &read_cap, &write_cap, &misc_cap);
 
127
}
 
128
 
 
129
/*!
 
130
  Get a string containing the name of the driver in use.
 
131
  
 
132
  @return a string with driver name or NULL if CdIo_t is NULL (we
 
133
  haven't initialized a specific device.
 
134
*/
 
135
const char *
 
136
getDriverName () 
 
137
{
 
138
  return cdio_get_driver_name(p_cdio);
 
139
}
 
140
 
 
141
/*!
 
142
  Get the driver id. 
 
143
  if CdIo_t is NULL (we haven't initialized a specific device driver), 
 
144
  then return DRIVER_UNKNOWN.
 
145
  
 
146
  @return the driver id..
 
147
*/
 
148
driver_id_t 
 
149
getDriverId () 
 
150
{
 
151
  return cdio_get_driver_id(p_cdio);
 
152
}
 
153
 
 
154
/*! 
 
155
  Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
 
156
  False is returned if we had an error getting the information.
 
157
*/
 
158
bool 
 
159
getHWinfo ( /*out*/ cdio_hwinfo_t &hw_info ) 
 
160
{
 
161
  return cdio_get_hwinfo(p_cdio, &hw_info);
 
162
}
 
163
 
 
164
/*! Get the LSN of the first track of the last session of
 
165
  on the CD.
 
166
  
 
167
  @param i_last_session pointer to the session number to be returned.
 
168
*/
 
169
void
 
170
getLastSession (/*out*/ lsn_t &i_last_session) 
 
171
{
 
172
  driver_return_code_t drc = cdio_get_last_session(p_cdio, &i_last_session);
 
173
  possible_throw_device_exception(drc);
 
174
}
 
175
 
 
176
/*! 
 
177
  Find out if media has changed since the last call.
 
178
  @return 1 if media has changed since last call, 0 if not. Error
 
179
  return codes are the same as driver_return_code_t
 
180
*/
 
181
int 
 
182
getMediaChanged() 
 
183
{
 
184
  return cdio_get_media_changed(p_cdio);
 
185
}
 
186
 
 
187
/*! True if CD-ROM understand ATAPI commands. */
 
188
bool_3way_t 
 
189
haveATAPI ()
 
190
{
 
191
  return cdio_have_atapi(p_cdio);
 
192
}
 
193
 
 
194
/*! 
 
195
 
 
196
  Sets up to read from the device specified by psz_source.  An open
 
197
  routine should be called before using any read routine. If device
 
198
  object was previously opened it is closed first.
 
199
  
 
200
  @return true if open succeeded or false if error.
 
201
 
 
202
*/
 
203
bool 
 
204
open(const char *psz_source)
 
205
{
 
206
  if (p_cdio) cdio_destroy(p_cdio);
 
207
  p_cdio = cdio_open_cd(psz_source);
 
208
  return NULL != p_cdio ;
 
209
}
 
210
 
 
211
/*! 
 
212
 
 
213
  Sets up to read from the device specified by psz_source and access
 
214
  mode.  An open routine should be called before using any read
 
215
  routine. If device object was previously opened it is "closed".
 
216
  
 
217
  @return true if open succeeded or false if error.
 
218
*/
 
219
bool 
 
220
open (const char *psz_source, driver_id_t driver_id, 
 
221
      const char *psz_access_mode = (const char *) NULL) 
 
222
{
 
223
  if (p_cdio) cdio_destroy(p_cdio);
 
224
  if (psz_access_mode)
 
225
    p_cdio = cdio_open_am(psz_source, driver_id, psz_access_mode);
 
226
  else 
 
227
    p_cdio = cdio_open(psz_source, driver_id);
 
228
  return NULL != p_cdio ;
 
229
}
 
230
 
 
231
/*!
 
232
  Set the blocksize for subsequent reads. 
 
233
*/
 
234
void
 
235
setBlocksize ( int i_blocksize )
 
236
{
 
237
  driver_return_code_t drc = cdio_set_blocksize ( p_cdio, i_blocksize );
 
238
  possible_throw_device_exception(drc);
 
239
}
 
240
 
 
241
/*!
 
242
    Set the drive speed. 
 
243
*/
 
244
void
 
245
setSpeed ( int i_speed ) 
 
246
{
 
247
  driver_return_code_t drc = cdio_set_speed ( p_cdio, i_speed );
 
248
  possible_throw_device_exception(drc);
 
249
}
 
250
 
 
251
/*!
 
252
    Set the arg "key" with "value" in "p_cdio".
 
253
    
 
254
    @param key the key to set
 
255
    @param value the value to assocaiate with key
 
256
*/
 
257
void
 
258
setArg (const char key[], const char value[]) 
 
259
{
 
260
  driver_return_code_t drc = cdio_set_arg (p_cdio, key, value);
 
261
  possible_throw_device_exception(drc);
 
262
}