Changeset 14351 for trunk/FACT++


Ignore:
Timestamp:
08/13/12 09:49:32 (12 years ago)
Author:
tbretz
Message:
The state from the callback was not yet properly propagated. Implemented kSM_KeepState to signal that the state should not change.
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/DimState.h

    r14123 r14351  
    2222
    2323protected:
    24     typedef std::function<void(const EventImp &)> callback;
     24    typedef std::function<int(const EventImp &)> callback;
    2525
    2626    callback fCallback;
     
    3636    }
    3737
    38     void Callback(const EventImp &evt)
    39     {
    40         if (fCallback)
    41             fCallback(evt);
    42     }
    43 
    44     virtual void Handler(const EventImp &evt)
     38    int Callback(const EventImp &evt)
     39    {
     40        return fCallback ? fCallback(evt) : StateMachineImp::kSM_KeepState;
     41    }
     42
     43    virtual int Handler(const EventImp &evt)
    4544    {
    4645        HandlerImp(evt);
    47         Callback(evt);
     46        return Callback(evt);
    4847    }
    4948
     
    145144    }
    146145
    147     void HandleDesc(const EventImp &evt)
     146    int HandleDesc(const EventImp &evt)
    148147    {
    149148        if (evt.GetSize()>0)
     
    154153            CallbackStates();
    155154        }
     155
     156        return StateMachineImp::kSM_KeepState;
    156157    }
    157158
     
    200201
    201202
    202     void HandleServiceDesc(const EventImp &evt)
     203    int HandleServiceDesc(const EventImp &evt)
    203204    {
    204205        descriptions.clear();
     
    212213
    213214        CallbackDescriptions();
     215
     216        return StateMachineImp::kSM_KeepState;
    214217    }
    215218};
     
    217220class DimVersion : public DimState
    218221{
    219     void Handler(const EventImp &evt)
     222    int Handler(const EventImp &evt)
    220223    {
    221224        HandlerImp(evt);
     
    225228            cur.second=kOffline;
    226229
    227         Callback(evt);
     230        return Callback(evt);
    228231    }
    229232
     
    251254    std::map<std::string, callback> fCallbacks;
    252255
    253     void Handler(const EventImp &evt)
     256    int Handler(const EventImp &evt)
    254257    {
    255258        HandlerImp(evt);
     
    262265        const size_t p0 = msg.find_first_of(':');
    263266        if (p0==std::string::npos)
    264             return;
     267            return StateMachineImp::kSM_KeepState;
    265268
    266269        // Evaluate scriptdepth
     
    272275        const size_t p1 = msg.find_last_of('[');
    273276        if (p1==std::string::npos)
    274             return;
     277            return StateMachineImp::kSM_KeepState;
    275278
    276279        const size_t p2 = msg.find_first_of(':', p0+1);
     
    282285        shortmsg.erase(p0, p3-p0);
    283286
    284         Callback(evt);
     287        const int rc = Callback(evt);
    285288
    286289        const auto func = fCallbacks.find(file);
    287290        if (func==fCallbacks.end())
    288             return;
     291            return rc;
    289292
    290293        // Call callback
    291         func->second(evt);
     294        return func->second(evt);
    292295    }
    293296
     
    340343            fCallbackServerEvent(evt);
    341344    }
    342     virtual void HandlerServer(const EventImp &evt)
     345    virtual int HandlerServer(const EventImp &evt)
    343346    {
    344347        HandlerServerImp(evt);
    345348        CallbackServerEvent(evt);
     349
     350        return StateMachineImp::kSM_KeepState;
    346351    }
    347352
     
    424429    }
    425430*/
    426     virtual void HandlerServiceList(const EventImp &evt)
     431    virtual int HandlerServiceList(const EventImp &evt)
    427432    {
    428433        HandlerServiceListImp(evt);
    429434        //CallbackServiceEvent(evt);
     435
     436        return StateMachineImp::kSM_KeepState;
    430437    }
    431438
  • trunk/FACT++/src/RemoteControl.h

    r14135 r14351  
    249249    }
    250250
    251     void Handle(const EventImp &evt, const string &service)
     251    int Handle(const EventImp &evt, const string &service)
    252252    {
    253253        const lock_guard<mutex> lock(fMutex);
     
    261261            it->second.second = static_cast<Event>(evt);
    262262        }
     263
     264        return StateMachineImp::kSM_KeepState;
    263265    }
    264266
  • trunk/FACT++/src/StateMachineImp.h

    r14124 r14351  
    2121    enum DefaultStates_t
    2222    {
     23        kSM_KeepState    =    -42,  ///<
    2324        kSM_NotReady   =     -1,  ///< Mainloop not running, state machine stopped
    2425        kSM_Ready      =      0,  ///< Mainloop running, state machine in operation
     
    6869    virtual void UnLock() { }
    6970
    70     int Wrapper(const std::function<void(const EventImp &)> &f, const EventImp &imp)
     71    int Wrapper(const std::function<int(const EventImp &)> &f, const EventImp &imp)
    7172    {
    72         f(imp);
    73         return GetCurrentState();
     73        const int rc = f(imp);
     74        return rc==kSM_KeepState ? GetCurrentState() : rc;
    7475    }
    7576
     
    9495    ~StateMachineImp();
    9596
    96     std::function<int(const EventImp &)> Wrap(const std::function<void(const EventImp &)> &func)
     97    std::function<int(const EventImp &)> Wrap(const std::function<int(const EventImp &)> &func)
    9798    {
    9899        return bind(&StateMachineImp::Wrapper, this, func, std::placeholders::_1);
Note: See TracChangeset for help on using the changeset viewer.