Index: trunk/FACT++/src/RemoteControl.cc
===================================================================
--- trunk/FACT++/src/RemoteControl.cc	(revision 10389)
+++ trunk/FACT++/src/RemoteControl.cc	(revision 10390)
@@ -1,70 +1,5 @@
 #include "RemoteControl.h"
 
-StateClient::StateClient(const std::string &name, MessageImp &imp) :
-    MessageDimRX(name, imp), fState(-2),
-    fInfoState((name + "/STATE").c_str(), const_cast<char*>(""), this)
-{
-}
-
-void StateClient::infoHandler()
-{
-    DimInfo *curr = getInfo(); // get current DimInfo address
-    if (!curr)
-        return;
-
-    if (curr==&fInfoState)
-    {
-        const char *txt = fInfoState.getString();
-
-        fState     = strlen(txt)==0 ? -2 : fInfoState.getQuality();
-        fStateTime = Time(fInfoState.getTimestamp(),
-                          fInfoState.getTimestampMillisecs());
-        fStateMsg  = txt;
-
-        if (fState!=-2)
-        {
-            stringstream msg;
-            msg << fInfoState.getName() << ": Changed state to " << fState << " '" << txt << "' received.";
-            fMsg.Write(fStateTime, msg.str().c_str(), MessageImp::kInfo);
-        }
-        return;
-    }
-
-    MessageDimRX::infoHandler();
-}
-
 // ==========================================================================
-
-void RemoteControlImp::infoHandler()
-{
-    const vector<string> list = fServiceList.GetServerList();
-
-    // Remover StateClients which are not available anymore
-    for (ClientList::iterator l=fClientList.begin(); l!=fClientList.end(); l++)
-    {
-        const string &server = l->first;
-
-        // HasServer doesn't work here, I don't understand why.
-        if (find(list.begin(), list.end(), server)!=list.end())
-            continue;
-
-        delete l->second;
-        fClientList.erase(l);
-    }
-
-
-    // Add StateClients which are new
-    for (vector<string>::const_iterator l=list.begin(); l!=list.end(); l++)
-    {
-        if (*l=="DIS_DNS")
-            continue;
-
-        const ClientList::const_iterator p = fClientList.find(*l);
-        if (p!=fClientList.end())
-            continue;
-
-        fClientList[*l] = new StateClient(*l, *this);
-    }
-}
 
 bool RemoteControlImp::ProcessCommand(const std::string &str)
@@ -82,8 +17,8 @@
         {
             const string c = str.substr(p2+1);
-            return !fCommandList.SendDimCommand(lout, s, c);
+            return !SendDimCommand(lout, s, c);
         }
 
-        if(fServiceList.HasServer(s))
+        if (HasServer(s))
         {
             fCurrentServer = s;
@@ -100,9 +35,8 @@
     }
 
-    return !fCommandList.SendDimCommand(lout, fCurrentServer, str);
+    return !SendDimCommand(lout, fCurrentServer, str);
 }
 
 // ==========================================================================
-#include <boost/regex.hpp>
 
 #include "tools.h"
@@ -123,22 +57,15 @@
         return beg + "> ";//Form("\n[%d] \033[34m\033[1m%s\033[0m> ", GetLine(), fCurrentServer.c_str());
 
-    // The server is valid, check for the state from the last status message
-    const string msg = l->second->GetMsg();
-
-    static const boost::regex expr("(.+)\\[[0-9]+\\].*");
+    const State state = GetState(fCurrentServer, l->second->GetState());
 
     // The server
     const string serv = Form("\033[34m\033[1m%s\033[0m", fCurrentServer.c_str());
 
-    boost::smatch what;
-    const int rc = boost::regex_match(msg, what, expr, boost::match_extra);
-
     // If no match found or something wrong found just output the server
