Changeset 10269


Ignore:
Timestamp:
Mar 30, 2011, 3:40:20 PM (10 years ago)
Author:
tbretz
Message:
 
File:
1 edited

Legend:

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

    r10230 r10269  
    3535
    3636public:
    37     void ConnectImp(const bs::error_code& error,
    38                     tcp::resolver::iterator endpoint_iterator)
    39     {
    40         Connection::ConnectImp(error, endpoint_iterator);
    41         if (IsConnected())
    42             StartAsyncRead();
     37    void ConnectionEstablished()
     38    {
     39        StartAsyncRead();
    4340    }
    4441
     
    7875    }
    7976
    80     void HandleReceivedData(const bs::error_code& error, size_t bytes_received)
     77    void HandleReceivedData(const bs::error_code& error, size_t bytes_received, int type)
    8178    {
    8279        // Do not schedule a new read if the connection failed.
     
    185182        kSM_Stopping,
    186183        kSM_Reconnect,
     184        kSM_SetUrl,
    187185    };
    188186
     
    211209        c9(*this, *this), fTimers(out)
    212210    {
    213         c1.SetEndpoint("localhost", 5000);
     211//        c1.SetEndpoint();
    214212        c2.SetEndpoint("localhost", 4001);
    215213        c3.SetEndpoint("ftmboard1.ethz.ch", 5000);
     
    231229        c9.SetLogStream(this);
    232230
    233         c1.AsyncConnect(); // This sets the connection to "open"
    234         c2.AsyncConnect(); // This sets the connection to "open"
    235         c3.AsyncConnect(); // This sets the connection to "open"
    236         //c4.AsyncConnect(); // This sets the connection to "open"
    237         //c5.AsyncConnect(); // This sets the connection to "open"
    238         //c6.AsyncConnect(); // This sets the connection to "open"
    239         //c7.AsyncConnect(); // This sets the connection to "open"
    240         //c8.AsyncConnect(); // This sets the connection to "open"
    241         //c9.AsyncConnect(); // This sets the connection to "open"
     231        c1.StartConnect(); // This sets the connection to "open"
     232        c2.StartConnect(); // This sets the connection to "open"
     233        c3.StartConnect(); // This sets the connection to "open"
     234        //c4.StartConnect(); // This sets the connection to "open"
     235        //c5.StartConnect(); // This sets the connection to "open"
     236        //c6.StartConnect(); // This sets the connection to "open"
     237        //c7.StartConnect(); // This sets the connection to "open"
     238        //c8.StartConnect(); // This sets the connection to "open"
     239        //c9.StartConnect(); // This sets the connection to "open"
    242240
    243241        AddStateName(kSM_Disconnected,  "Disconnected");
     
    256254        AddConfiguration("LED",  kSM_Connected);
    257255
    258         T::AddConfiguration("MYT",  "I:1;C:5;I");
    259         T::AddConfiguration("TESTI",            "I");
    260         T::AddConfiguration("TESTI:5",          "I:5");
    261         T::AddConfiguration("TESTI:5;F:1;D:2",  "I:5;F:1;D:2");
    262         T::AddConfiguration("TESTC",            "C");
    263         T::AddConfiguration("TESTI:5;C",        "I:5;C");
     256        T::AddConfiguration("TESTI",    "I");
     257        T::AddConfiguration("TESTI2",   "I:2");
     258        T::AddConfiguration("TESTIF",   "I:2;F:2");
     259        T::AddConfiguration("TESTIC",   "I:2;C");
     260
     261        T::AddConfiguration("CMD", "C")
     262            ->AssignFunction(boost::bind(&StateMachineFAD::Command, this, _1));
    264263
    265264        AddTransition(kSM_Reconnect, "RECONNECT");
    266265
     266        AddTransition(kSM_SetUrl, "SETURL", "C");
     267
    267268        T::PrintListOfEvents();
    268269    }
    269270
     271    int Command(const EventImp &evt)
     272    {
     273        string cmd = evt.GetText();
     274
     275        size_t p0 = cmd.find_first_of(' ');
     276        if (p0==string::npos)
     277            p0 = cmd.length();
     278
     279    T::Out() << "\nCommand: '" << cmd.substr(0, p0) << "'" << cmd.substr(p0)<< "'" << endl;
     280    /*
     281    const Converter c(T::Out(), "B:5;I:2;F;W;O;C", "yes no false 0 1 31 42 11.12 \"test hallo\" ");
     282
     283     T::Out() << c.GetRc() << endl;
     284     T::Out() << c.N() << endl;
     285     T::Out() << c.Get<bool>(0) << endl;
     286     T::Out() << c.Get<bool>(1) << endl;
     287     T::Out() << c.Get<bool>(2) << endl;
     288     T::Out() << c.Get<bool>(3) << endl;
     289     T::Out() << c.Get<bool>(4) << endl;
     290     T::Out() << c.Get<int>(5) << endl;
     291     T::Out() << c.Get<int>(6) << endl;
     292     T::Out() << c.Get<float>(7) << endl;
     293     T::Out() << c.Get<int>(7) << endl;
     294     T::Out() << c.Get<string>(8) << endl;
     295     T::Out() << c.Get<string>(9) << endl;
     296     T::Out() << c.Get<string>(10) << endl;
     297     */
     298     return T::GetCurrentState();
     299    }
    270300    int Start(const EventImp &evt, int i)
    271301    {
     
    336366        switch (evt.GetTargetState())
    337367        {
     368        case kSM_SetUrl:
     369            T::Out() << evt.GetText() << endl;
     370            c1.SetEndpoint(evt.GetText());
     371            return T::GetCurrentState();
    338372        case kSM_Reconnect:
    339373            // Close all connections
Note: See TracChangeset for help on using the changeset viewer.