Re-enabled use of AROS.Boot file due to lack of general enthusiasm for
[tangerine.git] / arch / all-linux / hidd / mouseclass.c
blobd411dc479bab2c71f9dafca92de120fcda098433
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Linux hidd handling mouse events.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #include <string.h>
18 #include <proto/utility.h>
19 #include <proto/oop.h>
20 #include <oop/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
31 #define DEBUG 0
32 #include <aros/debug.h>
34 static OOP_AttrBase HiddMouseAB;
36 static struct OOP_ABDescr attrbases[] =
38 { IID_Hidd_Mouse, &HiddMouseAB },
39 { NULL, NULL }
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);
56 if (o)
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)))
64 ULONG idx;
66 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
68 switch (idx)
70 case aoHidd_Mouse_IrqHandler:
71 data->mouse_callback = (VOID (*)())tag->ti_Data;
72 break;
74 case aoHidd_Mouse_IrqHandlerData:
75 data->callbackdata = (APTR)tag->ti_Data;
76 break;
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);
87 return o;
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)
103 ULONG idx;
105 if (IS_HIDDMOUSE_ATTR(msg->attrID, idx))
107 switch (idx)
109 case aoHidd_Mouse_RelativeCoords:
110 *msg->storage = TRUE;
111 return;
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);
126 return;
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))
139 return FALSE;
141 mousefd = open(MOUSE_DEVNAME, O_RDONLY);
142 if (-1 == mousefd) {
143 OOP_ReleaseAttrBases(attrbases);
145 kprintf("!!! init_mous(): COULD NOT OPEND MOUSE DEVICE %s: %s\n"
146 , MOUSE_DEVNAME, strerror(errno));
148 return FALSE;
149 } else {
150 file_opened = TRUE;
151 LIBBASE->lsd.mousefd = mousefd;
153 return TRUE;
160 /*************** free_mouseclass() **********************************/
161 static int Expunge_LinuxMouseClass(LIBBASETYPEPTR LIBBASE)
163 if (file_opened) {
164 close(mousefd);
167 OOP_ReleaseAttrBases(attrbases);
169 return TRUE;
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;
181 if (!mid)
182 mid = OOP_GetMethodID(IID_Hidd_LinuxMouse, moHidd_LinuxMouse_HandleEvent);
184 p.mID = mid;
185 p.mouseEvent = mouseEvent;
187 OOP_DoMethod(o, (OOP_Msg)&p);