2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Linux hidd handling mouse events.
9 #define __OOP_NOATTRBASES__
11 #include <sys/types.h>
18 #include <proto/utility.h>
19 #include <proto/oop.h>
22 #include <hidd/hidd.h>
23 #include <hidd/mouse.h>
25 #include <aros/symbolsets.h>
27 #include "linux_intern.h"
29 #include LC_LIBDEFS_FILE
32 #include <aros/debug.h>
34 static OOP_AttrBase HiddMouseAB
;
36 static struct OOP_ABDescr attrbases
[] =
38 { IID_Hidd_Mouse
, &HiddMouseAB
},
43 OOP_Object
*LinuxMouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
45 BOOL has_mouse_hidd
= FALSE
;
47 ObtainSemaphore(&LSD(cl
)->sema
);
48 if (LSD(cl
)->mousehidd
)
49 has_mouse_hidd
= TRUE
;
50 ReleaseSemaphore(&LSD(cl
)->sema
);
52 if (has_mouse_hidd
) /* Cannot open twice */
53 return NULL
; /* Should have some error code here */
55 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
58 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
59 struct TagItem
*tag
, *tstate
;
61 tstate
= msg
->attrList
;
62 while ((tag
= NextTagItem((const struct TagItem
**)&tstate
)))
66 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
70 case aoHidd_Mouse_IrqHandler
:
71 data
->mouse_callback
= (VOID (*)())tag
->ti_Data
;
74 case aoHidd_Mouse_IrqHandlerData
:
75 data
->callbackdata
= (APTR
)tag
->ti_Data
;
80 } /* while (tags to process) */
82 /* Install the mouse hidd */
83 ObtainSemaphore(&LSD(cl
)->sema
);
84 LSD(cl
)->mousehidd
= o
;
85 ReleaseSemaphore(&LSD(cl
)->sema
);
90 VOID
LinuxMouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
92 ObtainSemaphore(&LSD(cl
)->sema
);
93 LSD(cl
)->mousehidd
= NULL
;
94 ReleaseSemaphore(&LSD(cl
)->sema
);
96 OOP_DoSuperMethod(cl
, o
, msg
);
101 VOID
LinuxMouse__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
105 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
))
109 case aoHidd_Mouse_RelativeCoords
:
110 *msg
->storage
= TRUE
;
115 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
119 VOID
LinuxMouse__Hidd_LinuxMouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_LinuxMouse_HandleEvent
*msg
)
122 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
124 data
->mouse_callback(data
->callbackdata
, msg
->mouseEvent
);
129 /******************** init_mouseclass() *********************************/
131 static int mousefd
= 0;
133 #define MOUSE_DEVNAME "/dev/psaux"
134 static BOOL file_opened
= FALSE
;
136 static int Init_LinuxMouseClass(LIBBASETYPEPTR LIBBASE
)
138 if (!OOP_ObtainAttrBases(attrbases
))
141 mousefd
= open(MOUSE_DEVNAME
, O_RDONLY
);
143 OOP_ReleaseAttrBases(attrbases
);
145 kprintf("!!! init_mous(): COULD NOT OPEND MOUSE DEVICE %s: %s\n"
146 , MOUSE_DEVNAME
, strerror(errno
));
151 LIBBASE
->lsd
.mousefd
= mousefd
;
160 /*************** free_mouseclass() **********************************/
161 static int Expunge_LinuxMouseClass(LIBBASETYPEPTR LIBBASE
)
167 OOP_ReleaseAttrBases(attrbases
);
172 ADD2INITLIB(Init_LinuxMouseClass
, 0)
173 ADD2EXPUNGELIB(Expunge_LinuxMouseClass
, 0)
176 VOID
HIDD_LinuxMouse_HandleEvent(OOP_Object
*o
, struct pHidd_Mouse_Event
*mouseEvent
)
178 static OOP_MethodID mid
= 0;
179 struct pHidd_LinuxMouse_HandleEvent p
;
182 mid
= OOP_GetMethodID(IID_Hidd_LinuxMouse
, moHidd_LinuxMouse_HandleEvent
);
185 p
.mouseEvent
= mouseEvent
;
187 OOP_DoMethod(o
, (OOP_Msg
)&p
);