draft implementation of diagnostic command handler

This commit is contained in:
Fischlurch 2016-01-22 19:44:17 +01:00
parent cc310521a3
commit 1dc9642ec4
4 changed files with 112 additions and 5 deletions

View file

@ -116,7 +116,7 @@ namespace control {
* @throw error::Invalid if command not
* registered or incompletely defined.
*/
Command
Command
Command::get (Symbol cmdID)
{
Command cmd = CommandRegistry::instance().queryIndex (cmdID);

View file

@ -186,14 +186,13 @@ namespace test {
TimeSpan clip (Time(1,2,3), lib::test::randTime());
LuidH luid;
// we cannot invoke commands prior to binding arguments
VERIFY_ERROR (UNBOUND_ARGUMENTS, mock.issueCommand(cmd) );
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
mock.issueCommand(cmd);
cout << "____Nexus-Log_________________\n"
<< util::join(gui::test::Nexus::getLog(), "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
// we cannot invoke commands prior to binding arguments
VERIFY_ERROR (UNBOUND_ARGUMENTS, mock.issueCommand(cmd) );
// proper argument typing is ensured while dispatching the bind message.
VERIFY_ERROR (INVALID_ARGUMENTS, mock.prepareCommand(cmd, Rec({"lalala"})) );

View file

@ -48,6 +48,7 @@
#include "test/test-nexus.hpp"
#include "lib/test/event-log.hpp"
#include "gui/ctrl/nexus.hpp"
#include "proc/control/command.hpp"
#include "lib/diff/gen-node.hpp"
#include "lib/idi/entry-id.hpp"
#include "lib/idi/genfunc.hpp"
@ -69,6 +70,9 @@ using lib::diff::DataValues;
using lib::idi::instanceTypeID;
using lib::test::EventLog;
using gui::ctrl::BusTerm;
using proc::control::Command;
using proc::control::CommandImpl;
using proc::control::HandlingPattern;
using util::_Fmt;
//using util::contains;
//using util::isnil;
@ -76,7 +80,7 @@ using util::_Fmt;
namespace gui {
namespace test{
namespace { // quick-n-dirty string table implementation
namespace { // quick-n-dirty symbol table implementation
/** @warning grows eternally, never shrinks */
std::deque<string> idStringBuffer; ////////////////////////////////TICKET #158 replace by symbol table
@ -88,6 +92,9 @@ namespace test{
idStringBuffer.emplace_back (std::forward<string> (idString));
return Symbol (idStringBuffer.back().c_str());
}
////////////////////////(End)symbol-table hack
namespace { // internal details
@ -422,6 +429,103 @@ namespace test{
}
namespace { // install a diagnostic dummy-command-handler
class SimulatedCommandHandler
: public Variant<DataValues>::Predicate
, public HandlingPattern
{
mutable EventLog log_;
Command command_;
/* ==== HandlingPattern - Interface ==== */
void
performExec (CommandImpl& command) const override
{
log_.call ("TestNexus", "exec");
command.invokeCapture();
command.invokeOperation();
}
void
performUndo (CommandImpl& command) const override
{
log_.call ("TestNexus", "undo");
command.invokeUndo();
}
bool
isValid() const override
{
return true;
}
/* ==== CommandHandler ==== */
bool
handle (Rec const& argBinding) override
{
log_.event("TestNexus", "bound command arguments "+string(argBinding));
}
bool
handle (int const&) override
{
log_.event("TestNexus", "trigger "+string(command_));
return command_.exec (*this);
}
static Command
retrieveCommand (GenNode const& cmdMsg)
{
Symbol cmdID {cmdMsg.idi.getSym().c_str()};
return Command::get (cmdID);
}
public:
SimulatedCommandHandler (GenNode const& cmdMsg)
: log_(Nexus::getLog())
, command_(retrieveCommand(cmdMsg))
{
log_.event("TestNexus", "HANDLING Command-Message for "+string(command_));
if (not cmdMsg.data.accept (*this))
log_.warn(_Fmt("FAILED to handle command-message %s in test-mode") % cmdMsg);
}
bool
invokedExec()
{
return log_.verifyCall("exec").on(this);
}
bool
invokedUndo()
{
return log_.verifyCall("undo").on(this)
.afterCall("exec");
}
};
}//(End)diagnostic dummy-command-handler
void
Nexus::prepareDiagnosticCommandHandler()
{
testNexus().installCommandHandler(
[](GenNode const& cmdMsg)
{
SimulatedCommandHandler{cmdMsg};
});
}
bool
Nexus::canInvoke(Cmd cmd)

View file

@ -109,6 +109,9 @@ namespace test{
template<typename...ARGS>
static bool wasInvoked (Cmd, ARGS const& ...args);
private:
static void prepareDiagnosticCommandHandler();
};
@ -117,6 +120,7 @@ namespace test{
inline interact::InvocationTrail
Nexus::prepareMockCmd()
{
prepareDiagnosticCommandHandler();
return Cmd {PlaceholderCommand<ARGS...>::fabricateNewInstance(getLog())};
}