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>
23 #include <hidd/unixio_inline.h>
25 #include LC_LIBDEFS_FILE
27 #include "linuxinput_intern.h"
29 #include <linux/input.h>
34 * Some attrbases needed as global vars.
35 * These are write-once read-many.
37 OOP_AttrBase HiddKbdAB
;
38 OOP_AttrBase HiddMouseAB
;
40 static const struct OOP_ABDescr abd
[] =
42 { IID_Hidd_Kbd
, &HiddKbdAB
},
43 { IID_Hidd_Mouse
, &HiddMouseAB
},
47 VOID
Update_EventHandlers(struct LinuxInput_staticdata
*lsd
)
49 struct EventHandler
* eh
;
50 ForeachNode(&lsd
->eventhandlers
, eh
)
52 eh
->mousehidd
= lsd
->mousehidd
;
53 eh
->kbdhidd
= lsd
->kbdhidd
;
54 eh
->unixio
= lsd
->unixio
;
58 static inline void _sprintf(UBYTE
*buffer
, UBYTE
*format
, ...)
62 va_start(args
, format
);
63 VNewRawDoFmt(format
, RAWFMTFUNC_STRING
, buffer
, args
);
67 static VOID
Enumerate_InputDevices(struct LinuxInput_staticdata
*lsd
)
77 struct EventHandler
* eh
= NULL
;
79 _sprintf(eventdev
, "/dev/input/event%d", i
);
81 D(bug("[LinuxInput] Testing %s\n", eventdev
));
83 fd
= Hidd_UnixIO_OpenFile(lsd
->unixio
, eventdev
, O_RDONLY
, 0, &ioerr
);
87 read
= Hidd_UnixIO_IOControlFile(lsd
->unixio
, fd
, EVIOCGBIT(0, EV_MAX
), ¶m
,&ioerr
);
92 eh
= AllocVec(sizeof(struct EventHandler
), MEMF_PUBLIC
| MEMF_CLEAR
);
94 eh
->capabilities
= CAP_NONE
;
96 if ((param
& (1 << EV_REP
)) && (param
& (1 << EV_KEY
)))
99 eh
->capabilities
|= CAP_KEYBOARD
;
100 D(bug("[LinuxInput] Found Keyboard\n"));
103 if ((param
& (1 << EV_REL
)) && (param
& (1 << EV_KEY
)))
106 eh
->capabilities
|= CAP_MOUSE
;
107 D(bug("[LinuxInput] Found Mouse\n"));
111 if (eh
->capabilities
!= CAP_NONE
)
112 ADDHEAD(&lsd
->eventhandlers
, eh
);
120 VOID
Init_LinuxInput_inputtask(struct EventHandler
* eh
);
121 VOID
Kill_LinuxInput_inputtask(struct EventHandler
* eh
);
123 static int Init_Hidd(LIBBASETYPEPTR LIBBASE
)
125 struct EventHandler
* eh
;
127 InitSemaphore(&LIBBASE
->lsd
.sema
);
128 NEWLIST(&LIBBASE
->lsd
.eventhandlers
);
131 * We cannot cooperate with any other driver at the moment.
132 * Attempting to do so results in duplicating events (one from
133 * X11 and another from us).
135 if (OOP_FindClass("hidd.gfx.x11"))
138 D(bug("[LinuxInput] Opening UnixIO... "));
139 LIBBASE
->lsd
.unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
);
140 if (!LIBBASE
->lsd
.unixio
)
147 Enumerate_InputDevices(&LIBBASE
->lsd
);
148 if (IsListEmpty(&LIBBASE
->lsd
.eventhandlers
))
151 if (!OOP_ObtainAttrBases(abd
))
154 Update_EventHandlers(&LIBBASE
->lsd
);
156 ForeachNode(&LIBBASE
->lsd
.eventhandlers
, eh
)
158 Init_LinuxInput_inputtask(eh
);
161 D(bug("[LinuxInput] Finished Init_Hidd"));
166 static int Expunge_Hidd(LIBBASETYPEPTR LIBBASE
)
169 struct EventHandler
* eh
;
171 ForeachNode(&LIBBASE
->lsd
.eventhandlers
, eh
)
173 Kill_LinuxInput_inputtask(eh
);
174 Hidd_UnixIO_CloseFile(LIBBASE
->lsd
.unixio
, eh
->eventdev
, &ioerr
);
177 OOP_ReleaseAttrBases(abd
);
179 if (LIBBASE
->lsd
.unixio
)
180 OOP_DisposeObject(LIBBASE
->lsd
.unixio
);
185 ADD2INITLIB(Init_Hidd
, 1)
186 ADD2EXPUNGELIB(Expunge_Hidd
, 1)