grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hidds / kbd / kbdclass.c
blob97b3526621ce4e5554aae21239073c1acbf46a81
1 /*
2 Copyright (C) 2004-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define __OOP_NOATTRBASES__
8 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
10 #include <hidd/hidd.h>
11 #include <hidd/keyboard.h>
12 #include <oop/oop.h>
13 #include <utility/tagitem.h>
14 #include <proto/alib.h>
15 #include <proto/exec.h>
16 #include <proto/utility.h>
17 #include <proto/oop.h>
19 #include "kbd.h"
21 /*****************************************************************************************
23 NAME
24 --background_kbdclass--
26 LOCATION
27 CLID_Hidd_Kbd
29 NOTES
30 Instances of this class are virtual devices being clients of the
31 keyboard input subsystem. In order to receive keyboard events, you
32 have to create an object of this class and supply a callback using
33 aoHidd_Kbd_IrqHandler attribute. After this your callback will be
34 called every time the event arrives until you dispose your object.
36 Every client receives events from all keyboard devices merged into
37 a single stream.
39 *****************************************************************************************/
41 /*****************************************************************************************
43 NAME
44 aoHidd_Kbd_IrqHandler
46 SYNOPSIS
47 [I..], APTR
49 LOCATION
50 CLID_Hidd_Kbd
52 FUNCTION
53 Specifies a keyboard event handler. The handler will called be every time a
54 keyboard event happens. A "C" calling convention is used, declare the handler
55 functions as follows:
57 void KeyboardIRQ(APTR data, UWORD keyCode)
59 Handler parameters are:
60 data - Anything you specify using aoHidd_Kbd_IrqHandlerData
61 keyCode - A raw key code as specified in devices/rawkeycodes.h.
62 Key release event is indicated by ORing this value
63 with IECODE_UP_PREFIX (defined in devices/inputevent.h)
65 The handler is called inside interrupts, so usual restrictions apply to it.
67 NOTES
69 EXAMPLE
71 BUGS
72 Not all hosted drivers provide this attribute.
74 SEE ALSO
75 aoHidd_Kbd_IrqHandlerData
77 INTERNALS
79 *****************************************************************************************/
81 /*****************************************************************************************
83 NAME
84 aoHidd_Kbd_IrqHandlerData
86 SYNOPSIS
87 [I..], APTR
89 LOCATION
90 CLID_Hidd_Kbd
92 FUNCTION
93 Specifies a user-defined value that will be passed to IRQ handler as a first
94 parameter. The purpose of this is to pass some static data to the handler.
95 The system will not assume anything about this value.
97 Defaults to NULL if not specified.
99 NOTES
101 EXAMPLE
103 BUGS
105 SEE ALSO
106 aoHidd_Kbd_IrqHandler
108 INTERNALS
110 ******************************************************************************************/
112 OOP_Object *KBD__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
114 struct kbd_data *data;
115 struct TagItem *tag, *tstate;
116 struct Library *UtilityBase = CSD(cl)->cs_UtilityBase;
118 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
119 if (!o)
120 return NULL;
122 data = OOP_INST_DATA(cl, o);
123 data->callback = NULL;
124 data->callbackdata = NULL;
126 tstate = msg->attrList;
127 D(bug("tstate: %p\n", tstate));
129 while ((tag = NextTagItem(&tstate)))
131 ULONG idx;
133 D(bug("Got tag %d, data %x\n", tag->ti_Tag, tag->ti_Data));
135 if (IS_HIDDKBD_ATTR(tag->ti_Tag, idx))
137 D(bug("Kbd hidd tag\n"));
138 switch (idx)
140 case aoHidd_Kbd_IrqHandler:
141 data->callback = (APTR)tag->ti_Data;
142 D(bug("Got callback %p\n", (APTR)tag->ti_Data));
143 break;
145 case aoHidd_Kbd_IrqHandlerData:
146 data->callbackdata = (APTR)tag->ti_Data;
147 D(bug("Got data %p\n", (APTR)tag->ti_Data));
148 break;
151 } /* while (tags to process) */
154 * Add to interrupts list if we have a callback.
155 * Creating an object without callback is a legacy way of
156 * installing hardware drivers. It should be removed.
158 if (data->callback)
160 Disable();
161 ADDTAIL(&CSD(cl)->callbacks, data);
162 Enable();
165 return o;
168 VOID KBD__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
170 struct kbd_data *data = OOP_INST_DATA(cl, o);
172 /* This condition is a legacy and should be removed */
173 if (data->callback)
175 Disable();
176 REMOVE(data);
177 Enable();
179 OOP_DoSuperMethod(cl, o, msg);
183 * The following two methods are legacy and strongly deprecated.
184 * They are present only for backward compatibility with the old code.
187 /*****************************************************************************************
189 NAME
190 moHidd_Kbd_AddHardwareDriver
192 SYNOPSIS
193 OOP_Object *OOP_DoMethod(OOP_Object *obj, struct pHidd_Kbd_AddHardwareDriver *Msg);
195 OOP_Object *HIDD_Kbd_AddHardwareDriver(OOP_Object *obj, OOP_Class *driverClass,
196 struct TagItem *tags);
198 LOCATION
199 CLID_Hidd_Kbd
201 FUNCTION
202 Creates a hardware driver object and registers it in the system.
204 It does not matter on which instance of CLID_Hidd_Kbd class this method is
205 used. Hardware driver objects are shared between all of them.
207 Since V2 this interface is obsolete and deprecated. Use moHW_AddDriver
208 method on CLID_HW_Kbd class in order to install the driver.
210 INPUTS
211 obj - Any object of CLID_Hidd_Kbd class.
212 driverClass - A pointer to OOP class of the driver. In order to create an object
213 of some previously registered public class, use
214 oop.library/OOP_FindClass().
215 tags - An optional taglist which will be passed to driver class' New() method.
217 RESULT
218 A pointer to driver object.
220 NOTES
221 Do not dispose the returned object yourself, use HIDD_Kbd_RemHardwareDriver() for it.
223 EXAMPLE
225 BUGS
227 SEE ALSO
228 moHidd_Kbd_RemHardwareDriver
230 INTERNALS
231 This method supplies own interrupt handler to the driver, do not override this.
233 *****************************************************************************************/
235 OOP_Object *KBD__Hidd_Kbd__AddHardwareDriver(OOP_Class *cl, OOP_Object *o, struct pHidd_Kbd_AddHardwareDriver *Msg)
237 return HW_AddDriver(CSD(cl)->hwObj, Msg->driverClass, Msg->tags);
240 /*****************************************************************************************
242 NAME
243 moHidd_Kbd_RemHardwareDriver
245 SYNOPSIS
246 void OOP_DoMethod(OOP_Object *obj, struct pHidd_Kbd_RemHardwareDriver *Msg);
248 void HIDD_Kbd_RemHardwareDriver(OOP_Object *obj, OOP_Object *driver);
250 LOCATION
251 CLID_Hidd_Kbd
253 FUNCTION
254 Unregisters and disposes keyboard hardware driver object.
256 It does not matter on which instance of CLID_Hidd_Kbd class this method is
257 used. Hardware driver objects are shared between all of them.
259 Since V2 this interface is obsolete and deprecated. Use moHW_RemoveDriver
260 method on CLID_HW_Kbd class in order to remove the driver.
262 INPUTS
263 obj - Any object of CLID_Hidd_Kbd class.
264 driver - A pointer to a driver object, returned by HIDD_Kbd_AddHardwareDriver().
266 RESULT
267 None
269 NOTES
271 EXAMPLE
273 BUGS
275 SEE ALSO
276 moHidd_Kbd_AddHardwareDriver
278 INTERNALS
280 *****************************************************************************************/
282 void KBD__Hidd_Kbd__RemHardwareDriver(OOP_Class *cl, OOP_Object *o, struct pHidd_Kbd_RemHardwareDriver *Msg)
284 HW_RemoveDriver(CSD(cl)->hwObj, Msg->driverObject);