From fa9b94e3775828c08fcab3fb158d8bea820c7949 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 4 May 2018 08:23:37 +0200 Subject: [PATCH] API update for input_normalizer, depot recipes Update the input_normalizer to use new input event and timer APIs. Add a depot package and a test. Fix #103 --- recipes/src/input_normalizer/content.mk | 2 + recipes/src/input_normalizer/hash | 1 + recipes/src/input_normalizer/used_apis | 4 + run/input_normalizer.run | 179 ++++++++++++++++++++++++ src/server/input_normalizer/main.cc | 66 ++++----- 5 files changed, 217 insertions(+), 35 deletions(-) create mode 100644 recipes/src/input_normalizer/content.mk create mode 100644 recipes/src/input_normalizer/hash create mode 100644 recipes/src/input_normalizer/used_apis create mode 100644 run/input_normalizer.run diff --git a/recipes/src/input_normalizer/content.mk b/recipes/src/input_normalizer/content.mk new file mode 100644 index 0000000..76179c5 --- /dev/null +++ b/recipes/src/input_normalizer/content.mk @@ -0,0 +1,2 @@ +SRC_DIR = src/server/input_normalizer +include $(GENODE_DIR)/repos/base/recipes/src/content.inc diff --git a/recipes/src/input_normalizer/hash b/recipes/src/input_normalizer/hash new file mode 100644 index 0000000..f606e8f --- /dev/null +++ b/recipes/src/input_normalizer/hash @@ -0,0 +1 @@ +2018-05-04 684010e420025fbff56c55549e5988bee357a9c9 diff --git a/recipes/src/input_normalizer/used_apis b/recipes/src/input_normalizer/used_apis new file mode 100644 index 0000000..b827947 --- /dev/null +++ b/recipes/src/input_normalizer/used_apis @@ -0,0 +1,4 @@ +base +input_session +timer_session +os diff --git a/run/input_normalizer.run b/run/input_normalizer.run new file mode 100644 index 0000000..83b7a19 --- /dev/null +++ b/run/input_normalizer.run @@ -0,0 +1,179 @@ +# +# Build +# + +assert_spec x86 + +set build_components { + core init + drivers/timer + server/dynamic_rom + server/input_normalizer + test/input +} + +source ${genode_dir}/repos/base/run/platform_drv.inc +append_platform_drv_build_components + +lappend_if [have_spec ps2] build_components drivers/input/spec/ps2 +lappend_if [have_spec sdl] build_components drivers/framebuffer/spec/sdl + +build $build_components + +create_boot_directory + +# +# Generate config +# + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_platform_drv_config + +append_if [have_spec ps2] config { + + + + + + + + + + + + + + + + + } + +append_if [have_spec sdl] config { + + + + + + + + + + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append config { +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core ld.lib.so init + timer dynamic_rom + input_normalizer + test-input +} + +# platform-specific modules +append_platform_drv_boot_modules + +lappend_if [have_spec ps2] boot_modules ps2_drv +lappend_if [have_spec sdl] boot_modules fb_sdl + +build_boot_image $boot_modules + + +run_genode_until forever diff --git a/src/server/input_normalizer/main.cc b/src/server/input_normalizer/main.cc index 90b1e04..61ea35d 100644 --- a/src/server/input_normalizer/main.cc +++ b/src/server/input_normalizer/main.cc @@ -6,10 +6,10 @@ */ /* - * Copyright (C) 2014-2016 Genode Labs GmbH + * Copyright (C) 2014-2018 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. + * under the terms of the GNU Affero General Public License version 3. */ /* Genode includes */ @@ -47,7 +47,8 @@ struct Input_normalizer::Main return value; } - unsigned const period_us = config_period_ms() * 1000; + Microseconds const period_us = + Microseconds{config_period_ms() * 1000}; /* input session provided by our parent */ Input::Connection parent_input { env }; @@ -64,48 +65,46 @@ struct Input_normalizer::Main /* Timer session for delaying events */ Timer::Connection timer { env }; - enum { STAY_ACTIVE = 10 }; - int timer_active = 0; + /* submit after delay */ + void handle_timeout(Duration) + { + if (!queue.empty()) + queue.submit_signal(); + } - /* signaled by input */ + Timer::One_shot_timeout
burst_timeout = + { timer, *this, &Main::handle_timeout }; + + /* signaled by input signal */ void handle_input() { using namespace Input; - /* forward the queue */ + /* + * laggy pointing is upleasant, so signal downstream if + * there is anything other than button presses upstream, + * otherwise notify downstream after a timeout + */ + bool notify = false; + parent_input.for_each_event([&] (Event const &e) { - /* - * laggy pointing is upleasant, so signal the client if - * there is anything other than button presses queued, - * otherwise notify the client when the timer fires - */ - queue.add(e, (e.type() != Event::PRESS) && (e.type() != Event::RELEASE)); + if (!e.press() && !e.release()) + notify = true; + enum { SUBMIT_NOW = false }; + queue.add(e, SUBMIT_NOW); }); - if (timer_active < 1) /* wake up the timer */ - timer.trigger_periodic(period_us); - - timer_active = STAY_ACTIVE; + if (notify) { + queue.submit_signal(); + burst_timeout.discard(); + } else if (!burst_timeout.scheduled()) { + burst_timeout.schedule(period_us); + } } Signal_handler
input_handler = { env.ep(), *this, &Main::handle_input }; - /* signaled by timer */ - void handle_timer() - { - if (queue.empty()) { - --timer_active; - /* stop the timer if nothing is happening */ - if (timer_active < 1) - timer.trigger_periodic(0); - } else - queue.submit_signal(); - } - - Signal_handler
timer_handler = - { env.ep(), *this, &Main::handle_timer }; - /** * Constructor */ @@ -116,9 +115,6 @@ struct Input_normalizer::Main /* register input handler */ parent_input.sigh(input_handler); - /* register timeout handler */ - timer.sigh(timer_handler); - /* announce service */ env.parent().announce(env.ep().manage(input_root)); }