1 /* 2 * Provide access to keypad events on the configured device. 3 * 4 * Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/devices/dataspace.h> 23 #include <l4/devices/keypad-loader.h> 24 25 #include "input-event-server.h" 26 #include "input-keypad-client.h" 27 28 #include <l4/re/event> 29 30 #include <ipc/server.h> 31 32 #include "input_server.h" 33 34 35 36 static void handler(Input_event event, void *priv) 37 { 38 Input_event_server *server = (Input_event_server *) priv; 39 40 server->send_event(event.type, event.code, event.value); 41 } 42 43 44 45 int main(void) 46 { 47 /* Load the keypad details from the configured library. */ 48 49 Keypad_generic *keypad = load_keypad(); 50 Input_keypad_client client(keypad); 51 void *buffer; 52 53 /* Memory allocation capability for the event data. */ 54 55 l4re_ds_t mem = allocate_data(L4_PAGESIZE, &buffer); 56 57 if (l4_is_invalid_cap(mem)) 58 return 1; 59 60 /* Event buffer for the data. */ 61 62 L4Re::Event_buffer events(buffer, L4_PAGESIZE); 63 64 /* Initialise and register a server object. */ 65 66 Input_event_server obj(mem, events); 67 68 /* Attach the event handler and wait for events. */ 69 70 client.attach(handler, (void *) &obj); 71 72 /* Bind and start the IPC server loop. */ 73 74 if (ipc_server_loop_for(Input, &obj, "ev")) 75 return 1; 76 77 return 0; 78 }