Ignore:
Timestamp:
Apr 18, 2011, 2:32:50 PM (9 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.h

    r10341 r10390  
    11#ifndef FACT_RemoteControl
    22#define FACT_RemoteControl
    3 
    4 // **************************************************************************
    5 /** @class StateClient
    6 
    7 @brief A simple Dim client diriving from MessageDimRX subscribing to the STATE service
    8 
    9 This is a simple dim client which subscribes to the MESSAGE and STATE
    10 service of a server. It stores the last state and its time as well as
    11 the last message sent.
    12 
    13 **/
    14 // **************************************************************************
    15 #include "MessageDim.h"
    16 #include "Time.h"
    17 
    18 class StateClient : public MessageDimRX
    19 {
    20 private:
    21     Time fStateTime;           /// Combine into one MTime (together with value)
    22     int  fState;               /// -2 not initialized, -1 not connected, 0>= state of client
    23 
    24     std::string fStateMsg;     /// The message received with the last state change
    25 
    26     DimStampedInfo fInfoState; /// The dim service subscription
    27 
    28 protected:
    29     void infoHandler();
    30 
    31 public:
    32     StateClient(const std::string &name, MessageImp &imp);
    33 
    34     bool        IsConnected() const { return fState>=0; }
    35     int         GetState() const    { return fState;    }
    36     std::string GetMsg() const      { return fStateMsg; }
    37 };
    383
    394// **************************************************************************
     
    5116**/
    5217// **************************************************************************
    53 #include "ServiceList.h"
    54 #include "DimErrorRedirecter.h"
    55 
    56 using namespace std;
    57 
    58 class RemoteControlImp : public MessageImp, public DimErrorRedirecter, public DimInfoHandler
    59 {
    60 private:
     18#include "DimNetwork.h"
     19
     20class RemoteControlImp : public DimNetwork
     21{
     22protected:
    6123    std::ostream &lout;          /// Output stream for local synchrounous output
    6224
    63 protected:
    64     typedef std::map<const std::string, StateClient*> ClientList;
    65 
    66     ServiceList fCommandList;    /// An up-to-date list of all available commands
    67     ServiceList fServiceList;    /// An up-to-date list of all available services
    68     ClientList  fClientList;     /// A list with all MESSAGE services to which we subscribed
    69 
    7025    std::string fCurrentServer;  /// The server to which we currently cd'ed
    71 
    72     void infoHandler();
    7326
    7427protected:
    7528    // Redirect asynchronous output to the output window
    7629    RemoteControlImp(std::ostream &out, std::ostream &in) :
    77         MessageImp(out),
    78         DimErrorRedirecter(static_cast<MessageImp&>(*this)),
    79         lout(in), fCommandList("CMD", out), fServiceList("", out)
    80     {
    81         fCommandList.SetHandler(this);
    82         fServiceList.SetHandler(this);
     30        DimNetwork(out), lout(in)
     31    {
    8332    }
    8433    bool ProcessCommand(const std::string &str);
    8534};
     35
     36
    8637
    8738// **************************************************************************
     
    11061{
    11162private:
    112     std::ostream &lout; /// Output stream for local synchrounous output
    113 
    11463    static void append(std::string &str)
    11564    {
     
    13483
    13584                if (p1==string::npos && p2!=string::npos)
    136                     return T::Complete(fCommandList.GetServiceList(), text);
    137 
    138                 std::vector<std::string> v = fCommandList.GetServerList();
     85                    return T::Complete(GetCommandList(), text);
     86
     87                std::vector<std::string> v = GetServerList();
    13988                for_each(v.begin(), v.end(), RemoteControl::append);
    14089                return T::Complete(v, text);
    14190            }
    14291            else
    143                 return T::Complete(fCommandList.GetServiceList(fCurrentServer), text);
    144         }
    145         return T::Complete(fCommandList.GetServiceList(l), text);
     92                return T::Complete(GetCommandList(fCurrentServer), text);
     93        }
     94        return T::Complete(GetCommandList(l), text);
    14695    }
    14796
     
    14998    {
    15099        RemoteControlImp::infoHandler();
    151         if (!fCurrentServer.empty() && !fCommandList.HasServer(fCurrentServer))
     100        if (!fCurrentServer.empty() && !HasServer(fCurrentServer))
    152101        {
    153102            fCurrentServer = "";
     
    159108    // Redirect asynchronous output to the output window
    160109    RemoteControl(const char *name) : T(name),
    161         RemoteControlImp(T::GetStreamOut(), T::GetStreamIn()),
    162         lout(T::GetStreamIn())
    163     {
    164     }
    165 
     110        RemoteControlImp(T::GetStreamOut(), T::GetStreamIn())
     111    {
     112    }
    166113
    167114    bool PrintGeneralHelp()
     
    170117        lout << " " << kUnderline << "Specific commands:" << endl;
    171118        lout << kBold << "   h,help <arg> " << kReset << "List help text for given server or command." << endl;
    172         lout << kBold << "   s,servers    " << kReset << "List all servers which are connected." << endl;
     119//        lout << kBold << "   s,servers    " << kReset << "List all servers which are connected." << endl;
    173120        lout << kBold << "   svc,services " << kReset << "List all services in the network." << endl;
     121        lout << kBold << "   st,states    " << kReset << "List all states in the network." << endl;
    174122        lout << endl;
    175123        return true;
     
    179127    {
    180128        lout << endl << kBold << "List of commands:" << endl;
    181         fCommandList.PrintDescription(lout);
     129        PrintDescription(lout, true);
    182130        return true;
    183131    }
     
    198146            if (!fCurrentServer.empty())
    199147            {
    200                 if (fCommandList.PrintDescription(lout, fCurrentServer, svc)==0)
     148                if (PrintDescription(lout, true, fCurrentServer, svc)==0)
    201149                    lout << "   " << svc << ": <not found>" << endl;
    202150            }
    203151            else
    204152            {
    205                 if (fCommandList.PrintDescription(lout, s, c)==0)
     153                if (PrintDescription(lout, true, s, c)==0)
    206154                    lout << "   <no matches found>" <<endl;
    207155            }
     
    216164            return true;
    217165
    218         if (str=="servers" || str=="s")
    219         {
    220             fCommandList.PrintServerList(lout);
    221             return true;
    222         }
    223 
    224166        if (str=="services" || str=="svc")
    225167        {
    226             fServiceList.PrintDescription(lout);
     168            PrintDescription(lout, false);
     169            return true;
     170        }
     171
     172        if (str=="states" || str=="st")
     173        {
     174            PrintStates(lout);
    227175            return true;
    228176        }
Note: See TracChangeset for help on using the changeset viewer.