-    if (!rc || what.size()!=2)
-        return beg + " " + serv + "> ";//Form("[%d-%s] ", GetLine(), msg.c_str());
+    if (state.index<-1)
+        return beg + " " + serv + "> ";
 
     // If everything found add the state to the server
-    const string state = what[1];
-    return beg + " " + serv + Form(":\033[32m\033[1m%s\033[0m> ", state.c_str());
+    return beg + " " + serv + ":\033[32m\033[1m" + state.name + "\033[0m> ";
 }
 
@@ -158,18 +85,11 @@
         return beg + "> ";//Form("\n[%d] \033[34m\033[1m%s\033[0m> ", GetLine(), fCurrentServer.c_str());
 
-    // The server is valid, check for the state from the last status message
-    const string msg = l->second->GetMsg();
-
-    static const boost::regex expr("(.+)\\[[0-9]+\\].*");
-
-    boost::smatch what;
-    const int rc = boost::regex_match(msg, what, expr, boost::match_extra);
+    const State state = GetState(fCurrentServer, l->second->GetState());
 
     // If no match found or something wrong found just output the server
-    if (!rc || what.size()!=2)
-        return beg + " " + fCurrentServer + "> ";//Form("[%d-%s] ", GetLine(), msg.c_str());
+    if (state.index<-1)
+        return beg + " " + fCurrentServer + "> ";
 
     // If everything found add the state to the server
-    const string state = what[1];
-    return beg + " " + fCurrentServer + ":" + state + "> ";
+    return beg + " " + fCurrentServer + ":" + state.name + "> ";
 }
Index: trunk/FACT++/src/RemoteControl.h
===================================================================
--- trunk/FACT++/src/RemoteControl.h	(revision 10389)
+++ trunk/FACT++/src/RemoteControl.h	(revision 10390)
@@ -1,39 +1,4 @@
 #ifndef FACT_RemoteControl
 #define FACT_RemoteControl
-
-// **************************************************************************
-/** @class StateClient
-
-@brief A simple Dim client diriving from MessageDimRX subscribing to the STATE service
-
-This is a simple dim client which subscribes to the MESSAGE and STATE
-service of a server. It stores the last state and its time as well as
-the last message sent.
-
-**/
-// **************************************************************************
-#include "MessageDim.h"
-#include "Time.h"
-
-class StateClient : public MessageDimRX
-{
-private:
-    Time fStateTime;           /// Combine into one MTime (together with value)
-    int  fState;               /// -2 not initialized, -1 not connected, 0>= state of client
-
-    std::string fStateMsg;     /// The message received with the last state change
-
-    DimStampedInfo fInfoState; /// The dim service subscription
-
-protected:
-    void infoHandler();
-
-public:
-    StateClient(const std::string &name, MessageImp &imp);
-
-    bool        IsConnected() const { return fState>=0; }
-    int         GetState() const    { return fState;    }
-    std::string GetMsg() const      { return fStateMsg; }
-};
 
 // **************************************************************************
@@ -51,37 +16,23 @@
 **/
 // **************************************************************************
