Packets: Add StringParser ostream operation
[senf.git] / Scheduler / EventManager.cc
index 0743cb6..d267a1e 100644 (file)
@@ -29,7 +29,7 @@
 // Custom includes
 #include <boost/format.hpp>
 #include "../Utils/membind.hh"
-#include "Console/Console.hh"
+#include "../Utils/Console/Console.hh"
 #include "FIFORunner.hh"
 
 //#include "EventManager.mpp"
 prefix_ senf::scheduler::detail::EventManager::EventManager()
 {
 #ifndef SENF_DISABLE_CONSOLE
-    consoleDir_().add("events", senf::membind(&EventManager::consoleEvents, this));
+    consoleDir_().add("events", senf::membind(&EventManager::listEvents, this))
+        .doc("List all scheduler events sorted by priority\n"
+             "\n"
+             "Columns:\n"
+             "    TP      event type:\n"
+             "              fd  file descriptor\n"
+             "              tm  timer\n"
+             "              si  UNIX signal\n"
+             "              ee  event hook\n"
+             "    NAME    descriptive event name\n"
+             "    ADDRESS address of event class instance\n"
+             "    RUNCNT  number of times, the event was called\n"
+             "    S       state:\n"
+             "              R  runnable\n"
+             "              W  waiting\n"
+             "              -  event disabled\n"
+             "    INFO    further event specific information");
+
     senf::console::sysdir().add("scheduler", consoleDir_());
 #endif
 }
 
-prefix_ void senf::scheduler::detail::EventManager::consoleEvents(std::ostream & os)
+prefix_ void senf::scheduler::detail::EventManager::listEvents(std::ostream & os)
 {
-    iterator i (begin());
-    iterator const i_end (end());
-    // On an 80 column display, this wraps nicely directly before the RUN column
-    os << boost::format("%-6s %-52s %-10s %-8s %7s %s\n")
-        % "TYPE"
-        % "NAME"
-        % "ADDRESS"
-        % "ACTIVE?"
-        % "RUN"
-        % "INFO";
-    for (; i != i_end; ++i)
-        os << boost::format("%-6.6s %-52.52s 0x%08x %-8.8s %7d %s\n")
-            % i->type()
-            % i->name() 
-            % reinterpret_cast<unsigned long>(&(*i))
-            % (i->enabled() ? "enabled" : "disabled")
-            % i->runCount()
-            % i->info();
+    // On an 80 column display, this wraps nicely directly before the INFO column
+    boost::format fmt  ("%s %-55.55s 0x%08x %8d %s %s\n");
+    os << boost::format("%s %-55.55s %-10s %8s %s %s\n")
+        % "TP" % "NAME" % "ADDRESS" % "RUNCNT" % "S" % "INFO";
+    {
+        FIFORunner::iterator i (FIFORunner::instance().begin());
+        FIFORunner::iterator const i_end (FIFORunner::instance().end());
+        for (; i != i_end; ++i)
+            os << fmt 
+                % i->type()
+                % i->name() 
+                % reinterpret_cast<unsigned long>(&(*i))
+                % i->runCount()
+                % (i->runnable() ? "R" : "W")
+                % i->info();
+    }
+    {
+        iterator i (begin());
+        iterator const i_end (end());
+        for (; i != i_end; ++i)
+            if (! i->enabled())
+                os << fmt
+                    % i->type()
+                    % i->name() 
+                    % reinterpret_cast<unsigned long>(&(*i))
+                    % i->runCount()
+                    % "-"
+                    % i->info();
+    }
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////