Looper: implement core operation control logic
This commit is contained in:
parent
9c9e75ee01
commit
30254da95f
4 changed files with 46 additions and 20 deletions
|
|
@ -72,8 +72,18 @@ namespace control {
|
|||
|
||||
/* == diagnostics == */
|
||||
|
||||
// size_t size() const ;
|
||||
// bool empty() const ;
|
||||
size_t
|
||||
size() const
|
||||
{
|
||||
TODO ("implement queue");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const
|
||||
{
|
||||
return 0 == size();
|
||||
}
|
||||
|
||||
};
|
||||
////////////////TODO 12/16 currently just fleshing out the API....
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
//#include "lib/depend.hpp"
|
||||
|
||||
//#include <memory>
|
||||
//#include <functional>
|
||||
#include <functional>
|
||||
|
||||
|
||||
|
||||
|
|
@ -57,6 +57,7 @@ namespace control {
|
|||
|
||||
// using lib::Symbol;
|
||||
// using std::bind;
|
||||
// using std::function;
|
||||
|
||||
namespace {
|
||||
/**
|
||||
|
|
@ -77,21 +78,38 @@ namespace control {
|
|||
*/
|
||||
class Looper
|
||||
{
|
||||
bool shutdown = false;
|
||||
using Predicate = std::function<bool(void)>;
|
||||
|
||||
bool shutdown_ = false;
|
||||
bool disabled_ = false;
|
||||
Predicate hasCommandsPending_;
|
||||
|
||||
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 isDisabled() const { return false; }
|
||||
bool isDying() const { return shutdown; }
|
||||
bool isIdle() const { return not (isWorking() or needBuild() or isDisabled()); }
|
||||
|
||||
|
||||
/* == operation control == */
|
||||
|
||||
void
|
||||
triggerShutdown()
|
||||
{
|
||||
shutdown_ = true;
|
||||
}
|
||||
|
||||
/** state fusion to control (timed) wait */
|
||||
bool
|
||||
requireAction()
|
||||
|
|
@ -115,12 +133,6 @@ namespace control {
|
|||
return wakeTimeout_ms;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
triggerShutdown()
|
||||
{
|
||||
shutdown = true;
|
||||
}
|
||||
/* == diagnostics == */
|
||||
|
||||
// size_t size() const ;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,10 @@ namespace control {
|
|||
, bind (&DispatcherLoop::run, this, notification))
|
||||
, commandService_(new SessionCommandService(*this))
|
||||
, queue_()
|
||||
, looper_()
|
||||
, looper_([&]() -> bool
|
||||
{
|
||||
return not queue_.empty();
|
||||
})
|
||||
{
|
||||
INFO (session, "Proc-Dispatcher running...");
|
||||
}
|
||||
|
|
@ -162,8 +165,7 @@ namespace control {
|
|||
void
|
||||
awaitAction()
|
||||
{
|
||||
Lock(this).wait(looper_,
|
||||
&Looper::requireAction,
|
||||
Lock(this).wait(looper_, &Looper::requireAction,
|
||||
looper_.getTimeout());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace test {
|
|||
Looper
|
||||
install()
|
||||
{
|
||||
return Looper{};
|
||||
return Looper([&](){ return has_commands_in_queue; });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -143,12 +143,14 @@ namespace test {
|
|||
CHECK ( looper.requireAction());
|
||||
CHECK ( looper.isWorking());
|
||||
CHECK (not looper.isIdle());
|
||||
CHECK (looper.shallLoop());
|
||||
|
||||
setup.has_commands_in_queue = false;
|
||||
|
||||
CHECK (not looper.requireAction());
|
||||
CHECK (not looper.isWorking());
|
||||
CHECK ( looper.isIdle());
|
||||
CHECK (looper.shallLoop());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue