Looper: implement core operation control logic

This commit is contained in:
Fischlurch 2016-12-16 19:21:06 +01:00
parent 9c9e75ee01
commit 30254da95f
4 changed files with 46 additions and 20 deletions

View file

@ -72,8 +72,18 @@ namespace control {
/* == diagnostics == */ /* == diagnostics == */
// size_t size() const ; size_t
// bool empty() const ; size() const
{
TODO ("implement queue");
return 0;
}
bool
empty() const
{
return 0 == size();
}
}; };
////////////////TODO 12/16 currently just fleshing out the API.... ////////////////TODO 12/16 currently just fleshing out the API....

View file

@ -48,7 +48,7 @@
//#include "lib/depend.hpp" //#include "lib/depend.hpp"
//#include <memory> //#include <memory>
//#include <functional> #include <functional>
@ -57,6 +57,7 @@ namespace control {
// using lib::Symbol; // using lib::Symbol;
// using std::bind; // using std::bind;
// using std::function;
namespace { namespace {
/** /**
@ -77,21 +78,38 @@ namespace control {
*/ */
class Looper class Looper
{ {
bool shutdown = false; using Predicate = std::function<bool(void)>;
bool shutdown_ = false;
bool disabled_ = false;
Predicate hasCommandsPending_;
public: public:
Looper() template<class FUN>
Looper(FUN determine_commands_are_waiting)
: hasCommandsPending_(determine_commands_are_waiting)
{ } { }
/* == working state == */ // standard copy acceptable
bool isWorking() const { return false; }
bool isIdle() const { return false; } /* == working state logic == */
bool isDying() const { return shutdown_; }
bool isDisabled() const { return disabled_ or isDying(); }
bool isWorking() const { return hasCommandsPending_() and not isDisabled(); }
bool needBuild() const { return false; } bool needBuild() const { return false; }
bool isDisabled() const { return false; } bool isIdle() const { return not (isWorking() or needBuild() or isDisabled()); }
bool isDying() const { return shutdown; }
/* == operation control == */
void
triggerShutdown()
{
shutdown_ = true;
}
/** state fusion to control (timed) wait */ /** state fusion to control (timed) wait */
bool bool
requireAction() requireAction()
@ -115,12 +133,6 @@ namespace control {
return wakeTimeout_ms; return wakeTimeout_ms;
} }
void
triggerShutdown()
{
shutdown = true;
}
/* == diagnostics == */ /* == diagnostics == */
// size_t size() const ; // size_t size() const ;

View file

@ -67,7 +67,10 @@ namespace control {
, bind (&DispatcherLoop::run, this, notification)) , bind (&DispatcherLoop::run, this, notification))
, commandService_(new SessionCommandService(*this)) , commandService_(new SessionCommandService(*this))
, queue_() , queue_()
, looper_() , looper_([&]() -> bool
{
return not queue_.empty();
})
{ {
INFO (session, "Proc-Dispatcher running..."); INFO (session, "Proc-Dispatcher running...");
} }
@ -162,8 +165,7 @@ namespace control {
void void
awaitAction() awaitAction()
{ {
Lock(this).wait(looper_, Lock(this).wait(looper_, &Looper::requireAction,
&Looper::requireAction,
looper_.getTimeout()); looper_.getTimeout());
} }

View file

@ -57,7 +57,7 @@ namespace test {
Looper Looper
install() install()
{ {
return Looper{}; return Looper([&](){ return has_commands_in_queue; });
} }
}; };
@ -143,12 +143,14 @@ namespace test {
CHECK ( looper.requireAction()); CHECK ( looper.requireAction());
CHECK ( looper.isWorking()); CHECK ( looper.isWorking());
CHECK (not looper.isIdle()); CHECK (not looper.isIdle());
CHECK (looper.shallLoop());
setup.has_commands_in_queue = false; setup.has_commands_in_queue = false;
CHECK (not looper.requireAction()); CHECK (not looper.requireAction());
CHECK (not looper.isWorking()); CHECK (not looper.isWorking());
CHECK ( looper.isIdle()); CHECK ( looper.isIdle());
CHECK (looper.shallLoop());
} }
}; };