Changeset 14551


Ignore:
Timestamp:
11/03/12 18:52:18 (12 years ago)
Author:
tbretz
Message:
Fixed a severe bug which caused some events tobe added twice and implemented a callback for state changes
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r14541 r14551  
    297297    fMutex.unlock();
    298298
     299    fStateCallback(server, state);
     300
    299301    return GetCurrentState();
    300302}
     
    342344    if (server!="DIS_DNS")
    343345    {
    344         DimDescriptions *d = new DimDescriptions(server);
    345 
    346         fDimDescriptionsList.push_back(d);
    347         d->SetCallback(bind(&StateMachineDimControl::HandleStateChange, this, server, d));
    348         d->SetCallbackStates(bind(&StateMachineDimControl::HandleStates, this, server, d));
    349         d->SetCallbackDescriptions(bind(&StateMachineDimControl::HandleDescriptions, this, d));
    350         d->Subscribe(*this);
     346        struct Find : string
     347        {
     348            Find(const string &ref) : string(ref) { }
     349            bool operator()(const DimDescriptions *dim) { return *this==dim->server; }
     350        };
     351
     352        if (find_if(fDimDescriptionsList.begin(), fDimDescriptionsList.end(),
     353                    Find(server))==fDimDescriptionsList.end())
     354        {
     355            DimDescriptions *d = new DimDescriptions(server);
     356
     357            fDimDescriptionsList.push_back(d);
     358            d->SetCallback(bind(&StateMachineDimControl::HandleStateChange, this, server, d));
     359            d->SetCallbackStates(bind(&StateMachineDimControl::HandleStates, this, server, d));
     360            d->SetCallbackDescriptions(bind(&StateMachineDimControl::HandleDescriptions, this, d));
     361            d->Subscribe(*this);
     362        }
    351363    }
    352364
  • trunk/FACT++/src/StateMachineDimControl.h

    r14541 r14551  
    2121    std::map<std::pair<std::string, int32_t>, std::pair<std::string, std::string>> fStateDescriptionList;
    2222    std::map<std::string, std::vector<Description>> fServiceDescriptionList;
     23
     24    std::function<void(const std::string &, const State&)> fStateCallback;
    2325
    2426    DimVersion fDim;
     
    6365    void SendDimCommand(const std::string &server, std::string str, std::ostream &lout);
    6466
     67    void SetStateCallback(const std::function<void(const std::string &, const State &)> &func) { fStateCallback = func; }
     68
    6569public:
    6670    StateMachineDimControl(std::ostream &out=std::cout);
Note: See TracChangeset for help on using the changeset viewer.