Ignore:
Timestamp:
Apr 18, 2011, 2:32:50 PM (10 years ago)
Author:
tbretz
Message:
Moved the handling of the server and service lists to DimNetwork; simplified the remaining code accordingly; adapted to the use of DimServiceInfoList instead of ServiceList.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/RemoteControl.cc

    r10341 r10390  
    11#include "RemoteControl.h"
    22
    3 StateClient::StateClient(const std::string &name, MessageImp &imp) :
    4     MessageDimRX(name, imp), fState(-2),
    5     fInfoState((name + "/STATE").c_str(), const_cast<char*>(""), this)
    6 {
    7 }
    8 
    9 void StateClient::infoHandler()
    10 {
    11     DimInfo *curr = getInfo(); // get current DimInfo address
    12     if (!curr)
    13         return;
    14 
    15     if (curr==&fInfoState)
    16     {
    17         const char *txt = fInfoState.getString();
    18 
    19         fState     = strlen(txt)==0 ? -2 : fInfoState.getQuality();
    20         fStateTime = Time(fInfoState.getTimestamp(),
    21                           fInfoState.getTimestampMillisecs());
    22         fStateMsg  = txt;
    23 
    24         if (fState!=-2)
    25         {
    26             stringstream msg;
    27             msg << fInfoState.getName() << ": Changed state to " << fState << " '" << txt << "' received.";
    28             fMsg.Write(fStateTime, msg.str().c_str(), MessageImp::kInfo);
    29         }
    30         return;
    31     }
    32 
    33     MessageDimRX::infoHandler();
    34 }
    35 
    363// ==========================================================================
    37 
    38 void RemoteControlImp::infoHandler()
    39 {
    40     const vector<string> list = fServiceList.GetServerList();
    41 
    42     // Remover StateClients which are not available anymore
    43     for (ClientList::iterator l=fClientList.begin(); l!=fClientList.end(); l++)
    44     {
    45         const string &server = l->first;
    46 
    47         // HasServer doesn't work here, I don't understand why.
    48         if (find(list.begin(), list.end(), server)!=list.end())
    49             continue;
    50 
    51         delete l->second;
    52         fClientList.erase(l);
    53     }
    54 
    55 
    56     // Add StateClients which are new
    57     for (vector<string>::const_iterator l=list.begin(); l!=list.end(); l++)
    58     {
    59         if (*l=="DIS_DNS")
    60             continue;
    61 
    62         const ClientList::const_iterator p = fClientList.find(*l);
    63         if (p!=fClientList.end())
    64             continue;
    65 
    66         fClientList[*l] = new StateClient(*l, *this);
    67     }
    68 }
    694
    705bool RemoteControlImp::ProcessCommand(const std::string &str)
     
    8217        {
    8318            const string c = str.substr(p2+1);
    84             return !fCommandList.SendDimCommand(lout, s, c);
     19            return !SendDimCommand(lout, s, c);
    8520        }
    8621
    87         if(fServiceList.HasServer(s))
     22        if (HasServer(s))
    8823        {
    8924            fCurrentServer = s;
     
    10035    }
    10136
    102     return !fCommandList.SendDimCommand(lout, fCurrentServer, str);
     37    return !SendDimCommand(lout, fCurrentServer, str);
    10338}
    10439
    10540// ==========================================================================
    106 #include <boost/regex.hpp>
    10741
    10842#include "tools.h"
     
    12357        return beg + "> ";//Form("\n[%d] \033[34m\033[1m%s\033[0m> ", GetLine(), fCurrentServer.c_str());
    12458
    125     // The server is valid, check for the state from the last status message
    126     const string msg = l->second->GetMsg();
    127 
    128     static const boost::regex expr("(.+)\\[[0-9]+\\].*");
     59    const State state = GetState(fCurrentServer, l->second->GetState());
    12960
    13061    // The server
    13162    const string serv = Form("\033[34m\033[1m%s\033[0m", fCurrentServer.c_str());
    13263
    133     boost::smatch what;
    134     const int rc = boost::regex_match(msg, what, expr, boost::match_extra);
    135 
    13664    // If no match found or something wrong found just output the server
    137     if (!rc || what.size()!=2)
    138         return beg + " " + serv + "> ";//Form("[%d-%s] ", GetLine(), msg.c_str());
     65    if (state.index<-1)
     66        return beg + " " + serv + "> ";
    13967
    14068    // If everything found add the state to the server
    141     const string state = what[1];
    142     return beg + " " + serv + Form(":\033[32m\033[1m%s\033[0m> ", state.c_str());
     69    return beg + " " + serv + ":\033[32m\033[1m" + state.name + "\033[0m> ";
    14370}
    14471
     
    15885        return beg + "> ";//Form("\n[%d] \033[34m\033[1m%s\033[0m> ", GetLine(), fCurrentServer.c_str());
    15986
    160     // The server is valid, check for the state from the last status message
    161     const string msg = l->second->GetMsg();
    162 
    163     static const boost::regex expr("(.+)\\[[0-9]+\\].*");
    164 
    165     boost::smatch what;
    166     const int rc = boost::regex_match(msg, what, expr, boost::match_extra);
     87    const State state = GetState(fCurrentServer, l->second->GetState());
    16788
    16889    // If no match found or something wrong found just output the server
    169     if (!rc || what.size()!=2)
    170         return beg + " " + fCurrentServer + "> ";//Form("[%d-%s] ", GetLine(), msg.c_str());
     90    if (state.index<-1)
     91        return beg + " " + fCurrentServer + "> ";
    17192
    17293    // If everything found add the state to the server
    173     const string state = what[1];
    174     return beg + " " + fCurrentServer + ":" + state + "> ";
     94    return beg + " " + fCurrentServer + ":" + state.name + "> ";
    17595}
Note: See TracChangeset for help on using the changeset viewer.