grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hidds / mouse / mouseclass.c
blob82ef4b4ee1ef5c05621769b5553acbce366c143b
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 <hidd/hidd.h>
10 #include <hidd/mouse.h>
11 #include <oop/oop.h>
12 #include <utility/tagitem.h>
13 #include <proto/alib.h>
14 #include <proto/exec.h>
15 #include <proto/utility.h>
16 #include <proto/oop.h>
18 #include "mouse.h"
20 #define SysBase (CSD(cl)->cs_SysBase)
21 #define UtilityBase (CSD(cl)->cs_UtilityBase)
23 /*****************************************************************************************
25 NAME
26 --background_mouseclass--
28 LOCATION
29 CLID_Hidd_Mouse
31 NOTES
32 Instances of this class are virtual devices being clients of the
33 pointing input subsystem. In order to receive input events, you
34 have to create an object of this class and supply a callback using
35 aoHidd_Mouse_IrqHandler attribute. After this your callback will be
36 called every time the event arrives until you dispose your object.
38 Every client receives events from all pointing devices merged into
39 a single stream.
41 *****************************************************************************************/
43 /*****************************************************************************************
45 NAME
46 aoHidd_Mouse_IrqHandler
48 SYNOPSIS
49 [I..], APTR
51 LOCATION
52 CLID_Hidd_Mouse
54 FUNCTION
55 Specifies a pointing device interrupt handler. The handler will called be every time a
56 keyboard event happens. A "C" calling convention is used, declare the handler
57 functions as follows:
59 void MouseIRQ(APTR data, struct pHidd_Mouse_Event *event);
61 Handler parameters are:
62 data - Anything you specify using aoHidd_Mouse_IrqHandlerData
63 event - A pointer to a read-only event descriptor structure with the following
64 contents:
65 button - button code, or vHidd_Mouse_NoButton of the event describes a simple
66 motion.
67 x, y - event coordinates. Need to be always valid, even if the event describes
68 a button pressed without actual motion.
69 In case of mouse wheel event these fields specify horizontal and vertical
70 wheel delta respectively.
71 type - type of event (button press, button release, wheel or motion).
72 flags - event flags. Currently only one value of vHidd_Mouse_Relative is defined.
73 If this flag is not set, coordinates are assumed to be absolute.
74 This member is actually present in the structure only if the driver
75 supplies TRUE value for aoHidd_Mouse_Extended attribute.
77 The handler is called inside interrupts, so usual restrictions apply to it.
79 NOTES
80 CLID_Hidd_Mouse class always provides extended form of event structure
81 (struct pHidd_Mouse_ExtEvent). Drivers will not always provide it, depending
82 on their aoHidd_Mouse_Extended attribute value.
84 EXAMPLE
86 BUGS
88 SEE ALSO
89 aoHidd_Mouse_IrqHandlerData, aoHidd_Mouse_Extended
91 INTERNALS
93 *****************************************************************************************/
95 /*****************************************************************************************
97 NAME
98 aoHidd_Mouse_IrqHandlerData
100 SYNOPSIS
101 [I..], APTR
103 LOCATION
104 CLID_Hidd_Mouse
106 FUNCTION
107 Specifies a user-defined value that will be passed to interrupt handler as a first
108 parameter. The purpose of this is to pass some static data to the handler.
109 The system will not assume anything about this value.
111 Defaults to NULL if not specified.
113 NOTES
115 EXAMPLE
117 BUGS
119 SEE ALSO
120 aoHidd_Mouse_IrqHandler
122 INTERNALS
124 *****************************************************************************************/
126 /*****************************************************************************************
128 NAME
129 aoHidd_Mouse_State
131 SYNOPSIS
132 [..G], struct pHidd_Mouse_Event
134 LOCATION
135 CLID_Hidd_Mouse
137 FUNCTION
138 Obtains current pointing devices state.
140 This attribute was historically implemented only in PS/2 mouse driver, but the
141 implementation was broken and incomplete. At the moment this attribute is considered
142 reserved. Do not use it, the specification may change in future.
144 NOTES
146 EXAMPLE
148 BUGS
149 Not implemented, considered reserved.
151 SEE ALSO
153 INTERNALS
155 *****************************************************************************************/
157 /*****************************************************************************************
159 NAME
160 aoHidd_Mouse_RelativeCoords
162 SYNOPSIS
163 [..G], BOOL
165 LOCATION
166 CLID_Hidd_Mouse
168 FUNCTION
169 Asks the driver it the device provides relative (like mouse) or absolute (like
170 touchscreen or tabled) coordinates.
172 Drivers which provide extended event structure may not implement this attribute
173 because they may provide mixed set of events. In this case coordinates type
174 is determined by flags member of struct pHidd_Mouse_ExtEvent.
176 CLID_Hidd_Mouse class does not implement this attribute since it provides mixed
177 stream of events.
179 NOTES
181 EXAMPLE
183 BUGS
185 SEE ALSO
186 aoHidd_Mouse_IrqHandler, aoHidd_Mouse_Extended
188 INTERNALS
190 *****************************************************************************************/
192 /*****************************************************************************************
194 NAME
195 aoHidd_Mouse_Extended
197 SYNOPSIS
198 [..G], BOOL
200 LOCATION
201 CLID_Hidd_Mouse
203 FUNCTION
204 Asks the driver if it provides extended event descriptor structure
205 (struct pHidd_Mouse_ExtEvent).
207 If value of this attribute is FALSE, the flags member is actually missing from
208 the structure, not just zeroed out! So do not use it at all in this case.
210 CLID_Hidd_Mouse class always return TRUE for this attribute.
212 NOTES
214 EXAMPLE
216 BUGS
218 SEE ALSO
219 aoHidd_Mouse_IrqHandler
221 INTERNALS
223 ******************************************************************************************/
225 OOP_Object *Mouse__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
227 struct mouse_data *data;
228 struct TagItem *tag, *tstate;
230 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
231 if (!o)
232 return NULL;
234 data = OOP_INST_DATA(cl, o);
235 data->callback = NULL;
236 data->callbackdata = NULL;
238 tstate = msg->attrList;
239 D(bug("tstate: %p\n", tstate));
241 while ((tag = NextTagItem(&tstate)))
243 ULONG idx;
245 D(bug("Got tag %d, data %x\n", tag->ti_Tag, tag->ti_Data));
247 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
249 D(bug("Mouse hidd tag\n"));
250 switch (idx)
252 case aoHidd_Mouse_IrqHandler:
253 data->callback = (APTR)tag->ti_Data;
254 D(bug("Got callback %p\n", (APTR)tag->ti_Data));
255 break;
257 case aoHidd_Mouse_IrqHandlerData:
258 data->callbackdata = (APTR)tag->ti_Data;
259 D(bug("Got data %p\n", (APTR)tag->ti_Data));
260 break;
263 } /* while (tags to process) */
265 /* Add to interrupts list if we have a callback */
266 if (data->callback)
268 Disable();
269 ADDTAIL(&CSD(cl)->callbacks, data);
270 Enable();
273 return o;
276 VOID Mouse__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
278 struct mouse_data *data = OOP_INST_DATA(cl, o);
280 if (data->callback)
282 Disable();
283 REMOVE((struct Node *)data);
284 Enable();
286 OOP_DoSuperMethod(cl, o, msg);
289 VOID Mouse__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
291 ULONG idx;
293 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx))
295 switch (idx)
297 /* case aoHidd_Mouse_State:
299 TODO: Implement this, by ORing buttons from all registered mice (?)
301 return;*/
303 case aoHidd_Mouse_Extended:
304 *msg->storage = TRUE;
305 return;
309 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
313 * In future we could support enumeration of devices and specifying
314 * which device we wish to read events from (in case if we want to implement
315 * amigainput.library or something like it)
318 /*****************************************************************************************
320 NAME
321 moHidd_Mouse_AddHardwareDriver
323 SYNOPSIS
324 OOP_Object *OOP_DoMethod(OOP_Object *obj, struct pHidd_Mouse_AddHardwareDriver *Msg);
326 OOP_Object *HIDD_Mouse_AddHardwareDriver(OOP_Object *obj, OOP_Class *driverClass, struct TagItem *tags)
328 LOCATION
329 CLID_Hidd_Mouse
331 FUNCTION
332 Creates a hardware driver object and registers it in the system.
334 It does not matter on which instance of CLID_Hidd_Mouse class this method is
335 used. Hardware driver objects are shared between all of them.
337 Since V2 this interface is obsolete and deprecated. Use moHW_AddDriver
338 method on CLID_HW_Mouse class in order to install the driver.
340 INPUTS
341 obj - Any object of CLID_Hidd_Mouse class.
342 driverClass - A pointer to OOP class of the driver. In order to create an object
343 of some previously registered public class, use
344 oop.library/OOP_FindClass().
345 tags - An optional taglist which will be passed to driver class' New() method.
347 RESULT
348 A pointer to driver object.
350 NOTES
351 Do not dispose the returned object yourself, use HIDD_Mouse_RemHardwareDriver() for it.
353 EXAMPLE
355 BUGS
357 SEE ALSO
358 moHidd_Mouse_RemHardwareDriver
360 INTERNALS
361 This method supplies own interrupt handler to the driver, do not override this.
363 *****************************************************************************************/
365 OOP_Object *Mouse__Hidd_Mouse__AddHardwareDriver(OOP_Class *cl, OOP_Object *o, struct pHidd_Mouse_AddHardwareDriver *Msg)
367 return HW_AddDriver(CSD(cl)->hwObject, Msg->driverClass, Msg->tags);
370 /*****************************************************************************************
372 NAME
373 moHidd_Mouse_RemHardwareDriver
375 SYNOPSIS
376 void OOP_DoMethod(OOP_Object *obj, struct pHidd_Mouse_RemHardwareDriver *Msg);
378 void HIDD_Mouse_RemHardwareDriver(OOP_Object *obj, OOP_Object *driver);
380 LOCATION
381 CLID_Hidd_Mouse
383 FUNCTION
384 Unregisters and disposes pointing device hardware driver object.
386 It does not matter on which instance of CLID_Hidd_Mouse class this method is
387 used. Hardware driver objects are shared between all of them.
389 Since V2 this interface is obsolete and deprecated. Use moHW_RemoveDriver
390 method on CLID_HW_Kbd class in order to remove the driver.
392 INPUTS
393 obj - Any object of CLID_Hidd_Mouse class.
394 driver - A pointer to a driver object, returned by HIDD_Mouse_AddHardwareDriver().
396 RESULT
397 None
399 NOTES
401 EXAMPLE
403 BUGS
405 SEE ALSO
406 moHidd_Mouse_AddHardwareDriver
408 INTERNALS
410 *****************************************************************************************/
412 void Mouse__Hidd_Mouse__RemHardwareDriver(OOP_Class *cl, OOP_Object *o, struct pHidd_Mouse_RemHardwareDriver *Msg)
414 HW_RemoveDriver(CSD(cl)->hwObject, Msg->driverObject);