message broadcast implementation unit test PASS

...was indeed dead easy to implement
This commit is contained in:
Fischlurch 2016-02-14 02:20:51 +01:00
parent b5b62f101f
commit 44bb044eee
5 changed files with 72 additions and 7 deletions

View file

@ -156,6 +156,21 @@ namespace ctrl {
}
/** broadcast a notification message to all currently connected bus terminals.
* @param mark the actual state update or notification message to be delivered
* @return number of notified terminals.
* @remarks this call assumes that "somewhere" within the UI-Bus
* a distribution node or hub is installed, with the ability
* to find all currently connected terminals. In the standard
* configuration this is implemented by the ctrl::Nexus
*/
size_t
BusTerm::markAll (GenNode const& mark)
{
return theBus_.markAll (mark);
}
/**
* @internal establish new down-link connection form UI-Bus
* @param node reference to the [Tangible] to be connected.

View file

@ -110,6 +110,8 @@ namespace ctrl{
virtual void note (ID subject, GenNode const& mark);
virtual bool mark (ID subject, GenNode const& mark);
virtual size_t markAll (GenNode const& mark);
virtual operator string() const;
void note (GenNode const& mark);

View file

@ -103,6 +103,17 @@ namespace ctrl{
}
}
/** broadcast a notification to all connected terminal nodes.
* @note just uses the contents of the current routing table in arbitrary order.
*/
virtual size_t
markAll (GenNode const& mark) override
{
for (auto& entry : routingTable_)
this->mark (entry.first, mark);
return routingTable_.size();
}
/** add a new down-link connection to the routing table
* @param identity the [endpoint-ID](\ref BusTerm::endpointID_) used
* to address the new element to be connected to the bus.

View file

@ -308,10 +308,6 @@ namespace test {
CHECK (mockA.isExpanded());
CHECK (not mockC.isExpanded());
CHECK (not mockC.isTouched());
cout << "____Nexus-Log_________________\n"
<< util::join(gui::test::Nexus::getLog(), "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
}
@ -391,16 +387,32 @@ namespace test {
CHECK (nexusLog.verifyEvent("mark", "Echo").id("Error")
.beforeCall("markAll").on("TestNexus").arg("Foxtrot")
.beforeEvent("broadcast", "Foxtrot")
.beforeEvent("Broadcast", "Foxtrot")
.beforeCall("mark").on("TestNexus").arg("bravo", "GenNode-ID(\"Message\")-DataCap|«string»|Foxtrot")
.beforeCall("doMsg").on("bravo").arg("Foxtrot")
.beforeEvent("TestNexus", "broadcasted mark to 3 terminals"));
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
// the order of dispatch is unspecified,
// but we know a regular mark call sequence happens for each connected terminal
CHECK (nexusLog.verifyCall("markAll").on("TestNexus").arg("Foxtrot")
.beforeCall("mark").on("TestNexus").arg("alpha", "Foxtrot")
.beforeCall("doMsg").on("alpha").arg("Foxtrot")
.beforeEvent("TestNexus", "successfully broadcasted"));
CHECK (nexusLog.verifyCall("markAll").on("TestNexus").arg("Foxtrot")
.beforeCall("mark").on("TestNexus").arg("bravo", "Foxtrot")
.beforeCall("doMsg").on("bravo").arg("Foxtrot")
.beforeEvent("TestNexus", "successfully broadcasted"));
CHECK (nexusLog.verifyCall("markAll").on("TestNexus").arg("Foxtrot")
.beforeCall("mark").on("TestNexus").arg("charly", "Foxtrot")
.beforeCall("doMsg").on("charly").arg("Foxtrot")
.beforeEvent("TestNexus", "successfully broadcasted"));
cout << "____Nexus-Log_________________\n"
<< util::join(nexusLog, "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
}
@ -408,6 +420,12 @@ namespace test {
clearStates()
{
UNIMPLEMENTED ("broadcast state reset");
EventLog nexusLog = gui::test::Nexus::startNewLog();
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
cout << "____Nexus-Log_________________\n"
<< util::join(nexusLog, "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP
gui::test::Nexus::setStateMarkHandler(); // deinstall custom command handler
}

View file

@ -201,6 +201,16 @@ namespace test{
}
}
virtual size_t
markAll (GenNode const& mark) override
{
log_.call(this, "markAll", mark);
log_.event("Broadcast", _Fmt("Broadcast mark(\"%s\"): %s") % mark.idi.getSym() % mark.data);
size_t cnt = BusHub::markAll (mark);
log_.event("TestNexus", _Fmt("successfully broadcasted mark to %d terminals") % cnt);
return cnt;
}
virtual BusTerm&
routeAdd (ID identity, Tangible& newNode) override
{
@ -326,6 +336,15 @@ namespace test{
return false;
}
virtual size_t
markAll (GenNode const& mark) override
{
log().call(this, "markAll", mark);
log().error ("request to broadcast to all Zombies");
cerr << "broadcast message -> ZombieNexus" <<endl;
return 0;
}
virtual BusTerm&
routeAdd (ID identity, Tangible& newNode) override
{