diff --git a/src/proc/control/looper.hpp b/src/proc/control/looper.hpp index 3fea9a8f8..148f8bc24 100644 --- a/src/proc/control/looper.hpp +++ b/src/proc/control/looper.hpp @@ -110,6 +110,12 @@ namespace control { shutdown_ = true; } + void + enableProcessing(bool yes =true) + { + disabled_ = not yes; + } + /** state fusion to control (timed) wait */ bool requireAction() diff --git a/tests/core/proc/control/dispatcher-looper-test.cpp b/tests/core/proc/control/dispatcher-looper-test.cpp index 6c76f95d8..5634248e6 100644 --- a/tests/core/proc/control/dispatcher-looper-test.cpp +++ b/tests/core/proc/control/dispatcher-looper-test.cpp @@ -91,6 +91,8 @@ namespace test { verifyBasics(); verifyShutdown(); verifyWakeupActivity(); + verifyShutdown_stops_processing(); + verifyDisabling_stops_processing(); } @@ -152,6 +154,131 @@ namespace test { CHECK ( looper.isIdle()); CHECK (looper.shallLoop()); } + + + void + verifyShutdown_stops_processing() + { + Setup setup; + Looper looper = setup.install(); + + CHECK (not looper.isDying()); + CHECK (looper.shallLoop()); + + CHECK (not looper.requireAction()); + CHECK (not looper.isWorking()); + CHECK ( looper.isIdle()); + + setup.has_commands_in_queue = true; + + CHECK ( looper.requireAction()); + CHECK ( looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + looper.triggerShutdown(); + + CHECK ( looper.requireAction()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK (not looper.shallLoop()); + CHECK ( looper.isDying()); + + setup.has_commands_in_queue = false; + + CHECK ( looper.requireAction()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK (not looper.shallLoop()); + CHECK ( looper.isDying()); + + setup.has_commands_in_queue = true; + + CHECK ( looper.requireAction()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK (not looper.shallLoop()); + CHECK ( looper.isDying()); + } + + + void + verifyDisabling_stops_processing() + { + Setup setup; + Looper looper = setup.install(); + + CHECK (not looper.requireAction()); + CHECK (not looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK ( looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + setup.has_commands_in_queue = true; // normal operation: pending commands will be processed + + CHECK ( looper.requireAction()); // ..causes wake-up + CHECK (not looper.isDisabled()); + CHECK ( looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + looper.enableProcessing(false); // disable processing + + CHECK (not looper.requireAction()); + CHECK ( looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + setup.has_commands_in_queue = false; // while disabled, state of the command queue has no effect + + CHECK (not looper.requireAction()); + CHECK ( looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + setup.has_commands_in_queue = true; + + CHECK (not looper.requireAction()); + CHECK ( looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + looper.enableProcessing(); // resume normal operation + + CHECK ( looper.requireAction()); + CHECK (not looper.isDisabled()); + CHECK ( looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + looper.enableProcessing(false); // disable again + + CHECK (not looper.requireAction()); + CHECK ( looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK ( looper.shallLoop()); + CHECK (not looper.isDying()); + + looper.triggerShutdown(); // wake-up for shutdown even from disabled state + + CHECK ( looper.requireAction()); + CHECK ( looper.isDisabled()); + CHECK (not looper.isWorking()); + CHECK (not looper.isIdle()); + CHECK (not looper.shallLoop()); + CHECK ( looper.isDying()); + } };