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