behavior.h
#ifndef XF_BEHAVIOR_H
#define XF_BEHAVIOR_H
#include "xf/interface/behavior.h"
#include "xf/interface/dispatcher.h"
#include "xf/eventstatus.h"
#include "xf/initialevent.h"
#include "xf/defaulttransition.h"
#include "xf/timeout.h"
class XFTimeout;
class XFBehavior : public interface::XFBehavior
{
public:
#define GEN(event) pushEvent(new event)
explicit XFBehavior();
~XFBehavior() override;
void startBehavior() override;
void pushEvent(XFEvent * pEvent) override;
bool deleteOnTerminate() const override;
void setDeleteOnTerminate(bool deleteBehaviour) override;
protected:
virtual XFEventStatus processEvent() = 0;
const XFEvent * getCurrentEvent() const;
interface::XFDispatcher * getDispatcher();
const XFTimeout * getCurrentTimeout();
inline void scheduleTimeout(int timeoutId, int interval) { getDispatcher()->scheduleTimeout(timeoutId, interval, this); }
inline void unscheduleTimeout(int timeoutId) { getDispatcher()->unscheduleTimeout(timeoutId, this); }
private:
void setCurrentEvent(const XFEvent * pEvent);
TerminateBehavior process(const XFEvent * pEvent) override;
protected:
bool deleteOnTerminate_;
const XFEvent * pCurrentEvent_;
};
// end of xf_core group
#endif // XF_BEHAVIOR_H
XFBehavior
Base class for state machines, activities, process and data flows.
Definition: behavior.h:29
XFBehavior::processEvent
virtual XFEventStatus processEvent()=0
XFBehavior::XFBehavior
XFBehavior()
Default constructor for the behavior.
XFBehavior::deleteOnTerminate
bool deleteOnTerminate() const override
Tells XF to delete behavior when receiving terminate event.
XFBehavior::pCurrentEvent_
const XFEvent * pCurrentEvent_
Reference to actually processed event.
Definition: behavior.h:87
XFBehavior::pushEvent
void pushEvent(XFEvent *pEvent) override
Injects an event into the class.
XFBehavior::unscheduleTimeout
void unscheduleTimeout(int timeoutId)
Unschedules a timeout for this state machine.
Definition: behavior.h:65
XFBehavior::scheduleTimeout
void scheduleTimeout(int timeoutId, int interval)
Schedules a timeout for this state machine.
Definition: behavior.h:64
XFBehavior::startBehavior
void startBehavior() override
Starts the behavior, resp. the state machine.
XFBehavior::getDispatcher
interface::XFDispatcher * getDispatcher()
Returns reference to actual dispatcher.
XFBehavior::deleteOnTerminate_
bool deleteOnTerminate_
Indicates if the behavior can be deleted after reception of a 'terminate event'.
Definition: behavior.h:86
XFBehavior::getCurrentTimeout
const XFTimeout * getCurrentTimeout()
Returns a reference to the actually processed timeout.
XFBehavior::setDeleteOnTerminate
void setDeleteOnTerminate(bool deleteBehaviour) override
Sets/Clears the 'delete on terminate' property.
XFBehavior::getCurrentEvent
const XFEvent * getCurrentEvent() const
Returns the current event to be processed in processEvent().
XFEvent
Base class for all types of events and timeouts.
Definition: event.h:23
XFEventStatus
Event status returned after event processing.
Definition: eventstatus.h:16
XFTimeout
Used by the TimeoutManager to create and handle a timeout.
Definition: timeout.h:28
interface::XFBehavior
Interface to receive and process events.
Definition: behavior.h:24
interface::XFBehavior::TerminateBehavior
bool TerminateBehavior
Type returned by the process() method.
Definition: behavior.h:30
interface::XFDispatcher
Interface for the XF dispatcher providing the event processing loop.
Definition: dispatcher.h:29
interface::XFDispatcher::unscheduleTimeout
virtual void unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior)=0
Removes all timeouts corresponding the given parameters.
interface::XFDispatcher::scheduleTimeout
virtual void scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior)=0
Adds a new timeout to be handled.