-#include "ServiceList.h"
-#include "DimErrorRedirecter.h"
-
-using namespace std;
-
-class RemoteControlImp : public MessageImp, public DimErrorRedirecter, public DimInfoHandler
-{
-private:
+#include "DimNetwork.h"
+
+class RemoteControlImp : public DimNetwork
+{
+protected:
     std::ostream &lout;          /// Output stream for local synchrounous output
 
-protected:
-    typedef std::map<const std::string, StateClient*> ClientList;
-
-    ServiceList fCommandList;    /// An up-to-date list of all available commands
-    ServiceList fServiceList;    /// An up-to-date list of all available services
-    ClientList  fClientList;     /// A list with all MESSAGE services to which we subscribed
-
     std::string fCurrentServer;  /// The server to which we currently cd'ed
-
-    void infoHandler();
 
 protected:
     // Redirect asynchronous output to the output window
     RemoteControlImp(std::ostream &out, std::ostream &in) :
-        MessageImp(out),
-        DimErrorRedirecter(static_cast<MessageImp&>(*this)),
-        lout(in), fCommandList("CMD", out), fServiceList("", out)
-    {
-        fCommandList.SetHandler(this);
-        fServiceList.SetHandler(this);
+        DimNetwork(out), lout(in)
+    {
     }
     bool ProcessCommand(const std::string &str);
 };
+
+
 
 // **************************************************************************
@@ -110,6 +61,4 @@
 {
 private:
-    std::ostream &lout; /// Output stream for local synchrounous output
-
     static void append(std::string &str)
     {
@@ -134,14 +83,14 @@
 
                 if (p1==string::npos && p2!=string::npos)
-                    return T::Complete(fCommandList.GetServiceList(), text);
-
-                std::vector<std::string> v = fCommandList.GetServerList();
+                    return T::Complete(GetCommandList(), text);
+
+                std::vector<std::string> v = GetServerList();
                 for_each(v.begin(), v.end(), RemoteControl::append);
                 return T::Complete(v, text);
             }
             else
-                return T::Complete(fCommandList.GetServiceList(fCurrentServer), text);
-        }
-        return T::Complete(fCommandList.GetServiceList(l), text);
+                return T::Complete(GetCommandList(fCurrentServer), text);
+        }
+        return T::Complete(GetCommandList(l), text);
     }
 
@@ -149,5 +98,5 @@
     {
         RemoteControlImp::infoHandler();
-        if (!fCurrentServer.empty() && !fCommandList.HasServer(fCurrentServer))
+        if (!fCurrentServer.empty() && !HasServer(fCurrentServer))
         {
             fCurrentServer = "";
@@ -159,9 +108,7 @@
     // Redirect asynchronous output to the output window
     RemoteControl(const char *name) : T(name),
-        RemoteControlImp(T::GetStreamOut(), T::GetStreamIn()),
-        lout(T::GetStreamIn())
-    {
-    }
-
+        RemoteControlImp(T::GetStreamOut(), T::GetStreamIn())
+    {
+    }
 
     bool PrintGeneralHelp()
@@ -170,6 +117,7 @@
         lout << " " << kUnderline << "Specific commands:" << endl;
         lout << kBold << "   h,help <arg> " << kReset << "List help text for given server or command." << endl;
-        lout << kBold << "   s,servers    " << kReset << "List all servers which are connected." << endl;
+//        lout << kBold << "   s,servers    " << kReset << "List all servers which are connected." << endl;
         lout << kBold << "   svc,services " << kReset << "List all services in the network." << endl;
+        lout << kBold << "   st,states    " << kReset << "List all states in the network." << endl;
         lout << endl;
         return true;
@@ -179,5 +127,5 @@
     {
         lout << endl << kBold << "List of commands:" << endl;
-        fCommandList.PrintDescription(lout);
+        PrintDescription(lout, true);
         return true;
     }
@@ -198,10 +146,10 @@
             if (!fCurrentServer.empty())
             {
-                if (fCommandList.PrintDescription(lout, fCurrentServer, svc)==0)
+                if (PrintDescription(lout, true, fCurrentServer, svc)==0)
                     lout << "   " << svc << ": <not found>" << endl;
             }
             else
             {
-                if (fCommandList.PrintDescription(lout, s, c)==0)
+                if (PrintDescription(lout, true, s, c)==0)
                     lout << "   <no matches found>" <<endl;
             }
@@ -216,13 +164,13 @@
             return true;
 
-        if (str=="servers" || str=="s")
-        {
-            fCommandList.PrintServerList(lout);
-            return true;
-        }
-
         if (str=="services" || str=="svc")
         {
-            fServiceList.PrintDescription(lout);
+            PrintDescription(lout, false);
+            return true;
+        }
+
+        if (str=="states" || str=="st")
+        {
+            PrintStates(lout);
             return true;
         }
