4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1990-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <AudioPipe.h>
33 // class AudioPipe methods
36 // Constructor with file descriptor, mode, and optional name
39 const int desc
, // file descriptor
40 const FileAccess acc
, // access mode
41 const char *name_local
): // name
42 AudioUnixfile(name_local
, acc
)
47 // The create routine for pipes writes a file header
48 AudioError
AudioPipe::
53 // Was the header properly set?
54 err
= GetHeader().Validate();
55 if (err
!= AUDIO_SUCCESS
)
56 return (RaiseError(err
));
58 // Open fd supplied by constructor
60 return (RaiseError(AUDIO_ERR_NOEFFECT
));
62 // Write the file header with current (usually unknown) size
63 err
= encode_filehdr();
64 if (err
!= AUDIO_SUCCESS
) {
65 (void) close(getfd()); // If error, remove file
70 // Set the actual output length to zero
73 return (AUDIO_SUCCESS
);
76 // The open routine for pipes decodes the header
77 AudioError
AudioPipe::
82 // The constructor should have supplied a valid fd
84 return (RaiseError(AUDIO_ERR_NOEFFECT
));
86 // Decode a file header
87 err
= decode_filehdr();
88 if (err
!= AUDIO_SUCCESS
) {
89 (void) close(getfd());
94 return (AUDIO_SUCCESS
);
97 // Read data from underlying pipe into specified buffer.
98 // No data format translation takes place.
99 // Since there's no going back, the object's read position pointer is updated.
100 AudioError
AudioPipe::
102 void* buf
, // destination buffer address
103 size_t& len
, // buffer length (updated)
104 Double
& pos
) // start position (updated)
107 char *tbuf
; // current buffer pointer
108 size_t remain
; // number of bytes remaining
109 size_t cnt
; // accumulated number of bytes read
115 // Pipes return short reads. If non-blocking i/o, try to read all.
117 // Call the real routine
118 err
= AudioUnixfile::ReadData((void*)tbuf
, remain
, pos
);
120 // Update the object's read position
122 (void) SetReadPosition(pos
, Absolute
);
129 } while (!err
&& (remain
> 0) && GetBlocking());
132 return (AUDIO_SUCCESS
);
136 // Write data to underlying file from specified buffer.
137 // No data format translation takes place.
138 // Since there's no going back, the object's write position pointer is updated.
139 AudioError
AudioPipe::
141 void* buf
, // source buffer address
142 size_t& len
, // buffer length (updated)
143 Double
& pos
) // start position (updated)
147 // Call the real routine
148 err
= AudioUnixfile::WriteData(buf
, len
, pos
);
150 // Update the object's write position
151 if (err
== AUDIO_SUCCESS
)
152 (void) SetWritePosition(pos
, Absolute
);