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@
22 #include <IOKit/assert.h>
23 #include <IOKit/IOMessage.h>
24 #include <IOKit/IOLib.h>
25 #include "IOBSDConsole.h"
26 #include <IOKit/hidsystem/IOHIKeyboard.h>
27 #include <IOKit/hidsystem/IOLLEvent.h>
29 static IOBSDConsole
* gBSDConsoleInst
= 0;
30 bool displayWranglerPublished( OSObject
*, void *, IOService
* );
32 #define super IOService
33 OSDefineMetaClassAndStructors(IOBSDConsole
, IOService
);
35 //************************************************************************
37 bool IOBSDConsole::start(IOService
* provider
)
41 if (!super::start(provider
)) return false;
43 assert( gBSDConsoleInst
== 0 );
44 gBSDConsoleInst
= this;
46 notify
= addNotification( gIOPublishNotification
,
47 serviceMatching("IOHIKeyboard"),
48 (IOServiceNotificationHandler
) &IOBSDConsole::publishNotificationHandler
,
52 notify
= addNotification( gIOPublishNotification
,
53 serviceMatching("IODisplayWrangler"),
54 (IOServiceNotificationHandler
)displayWranglerPublished
,
58 notify
= addNotification( gIOPublishNotification
,
59 serviceMatching("IOAudioStream"),
60 (IOServiceNotificationHandler
) &IOBSDConsole::publishNotificationHandler
,
67 bool IOBSDConsole::publishNotificationHandler(
70 IOService
* newService
)
73 IOHIKeyboard
* keyboard
= 0;
74 IOService
* audio
= 0;
77 audio
= OSDynamicCast(IOService
, newService
->metaCast("IOAudioStream"));
80 out
= OSDynamicCast(OSNumber
, newService
->getProperty("Out"));
82 if (out
->unsigned8BitValue() == 1) {
83 self
->fAudioOut
= newService
;
89 keyboard
= OSDynamicCast( IOHIKeyboard
, newService
);
91 if( keyboard
&& self
->attach( keyboard
)) {
92 self
->arbitrateForKeyboard( keyboard
);
96 if( !keyboard
&& !audio
)
97 IOLog("%s: strange service notify \"%s\"\n",
98 self
->getName(), newService
->getName());
103 // **********************************************************************************
104 // displayWranglerPublished
106 // The Display Wrangler has appeared. We will be calling its
107 // ActivityTickle method when there is user activity.
108 // **********************************************************************************
109 bool displayWranglerPublished( OSObject
* us
, void * ref
, IOService
* yourDevice
)
111 if ( yourDevice
!= NULL
) {
112 ((IOBSDConsole
*)us
)->displayManager
= yourDevice
;
118 //************************************************************************
119 // Keyboard client stuff
120 //************************************************************************
122 void IOBSDConsole::arbitrateForKeyboard( IOHIKeyboard
* nub
)
125 keyboardEvent
, 0, updateEventFlags
);
126 // failure can be expected if the HID system already has it
129 IOReturn
IOBSDConsole::message(UInt32 type
, IOService
* provider
,
132 IOReturn status
= kIOReturnSuccess
;
136 case kIOMessageServiceIsTerminated
:
137 case kIOMessageServiceIsRequestingClose
:
138 provider
->close( this );
141 case kIOMessageServiceWasClosed
:
142 arbitrateForKeyboard( (IOHIKeyboard
*) provider
);
146 status
= super::message(type
, provider
, argument
);
154 void cons_cinput( char c
);
156 #warning REMOVE cons_cinput DECLARATION FROM HERE
158 void IOBSDConsole::keyboardEvent(OSObject
* target
,
159 /* eventType */ unsigned eventType
,
160 /* flags */ unsigned /* flags */,
161 /* keyCode */ unsigned /* key */,
162 /* charCode */ unsigned charCode
,
163 /* charSet */ unsigned charSet
,
164 /* originalCharCode */ unsigned /* origCharCode */,
165 /* originalCharSet */ unsigned /* origCharSet */,
166 /* keyboardType */ unsigned /* keyboardType */,
167 /* repeat */ bool /* repeat */,
168 /* atTime */ AbsoluteTime
/* ts */)
170 static const char cursorCodes
[] = { 'D', 'A', 'C', 'B' };
172 if ( ((IOBSDConsole
*)target
)->displayManager
!= NULL
) { // if there is a display manager,
173 ((IOBSDConsole
*)target
)->displayManager
->activityTickle(kIOPMSuperclassPolicy1
); // tell it there is user activity
176 if( eventType
== NX_KEYDOWN
) {
177 if( (charSet
== NX_SYMBOLSET
)
178 && (charCode
>= 0xac) && (charCode
<= 0xaf)) {
179 cons_cinput( '\033');
181 charCode
= cursorCodes
[ charCode
- 0xac ];
183 cons_cinput( charCode
);
187 void IOBSDConsole::updateEventFlags(OSObject
* /*target*/, unsigned /*flags*/)
192 //************************************************************************
193 // Utility sound making stuff, callable from C
194 //************************************************************************
200 bool (*playBeep
)(IOService
*outputStream
) = 0;
203 * Make some sort of noise if possible
210 if (gBSDConsoleInst
&& playBeep
&& (output
= gBSDConsoleInst
->getAudioOut())) {