Changed to colour every module ending with Source or Sink red
[senf.git] / senf / PPI / Connectors.cc
index 156a717..0813b41 100644 (file)
 prefix_ void senf::ppi::connector::Connector::connect(Connector & target)
 {
     // The connector is not registered -> route() or noroute() statement missing
-    SENF_ASSERT( module_ && 
+    SENF_ASSERT( module_,
                  "senf::ppi::connector::Connector::connect(): (source) "
                  "Missing route() or noroute()" );
     // The connector is already connected
-    SENF_ASSERT( ! peer_ &&
+    SENF_ASSERT( ! peer_,
                  "senf::ppi::connector::Connector::connect(): (source) "
                  "duplicate connection" );
     // The target connector is not registered -> route() or noroute() statement missing
-    SENF_ASSERT( target.module_ &&
+    SENF_ASSERT( target.module_,
                  "senf::ppi::connector::Connector::connect(): (target) "
                  "Missing route() or noroute()" );
     // The target connector is already connected
-    SENF_ASSERT( ! target.peer_ &&
+    SENF_ASSERT( ! target.peer_,
                  "senf::ppi::connector::Connector::connect(): (target) "
                  "duplicate connection" );
     if (! (packetTypeID() == typeid(void) ||
-           target.packetTypeID() == typeid(void) || 
+           target.packetTypeID() == typeid(void) ||
            packetTypeID() == target.packetTypeID()) )
-        throw IncompatibleConnectorsException() 
-            << ": " << prettyName(packetTypeID()) 
+        throw IncompatibleConnectorsException()
+            << ": " << prettyName(packetTypeID())
             << " [in module " << prettyName(typeid(*module_))  << "] "
             << ", " << prettyName(target.packetTypeID())
             << " [in module " << prettyName(typeid(*target.module_)) << "]";
-            
+
     peer_ = & target;
     target.peer_ = this;
 
@@ -84,8 +84,8 @@ prefix_ void senf::ppi::connector::Connector::trace(Packet const & p, char const
         return;
     SENF_LOG_BLOCK(({
                 std::string type (prettyName(p.typeId().id()));
-                log << "PPI packet trace: " << label << " 0x" << std::hex << p.id() << " " 
-                    << type.substr(21, type.size()-22) << " on " << & module() << " " 
+                log << "PPI packet trace: " << label << " 0x" << std::hex << p.id() << " "
+                    << type.substr(21, type.size()-22) << " on " << & module() << " "
                     << prettyName(typeid(module())) << " connector 0x" << this << "\n";
                 if (traceState_ == TRACE_CONTENTS)
                     p.dump(log);
@@ -98,14 +98,14 @@ prefix_ void senf::ppi::connector::Connector::throttleTrace(char const * label,
     if (traceState_ == NO_TRACING)
         return;
     SENF_LOG_BLOCK(({
-                log << "PPI throttling trace: " << label << " " << type << " on " << & module() 
+                log << "PPI throttling trace: " << label << " " << type << " on " << & module()
                     << " " << prettyName(typeid(module())) << " connector 0x" << this << "\n";
             }));
 }
 
 namespace senf { namespace ppi { namespace connector {
 
-    SENF_CONSOLE_REGISTER_ENUM_MEMBER( 
+    SENF_CONSOLE_REGISTER_ENUM_MEMBER(
         Connector, TraceState, (NO_TRACING)(TRACE_IDS)(TRACE_CONTENTS) );
 
 }}}
@@ -120,40 +120,44 @@ namespace {
     ConsoleRegister::ConsoleRegister()
     {
         senf::ppi::ModuleManager::instance().consoleDir()
-            .add("tracing", SENF_FNP(senf::ppi::connector::Connector::TraceState,
-                                     senf::ppi::connector::Connector::tracing, ()))
-            .doc("Log every packet sent or received by any module.\n"
-                 "There are three different tracing levels:\n"
-                 "\n"
-                 "    NO_TRACING      don't output any tracing information\n"
-                 "    TRACE_IDS       trace packet id's but do not show packet contents\n"
-                 "    TRACE_CONTENTS  trace complete packet contents\n"
-                 "\n"
-                 "A log message is generated whenever the packet traverses a connector. The\n"
-                 "TRACE_IDS log message has the following format:\n"
-                 "\n"
-                 "    PPI packet trace: <direction> <packet-id> <packet-type>\n"
-                 "                      on <module-id> <module-type> connector <connector-id>\n"
-                 "    PPI throttling trace: <direction> <throttle-msg>\n"
-                 "                      on <module-id> <module-type> connector <connector-id>\n"
-                 "\n"
-                 "The fields are:\n"
-                 "\n"
-                 "    direction       'IN' for packets/throttle notifications entering the module,\n"
-                 "                    'OUT' for packets/throttle notifications leaving it\n"
-                 "    packet-id       Numeric unique packet id. This value is unique for packets\n"
-                 "                    alive at the same time, packets at different times may (and\n"
-                 "                    will) share id's\n"
-                 "    packet-type     The type of the packet header\n"
-                 "    module-id       Unique module id\n"
-                 "    module-type     Type of the module the packet is sent to/from\n"
-                 "    connector-id    Unique connector id\n"
-                 "    throttle-msg    Type of throttling event\n");
+            .add("tracing", senf::console::factory::Command(
+                     SENF_FNP(senf::ppi::connector::Connector::TraceState,
+                              senf::ppi::connector::Connector::tracing, ()))
+                 .doc("Log every packet sent or received by any module.\n"
+                      "There are three different tracing levels:\n"
+                      "\n"
+                      "    NO_TRACING      don't output any tracing information\n"
+                      "    TRACE_IDS       trace packet id's but do not show packet contents\n"
+                      "    TRACE_CONTENTS  trace complete packet contents\n"
+                      "\n"
+                      "A log message is generated whenever the packet traverses a connector. The\n"
+                      "TRACE_IDS log message has the following format:\n"
+                      "\n"
+                      "    PPI packet trace: <direction> <packet-id> <packet-type>\n"
+                      "                      on <module-id> <module-type> connector <connector-id>\n"
+                      "    PPI throttling trace: <direction> <throttle-msg>\n"
+                      "                      on <module-id> <module-type> connector <connector-id>\n"
+                      "\n"
+                      "The fields are:\n"
+                      "\n"
+                      "    direction       'IN' for packets/throttle notifications entering the module,\n"
+                      "                    'OUT' for packets/throttle notifications leaving it\n"
+                      "    packet-id       Numeric unique packet id. This value is unique for packets\n"
+                      "                    alive at the same time, packets at different times may (and\n"
+                      "                    will) share id's\n"
+                      "    packet-type     The type of the packet header\n"
+                      "    module-id       Unique module id\n"
+                      "    module-type     Type of the module the packet is sent to/from\n"
+                      "    connector-id    Unique connector id\n"
+                      "    throttle-msg    Type of throttling event\n")
+                );
 
         senf::ppi::ModuleManager::instance().consoleDir()
-            .add("tracing", SENF_FNP(void, senf::ppi::connector::Connector::tracing,
-                                     (senf::ppi::connector::Connector::TraceState)))
-            .arg("state", "new tracing state");
+            .add("tracing", senf::console::factory::Command(
+                     SENF_FNP(void, senf::ppi::connector::Connector::tracing,
+                              (senf::ppi::connector::Connector::TraceState)))
+                 .arg("state", "new tracing state")
+                );
     }
 
     ConsoleRegister consoleRegister;
@@ -163,8 +167,9 @@ namespace {
 prefix_ void senf::ppi::connector::Connector::disconnect()
 {
     // Cannot disconnected a non-connected connector
-    SENF_ASSERT( peer_ &&
+    SENF_ASSERT( peer_,
                  "senf::ppi::connector::Connector::disconnect(): Not connected" );
+
     Connector & peer (*peer_);
     peer_ = 0;
     peer.peer_ = 0;
@@ -173,6 +178,9 @@ prefix_ void senf::ppi::connector::Connector::disconnect()
         enqueueInitializable();
     if (! peer.initializationScheduled())
         peer.enqueueInitializable();
+
+    v_disconnected();
+    peer.v_disconnected();
 }
 
 prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID()
@@ -180,6 +188,10 @@ prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID()
     return typeid(void);
 }
 
+prefix_ void senf::ppi::connector::Connector::v_disconnected()
+    const
+{}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::ppi::connector::PassiveConnector
 
@@ -206,7 +218,7 @@ prefix_ void senf::ppi::connector::PassiveConnector::v_unthrottleEvent()
 
 prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle()
 {
-    if (std::find_if(routes_.begin(), routes_.end(), 
+    if (std::find_if(routes_.begin(), routes_.end(),
                      boost::bind(&ForwardingRoute::throttled, _1)) == routes_.end()) {
         remoteThrottled_ = false;
         if (!nativeThrottled_)
@@ -260,6 +272,13 @@ prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRout
     notifyRoutes_.push_back(&route);
 }
 
+prefix_ void senf::ppi::connector::ActiveConnector::unregisterRoute(ForwardingRoute & route)
+{
+    NotifyRoutes::iterator i (std::find(notifyRoutes_.begin(), notifyRoutes_.end(), &route));
+    if (i != notifyRoutes_.end())
+        notifyRoutes_.erase(i);
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::ppi::connector::InputConnector
 
@@ -304,7 +323,7 @@ prefix_ void senf::ppi::connector::GenericActiveInput::v_requestEvent()
 // senf::ppi::connector::GenericPassiveInput
 
 ////////////////////////////////////////
-// private members 
+// private members
 
 prefix_ void senf::ppi::connector::GenericPassiveInput::v_enqueueEvent()
 {