2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <hidd/mouse.h>
9 #include <proto/utility.h>
14 * This file contains private DriverData class.
15 * The problem is that together with the actual driver object we have
16 * to store some information about the driver, together with the callback.
17 * Unfortunately our drivers do not have any base class, so we cannot just
18 * add fields to its structure. In order to circumvent this limitation,
19 * we use proxy objects instead of real driver objects. Proxy object
20 * encapsulates driver object together with all the needed information.
21 * (De)masquerading drivers is done in subsystem class.
24 static void GlobalCallback(struct driverNode
*drv
, struct pHidd_Mouse_ExtEvent
*ev
)
26 struct pHidd_Mouse_ExtEvent xev
;
27 struct mouse_data
*data
;
29 /* Ignore the event if the driver is not activated yet */
34 * The event passed in may be pHidd_Mouse_Event instead of pHidd_Mouse_ExtEvent,
35 * according to flags. In this case we add own flags
37 if (drv
->flags
!= vHidd_Mouse_Extended
)
39 xev
.button
= ev
->button
;
43 xev
.flags
= drv
->flags
;
48 for (data
= (struct mouse_data
*)drv
->callbacks
->mlh_Head
; data
->node
.mln_Succ
;
49 data
= (struct mouse_data
*)data
->node
.mln_Succ
)
51 data
->callback(data
->callbackdata
, ev
);
55 OOP_Object
*DriverData__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
57 struct Library
*OOPBase
= CSD(cl
)->cs_OOPBase
;
58 struct Library
*UtilityBase
= CSD(cl
)->cs_UtilityBase
;
59 OOP_Class
*driverClass
;
61 driverClass
= (OOP_Class
*)GetTagData(aHidd_DriverData_ClassPtr
, 0, msg
->attrList
);
62 D(bug("[Mouse] AddHardwareDriver(0x%p)\n", driverClass
));
64 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, &msg
->mID
);
67 struct driverNode
*drvnode
= OOP_INST_DATA(cl
, o
);
68 struct TagItem tags
[] =
70 { aHidd_Mouse_IrqHandler
, (IPTR
)GlobalCallback
},
71 { aHidd_Mouse_IrqHandlerData
, (IPTR
)drvnode
},
72 { TAG_MORE
, (IPTR
)msg
->attrList
}
75 drvnode
->drv
= OOP_NewObject(driverClass
, NULL
, tags
);
76 D(bug("[Mouse] Driver node 0x%p, driver 0x%p\n", drvnode
, drvnode
->drv
));
80 struct mouse_staticdata
*csd
= CSD(cl
);
83 OOP_GetAttr(drvnode
->drv
, aHidd_Mouse_Extended
, &val
);
84 D(bug("[Mouse] Extended event: %d\n", val
));
87 drvnode
->flags
= vHidd_Mouse_Extended
;
91 OOP_GetAttr(drvnode
->drv
, aHidd_Mouse_RelativeCoords
, &val
);
92 D(bug("[Mouse] Relative coordinates: %d\n", val
));
93 drvnode
->flags
= val
? vHidd_Mouse_Relative
: 0;
95 /* This enables sending interrupts to clients */
96 drvnode
->callbacks
= &csd
->callbacks
;
103 * One more trick saving us from headache with OOP_GetMethodID():
104 * Given a method ID, we can obtain MethodBase of the same
105 * interface by simply subtracting method offset.
107 OOP_MethodID rootMethodBase
= msg
->mID
- moRoot_New
;
108 OOP_MethodID dispose_msg
= rootMethodBase
+ moRoot_Dispose
;
110 OOP_DoSuperMethod(cl
, o
, &dispose_msg
);
116 void DriverData__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
118 struct Library
*OOPBase
= CSD(cl
)->cs_OOPBase
;
119 struct driverNode
*drvnode
= OOP_INST_DATA(cl
, o
);
121 OOP_DisposeObject(drvnode
->drv
);
122 OOP_DoSuperMethod(cl
, o
, msg
);