2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <IOKit/assert.h>
24 #include <IOKit/IOLib.h>
25 #include <IOKit/storage/IOCDAudioControlUserClient.h>
27 #define super IOUserClient
28 OSDefineMetaClassAndStructors(IOCDAudioControlUserClient
, IOUserClient
)
30 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 IOCDAudioControl
* IOCDAudioControlUserClient::getProvider() const
35 // Obtain this object's provider. We override the superclass's method
36 // to return a more specific subclass of IOService -- IOCDAudioControl.
37 // This method serves simply as a convenience to subclass developers.
40 return (IOCDAudioControl
*) IOService::getProvider();
43 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 IOCDAudioControlUserClient
* IOCDAudioControlUserClient::withTask(task_t
)
48 // Create a new IOCDAudioControlUserClient.
51 IOCDAudioControlUserClient
* me
= new IOCDAudioControlUserClient
;
53 if ( me
&& me
->init() == false )
62 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64 bool IOCDAudioControlUserClient::start(IOService
* provider
)
67 // Prepare the user client for usage.
70 // State our assumptions.
72 assert(OSDynamicCast(IOCDAudioControl
, provider
));
74 // Ask our superclass' opinion.
76 if ( super::start(provider
) == false ) return false;
80 if ( provider
->open(this) == false ) return false;
82 // Prepare our method dispatch table.
84 _methods
[kIOCDAudioControlMethodGetStatus
].func
= (IOMethod
) &IOCDAudioControlUserClient::getStatus
;
85 _methods
[kIOCDAudioControlMethodGetStatus
].flags
= kIOUCScalarIStructO
;
86 _methods
[kIOCDAudioControlMethodGetStatus
].count0
= 0;
87 _methods
[kIOCDAudioControlMethodGetStatus
].count1
= sizeof(CDAudioStatus
);
88 _methods
[kIOCDAudioControlMethodGetStatus
].object
= this;
90 _methods
[kIOCDAudioControlMethodGetTOC
].func
= (IOMethod
) &IOCDAudioControlUserClient::getTOC
;
91 _methods
[kIOCDAudioControlMethodGetTOC
].flags
= kIOUCScalarIStructO
;
92 _methods
[kIOCDAudioControlMethodGetTOC
].count0
= 0;
93 _methods
[kIOCDAudioControlMethodGetTOC
].count1
= 0xFFFFFFFF;
94 _methods
[kIOCDAudioControlMethodGetTOC
].object
= this;
96 _methods
[kIOCDAudioControlMethodGetVolume
].func
= (IOMethod
) &IOCDAudioControlUserClient::getVolume
;
97 _methods
[kIOCDAudioControlMethodGetVolume
].flags
= kIOUCScalarIScalarO
;
98 _methods
[kIOCDAudioControlMethodGetVolume
].count0
= 0;
99 _methods
[kIOCDAudioControlMethodGetVolume
].count1
= 2;
100 _methods
[kIOCDAudioControlMethodGetVolume
].object
= this;
102 _methods
[kIOCDAudioControlMethodSetVolume
].func
= (IOMethod
) &IOCDAudioControlUserClient::setVolume
;
103 _methods
[kIOCDAudioControlMethodSetVolume
].flags
= kIOUCScalarIScalarO
;
104 _methods
[kIOCDAudioControlMethodSetVolume
].count0
= 2;
105 _methods
[kIOCDAudioControlMethodSetVolume
].count1
= 0;
106 _methods
[kIOCDAudioControlMethodSetVolume
].object
= this;
108 _methods
[kIOCDAudioControlMethodPause
].func
= (IOMethod
) &IOCDAudioControlUserClient::pause
;
109 _methods
[kIOCDAudioControlMethodPause
].flags
= kIOUCScalarIScalarO
;
110 _methods
[kIOCDAudioControlMethodPause
].count0
= 1;
111 _methods
[kIOCDAudioControlMethodPause
].count1
= 0;
112 _methods
[kIOCDAudioControlMethodPause
].object
= this;
114 _methods
[kIOCDAudioControlMethodPlay
].func
= (IOMethod
) &IOCDAudioControlUserClient::play
;
115 _methods
[kIOCDAudioControlMethodPlay
].flags
= kIOUCScalarIScalarO
;
116 _methods
[kIOCDAudioControlMethodPlay
].count0
= 2;
117 _methods
[kIOCDAudioControlMethodPlay
].count1
= 0;
118 _methods
[kIOCDAudioControlMethodPlay
].object
= this;
120 _methods
[kIOCDAudioControlMethodScan
].func
= (IOMethod
) &IOCDAudioControlUserClient::scan
;
121 _methods
[kIOCDAudioControlMethodScan
].flags
= kIOUCScalarIScalarO
;
122 _methods
[kIOCDAudioControlMethodScan
].count0
= 2;
123 _methods
[kIOCDAudioControlMethodScan
].count1
= 0;
124 _methods
[kIOCDAudioControlMethodScan
].object
= this;
126 _methods
[kIOCDAudioControlMethodStop
].func
= (IOMethod
) &IOCDAudioControlUserClient::stop
;
127 _methods
[kIOCDAudioControlMethodStop
].flags
= 0;
128 _methods
[kIOCDAudioControlMethodStop
].count0
= 0;
129 _methods
[kIOCDAudioControlMethodStop
].count1
= 0;
130 _methods
[kIOCDAudioControlMethodStop
].object
= this;
135 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137 IOReturn
IOCDAudioControlUserClient::clientClose()
140 // Relinquish the user client.
143 IOCDAudioControl
* provider
= getProvider();
145 if ( provider
&& provider
->isOpen(this) )
147 provider
->close(this);
151 return kIOReturnSuccess
;
154 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156 IOExternalMethod
* IOCDAudioControlUserClient::getExternalMethodForIndex(
160 // Obtain the method definition given a method index.
163 if (index
>= kIOCDAudioControlMethodCount
) return 0;
165 return _methods
+ index
;
168 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 IOReturn
IOCDAudioControlUserClient::getStatus( CDAudioStatus
* status
,
171 UInt32
* statusSize
)
174 // Get the current audio play status information.
177 if ( *statusSize
!= sizeof(CDAudioStatus
) ) return kIOReturnBadArgument
;
179 return getProvider()->getStatus(status
);
182 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184 IOReturn
IOCDAudioControlUserClient::getTOC(CDTOC
* toc
, UInt32
* tocMaxSize
)
187 // Get the full Table Of Contents.
190 CDTOC
* original
= getProvider()->getTOC();
192 if (original
== 0) return kIOReturnBadMedia
;
194 *tocMaxSize
= min(original
->length
+ sizeof(UInt16
), *tocMaxSize
);
195 bcopy(original
, toc
, *tocMaxSize
);
197 return kIOReturnSuccess
;
200 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
202 IOReturn
IOCDAudioControlUserClient::getVolume(UInt32
* left
, UInt32
* right
)
205 // Get the current audio volume.
210 if ( ((*left
) & ~0xFF) || ((*right
) & ~0xFF) ) return kIOReturnBadArgument
;
212 status
= getProvider()->getVolume((UInt8
*) left
, (UInt8
*) right
);
214 *left
= *((UInt8
*) left
);
215 *right
= *((UInt8
*) right
);
220 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222 IOReturn
IOCDAudioControlUserClient::setVolume(UInt32 left
, UInt32 right
)
225 // Set the current audio volume.
228 if ( (left
& ~0xFF) || (right
& ~0xFF) ) return kIOReturnBadArgument
;
230 return getProvider()->setVolume((UInt8
) left
, (UInt8
) right
);
233 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
235 IOReturn
IOCDAudioControlUserClient::pause(UInt32 pause
)
238 // Pause or resume the audio playback.
241 return getProvider()->pause((bool) pause
);
244 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246 IOReturn
IOCDAudioControlUserClient::play(UInt32 msfStart
, UInt32 msfStop
)
255 timeStart
.minute
= (msfStart
>> 16) & 0xFF;
256 timeStart
.second
= (msfStart
>> 8) & 0xFF;
257 timeStart
.frame
= (msfStart
>> 0) & 0xFF;
259 timeStop
.minute
= (msfStop
>> 16) & 0xFF;
260 timeStop
.second
= (msfStop
>> 8) & 0xFF;
261 timeStop
.frame
= (msfStop
>> 0) & 0xFF;
263 return getProvider()->play(timeStart
, timeStop
);
266 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
268 IOReturn
IOCDAudioControlUserClient::scan(UInt32 msfStart
, UInt32 reverse
)
271 // Perform a fast-forward or fast-backward operation.
276 timeStart
.minute
= (msfStart
>> 16) & 0xFF;
277 timeStart
.second
= (msfStart
>> 8) & 0xFF;
278 timeStart
.frame
= (msfStart
>> 0) & 0xFF;
280 return getProvider()->scan(timeStart
, reverse
? true : false);
283 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
285 IOReturn
IOCDAudioControlUserClient::stop()
288 // Stop the audio playback (or audio scan).
291 return getProvider()->stop();
294 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
296 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 0);
298 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 1);
302 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 2);
306 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
308 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 3);
310 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
312 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 4);
314 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 5);
318 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
320 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 6);
322 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
324 OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient
, 7);