Simplified XF 1.1.0

behavior.h
1#ifndef XF_BEHAVIOR_H
2#define XF_BEHAVIOR_H
3
4#include "xf/interface/behavior.h"
5#include "xf/interface/dispatcher.h"
6#include "xf/eventstatus.h"
7#include "xf/initialevent.h"
8#include "xf/defaulttransition.h"
9#include "xf/timeout.h"
10
11 class XFTimeout;
12
28 class XFBehavior : public interface::XFBehavior
29{
30 public:
31 #define GEN(event) pushEvent(new event)
32
36 explicit XFBehavior();
37 ~XFBehavior() override;
38
39 void startBehavior() override;
40
41 void pushEvent(XFEvent * pEvent) override;
42
43 bool deleteOnTerminate() const override;
44 void setDeleteOnTerminate(bool deleteBehaviour) override;
45
46 protected:
52 virtual XFEventStatus processEvent() = 0;
53
54 const XFEvent * getCurrentEvent() const;
55 interface::XFDispatcher * getDispatcher();
56
57
62 const XFTimeout * getCurrentTimeout();
63
64 inline void scheduleTimeout(int timeoutId, int interval) { getDispatcher()->scheduleTimeout(timeoutId, interval, this); }
65 inline void unscheduleTimeout(int timeoutId) { getDispatcher()->unscheduleTimeout(timeoutId, this); }
66
67 private:
68 void setCurrentEvent(const XFEvent * pEvent);
69
83 TerminateBehavior process(const XFEvent * pEvent) override;
84
85 protected:
86 bool deleteOnTerminate_;
87 const XFEvent * pCurrentEvent_;
88};
89 // end of xf_core group
91#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.