]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
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> | |
28 | ||
29 | static IOBSDConsole * gBSDConsoleInst = 0; | |
30 | bool displayWranglerPublished( OSObject *, void *, IOService * ); | |
31 | ||
32 | #define super IOService | |
33 | OSDefineMetaClassAndStructors(IOBSDConsole, IOService); | |
34 | ||
35 | //************************************************************************ | |
36 | ||
37 | bool IOBSDConsole::start(IOService * provider) | |
38 | { | |
39 | OSObject * notify; | |
40 | ||
41 | if (!super::start(provider)) return false; | |
42 | ||
43 | assert( gBSDConsoleInst == 0 ); | |
44 | gBSDConsoleInst = this; | |
45 | ||
46 | notify = addNotification( gIOPublishNotification, | |
47 | serviceMatching("IOHIKeyboard"), | |
48 | (IOServiceNotificationHandler) &IOBSDConsole::publishNotificationHandler, | |
49 | this, 0 ); | |
50 | assert( notify ); | |
51 | ||
52 | notify = addNotification( gIOPublishNotification, | |
53 | serviceMatching("IODisplayWrangler"), | |
54 | (IOServiceNotificationHandler)displayWranglerPublished, | |
55 | this, 0 ); | |
56 | assert( notify ); | |
57 | ||
58 | notify = addNotification( gIOPublishNotification, | |
59 | serviceMatching("IOAudioStream"), | |
60 | (IOServiceNotificationHandler) &IOBSDConsole::publishNotificationHandler, | |
61 | this, this ); | |
62 | assert( notify ); | |
63 | ||
64 | return( true ); | |
65 | } | |
66 | ||
67 | bool IOBSDConsole::publishNotificationHandler( | |
68 | IOBSDConsole * self, | |
69 | void * ref, | |
70 | IOService * newService ) | |
71 | ||
72 | { | |
73 | IOHIKeyboard * keyboard = 0; | |
74 | IOService * audio = 0; | |
75 | ||
76 | if( ref) { | |
77 | audio = OSDynamicCast(IOService, newService->metaCast("IOAudioStream")); | |
78 | if (audio != 0) { | |
79 | OSNumber *out; | |
80 | out = OSDynamicCast(OSNumber, newService->getProperty("Out")); | |
81 | if (out) { | |
82 | if (out->unsigned8BitValue() == 1) { | |
83 | self->fAudioOut = newService; | |
84 | } | |
85 | } | |
86 | } | |
87 | } else { | |
88 | audio = 0; | |
89 | keyboard = OSDynamicCast( IOHIKeyboard, newService ); | |
90 | ||
91 | if( keyboard && self->attach( keyboard )) { | |
92 | self->arbitrateForKeyboard( keyboard ); | |
93 | } | |
94 | } | |
95 | ||
96 | if( !keyboard && !audio) | |
97 | IOLog("%s: strange service notify \"%s\"\n", | |
98 | self->getName(), newService->getName()); | |
99 | ||
100 | return true; | |
101 | } | |
102 | ||
103 | // ********************************************************************************** | |
104 | // displayWranglerPublished | |
105 | // | |
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 ) | |
110 | { | |
111 | if ( yourDevice != NULL ) { | |
112 | ((IOBSDConsole *)us)->displayManager = yourDevice; | |
113 | } | |
114 | return true; | |
115 | } | |
116 | ||
117 | ||
118 | //************************************************************************ | |
119 | // Keyboard client stuff | |
120 | //************************************************************************ | |
121 | ||
122 | void IOBSDConsole::arbitrateForKeyboard( IOHIKeyboard * nub ) | |
123 | { | |
124 | nub->open(this, 0, | |
125 | keyboardEvent, 0, updateEventFlags); | |
126 | // failure can be expected if the HID system already has it | |
127 | } | |
128 | ||
129 | IOReturn IOBSDConsole::message(UInt32 type, IOService * provider, | |
130 | void * argument) | |
131 | { | |
132 | IOReturn status = kIOReturnSuccess; | |
133 | ||
134 | switch (type) | |
135 | { | |
136 | case kIOMessageServiceIsTerminated: | |
137 | case kIOMessageServiceIsRequestingClose: | |
138 | provider->close( this ); | |
139 | break; | |
140 | ||
141 | case kIOMessageServiceWasClosed: | |
142 | arbitrateForKeyboard( (IOHIKeyboard *) provider ); | |
143 | break; | |
144 | ||
145 | default: | |
146 | status = super::message(type, provider, argument); | |
147 | break; | |
148 | } | |
149 | ||
150 | return status; | |
151 | } | |
152 | ||
153 | extern "C" { | |
154 | void cons_cinput( char c); | |
155 | } | |
156 | #warning REMOVE cons_cinput DECLARATION FROM HERE | |
157 | ||
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 */) | |
169 | { | |
170 | static const char cursorCodes[] = { 'D', 'A', 'C', 'B' }; | |
171 | ||
172 | if ( ((IOBSDConsole *)target)->displayManager != NULL ) { // if there is a display manager, | |
173 | ((IOBSDConsole *)target)->displayManager->activityTickle(kIOPMSuperclassPolicy1); // tell it there is user activity | |
174 | } | |
175 | ||
176 | if( eventType == NX_KEYDOWN) { | |
177 | if( (charSet == NX_SYMBOLSET) | |
178 | && (charCode >= 0xac) && (charCode <= 0xaf)) { | |
179 | cons_cinput( '\033'); | |
180 | cons_cinput( 'O'); | |
181 | charCode = cursorCodes[ charCode - 0xac ]; | |
182 | } | |
183 | cons_cinput( charCode); | |
184 | } | |
185 | } | |
186 | ||
187 | void IOBSDConsole::updateEventFlags(OSObject * /*target*/, unsigned /*flags*/) | |
188 | { | |
189 | return; | |
190 | } | |
191 | ||
192 | //************************************************************************ | |
193 | // Utility sound making stuff, callable from C | |
194 | //************************************************************************ | |
195 | extern "C" { | |
196 | int asc_ringbell(); | |
197 | } | |
198 | ||
199 | ||
200 | bool (*playBeep)(IOService *outputStream) = 0; | |
201 | ||
202 | /* | |
203 | * Make some sort of noise if possible | |
204 | */ | |
205 | ||
206 | int asc_ringbell() | |
207 | { | |
208 | IOService *output; | |
209 | ||
210 | if (gBSDConsoleInst && playBeep && (output = gBSDConsoleInst->getAudioOut())) { | |
211 | playBeep(output); | |
212 | } | |
213 | ||
214 | return true; | |
215 | } | |
216 |