2 Copyright © 2013, The AROS Development Team. All rights reserved.
5 Desc: LinuxInput hidd initialization code.
11 #define __OOP_NOATTRBASES__
13 #include <exec/rawfmt.h>
14 #include <aros/symbolsets.h>
15 #include <aros/debug.h>
16 #include <utility/utility.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
20 #include <hidd/mouse.h>
21 #include <hidd/keyboard.h>
22 #include <hidd/unixio.h>
24 #include LC_LIBDEFS_FILE
26 #include "linuxinput_intern.h"
28 #include <linux/input.h>
33 * Some attrbases needed as global vars.
34 * These are write-once read-many.
36 OOP_AttrBase HiddKbdAB
;
37 OOP_AttrBase HiddMouseAB
;
39 static const struct OOP_ABDescr abd
[] =
41 { IID_Hidd_Kbd
, &HiddKbdAB
},
42 { IID_Hidd_Mouse
, &HiddMouseAB
},
46 VOID
Update_EventHandlers(struct LinuxInput_staticdata
*lsd
)
48 struct EventHandler
* eh
;
49 ForeachNode(&lsd
->eventhandlers
, eh
)
51 eh
->mousehidd
= lsd
->mousehidd
;
52 eh
->kbdhidd
= lsd
->kbdhidd
;
53 eh
->unixio
= lsd
->unixio
;
57 static inline void _sprintf(UBYTE
*buffer
, UBYTE
*format
, ...)
61 va_start(args
, format
);
62 VNewRawDoFmt(format
, RAWFMTFUNC_STRING
, buffer
, args
);
66 static VOID
Enumerate_InputDevices(struct LinuxInput_staticdata
*lsd
)
76 struct EventHandler
* eh
= NULL
;
78 _sprintf(eventdev
, "/dev/input/event%d", i
);
80 D(bug("[LinuxInput] Testing %s\n", eventdev
));
82 fd
= Hidd_UnixIO_OpenFile(lsd
->unixio
, eventdev
, O_RDONLY
, 0, &ioerr
);
86 read
= Hidd_UnixIO_IOControlFile(lsd
->unixio
, fd
, EVIOCGBIT(0, EV_MAX
), ¶m
,&ioerr
);
91 eh
= AllocVec(sizeof(struct EventHandler
), MEMF_PUBLIC
| MEMF_CLEAR
);
93 eh
->capabilities
= CAP_NONE
;
95 if ((param
& (1 << EV_REP
)) && (param
& (1 << EV_KEY
)))
98 eh
->capabilities
|= CAP_KEYBOARD
;
99 D(bug("[LinuxInput] Found Keyboard\n"));
102 if ((param
& (1 << EV_REL
)) && (param
& (1 << EV_KEY
)))
105 eh
->capabilities
|= CAP_MOUSE
;
106 D(bug("[LinuxInput] Found Mouse\n"));
110 if (eh
->capabilities
!= CAP_NONE
)
111 ADDHEAD(&lsd
->eventhandlers
, eh
);
119 VOID
Init_LinuxInput_inputtask(struct EventHandler
* eh
);
120 VOID
Kill_LinuxInput_inputtask(struct EventHandler
* eh
);
122 static int Init_Hidd(LIBBASETYPEPTR LIBBASE
)
124 struct EventHandler
* eh
;
126 InitSemaphore(&LIBBASE
->lsd
.sema
);
127 NEWLIST(&LIBBASE
->lsd
.eventhandlers
);
130 * We cannot cooperate with any other driver at the moment.
131 * Attempting to do so results in duplicating events (one from
132 * X11 and another from us).
134 if (OOP_FindClass("hidd.gfx.x11"))
137 D(bug("[LinuxInput] Opening UnixIO... "));
138 LIBBASE
->lsd
.unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
);
139 if (!LIBBASE
->lsd
.unixio
)
146 Enumerate_InputDevices(&LIBBASE
->lsd
);
147 if (IsListEmpty(&LIBBASE
->lsd
.eventhandlers
))
150 if (!OOP_ObtainAttrBases(abd
))
153 Update_EventHandlers(&LIBBASE
->lsd
);
155 ForeachNode(&LIBBASE
->lsd
.eventhandlers
, eh
)
157 Init_LinuxInput_inputtask(eh
);
160 D(bug("[LinuxInput] Finished Init_Hidd"));
165 static int Expunge_Hidd(LIBBASETYPEPTR LIBBASE
)
168 struct EventHandler
* eh
;
170 ForeachNode(&LIBBASE
->lsd
.eventhandlers
, eh
)
172 Kill_LinuxInput_inputtask(eh
);
173 Hidd_UnixIO_CloseFile(LIBBASE
->lsd
.unixio
, eh
->eventdev
, &ioerr
);
176 OOP_ReleaseAttrBases(abd
);
178 if (LIBBASE
->lsd
.unixio
)
179 OOP_DisposeObject(LIBBASE
->lsd
.unixio
);
184 ADD2INITLIB(Init_Hidd
, 1)
185 ADD2EXPUNGELIB(Expunge_Hidd
, 1)