vrecko
virtual reality framework
|
#include <EventDispatcher.h>
Classes | |
struct | EventDefinitionStruct |
Struct that defines an event. More... | |
struct | EventStruct |
Struct contains received event. More... | |
struct | ICS |
struct | ICSBase |
Struct that holds identification of receiver and interconnection type. More... | |
struct | REQUEST_Struct |
struct | StringWithHash |
struct | StringWithHashComparator |
Public Types | |
enum | InterconnectionType { FORWARD_OUTPUT = 1, ACTIVATE_INPUT, REQUEST } |
Types of an interconnection in the EventDispatcher. More... | |
enum | SRType { UNKNOWN = 0, ENVIRONMENTOBJECT, ABILITY, DEVICE, SCENE, WORLD, OUTER_OBJECT } |
Type of an sender/receiver. More... | |
typedef std::multimap < StringWithHash, ICS *, StringWithHashComparator > | EI_Type |
typedef std::map < StringWithHash, REQUEST_Struct, StringWithHashComparator > | REQUEST_Map |
The type of the request/default_request maps. More... | |
Public Types inherited from vrecko::BaseClass | |
enum | NotificationTypes { NOTIFICATION_DELETE_CLASS = 1, NOTIFICATION_EO_REGISTERING = 2, NOTIFICATION_EO_UNREGISTERING = 4, NOTIFICATION_PROGRAM_TERMINATION = 8, NOTIFICATION_ALL = 0xFFFFFFFF } |
Public Member Functions | |
EventDispatcher () | |
~EventDispatcher () | |
EventDispatcher (EventDispatcher &ed) | |
void | setMainThreadId (pthread_t ptID) |
bool | insertEventInterconnection (const std::string &sender, const std::string &receiver, InterconnectionType type=FORWARD_OUTPUT, const std::string &sceneFile=*((std::string *) NULL)) |
bool | deleteEventInterconnection (const std::string &sender, const std::string &receiver, InterconnectionType type=FORWARD_OUTPUT) |
void | dirtyInterconnectionsForObject (BaseClass *object, bool bProcessEvents=true, bool bProcessRequests=true) |
bool | reportEvent (const std::string &senderAndOutputString, VreckoMessage *pMessage, EventType eType=EXPRESS_EVENT) |
bool | reportEvent (BaseClass *receiver_ptr, const std::string &input_name, VreckoMessage *pMessage, EventType eType=EXPRESS_EVENT) |
osg::ref_ptr< VreckoMessage > | request (const std::string &req_sender, VreckoMessage *pMessage) |
osg::ref_ptr< VreckoMessage > | request (BaseClass *receiver_ptr, const std::string &request_name, VreckoMessage *pMessage) |
void | update (void) |
void | setScenePtr (Scene *ptr) |
bool | addOuterObject (const std::string &object_id, BaseClass *pOObject) |
bool | removeOuterObject (const std::string &object_id) |
bool | removeOuterObject (BaseClass *pOObject) |
EI_Type & | getEventInterconnectionMap () |
REQUEST_Map & | getRequestInterconnectionMap () |
REQUEST_Map & | getDefaultRequestInterconnectionMap () |
std::vector < EventDefinitionStruct > & | getEventsVector (void) |
Return reference to eventsVector. More... | |
void | setNetSupport (bool status) |
bool | parseSR (const std::string &sr, bool isSender, BaseClass **pEntity, SRType *pSRType, std::string *pIOName, osg::ref_ptr< VreckoMessage > *pRefMessage, bool isRequest=false, bool noErrorOuptut=false) |
Core method to parse render (or receiver) string and return all the components independently. More... | |
int | getProcessedEventsCounter () |
void | resetProcessedEventsCounter () |
Public Member Functions inherited from vrecko::BaseClass | |
BaseClass (const char *startingSenderString) | |
The main constructor. More... | |
BaseClass (BaseClass &bc) | |
Copy constructor. Probably not really used. More... | |
virtual | ~BaseClass () |
Destructor. More... | |
virtual bool | initialize (XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters=NULL) |
Core initialization. More... | |
virtual bool | initializeFromString (const char *xmlString) |
Helper method that allows to initialize ability from a XML-formatted string. More... | |
virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * | saveXMLParameters (XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *) |
Save current setting into a XML node. More... | |
bool | inputPresent (const std::string &name) |
Returns true if input pin (not request inputpin ) with given name is present. More... | |
bool | outputPresent (const std::string &name) |
Returns true if output pin (not request output pin) with given name is present. More... | |
void | addInputPin (InputPinBase *pin) |
Adds an input pin. More... | |
void | removeInputPin (InputPinBase *pin) |
Removes an input pin. More... | |
void | addOutputPin (OutputPinBase *pin) |
Adds an output pin. More... | |
void | removeOutputPin (OutputPinBase *pin) |
Removes and output pin. More... | |
void | addRequestInputPin (RequestInputPinBase *pin) |
Adds a request input pin. More... | |
void | removeRequestInputPin (RequestInputPinBase *pin) |
Removes a request input pin. More... | |
void | addRequestOutputPin (RequestOutputPinBase *pin) |
Adds a request output pin. More... | |
void | removeRequestOutputPin (RequestOutputPinBase *pin) |
Removes a request output pin. More... | |
bool | addNotification (BaseClass *receiver, unsigned long notificationTypes) |
Registers an observer that will be notified if a specific change occurs. More... | |
bool | removeNotification (BaseClass *receiver, unsigned long notificationTypes=NOTIFICATION_ALL) |
Unregisters a previously registered observer. More... | |
virtual void | processEvent (const std::string &input_name, VreckoMessage *pMessage) |
Internal method for processing the events. More... | |
virtual VreckoMessage * | processRequest (const std::string &request_input_name, VreckoMessage *pMessage) |
Internal method for processing the requests. More... | |
virtual const std::string & | getSenderString (void) |
Returns the sender (or receiver) identification string. More... | |
void | reportError (const std::string &error) |
Print error message. More... | |
void | setPriority (long int pr) |
Sets the priority. (Possible problems - read the full description for more info) More... | |
long int | getPriority (void) const |
Returns current object priority. More... | |
void | setAttribute (const std::string &attr_name, int attr_value) |
Sets an attribute value. More... | |
int | getAttribute (const std::string &attr_name) |
Returns attribute value. More... | |
int | getAttribute (const char *attr_name) |
Returns attribute value. More... | |
void | deleteAttribute (const std::string &attr_name) |
Delete an attribute. More... | |
void | setSceneFile (const std::string &sceneFileName) |
Set the name of the file this component was in (and possibly will be saved to). More... | |
const std::string & | getSceneFile () const |
Get the name of the file this component was in. More... | |
virtual void | preInitialize (void) |
OBSOLETE METHOD, kept for backwards compatibility. More... | |
virtual void | postInitialize (void) |
OBSOLETE METHOD, kept for backwards compatibility. More... | |
virtual bool | loadXMLParameters (XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *) |
OBSOLETE METHOD, kept for backwards compatibility. More... | |
virtual bool | loadXMLParameters (const char *xmlString) |
OBSOLETE METHOD, kept for backwards compatibility. More... | |
InputPinBase * | getInputPin (const char *strName) |
Returns pointer to an input pin with specified name. More... | |
OutputPinBase * | getOutputPin (const char *strName) |
Returns pointer to an output pin with specified name. More... | |
RequestInputPinBase * | getRequestInputPin (const char *strName) |
Returns pointer to an request input pin with specified name. More... | |
RequestOutputPinBase * | getRequestOutputPin (const char *strName) |
Returns pointer to an input pin with specified name. More... | |
Protected Types | |
typedef std::vector< std::string > | Decomposition_vec |
Protected Types inherited from vrecko::BaseClass | |
typedef std::map< std::string, int > | AttributeMap |
Attributes. More... | |
typedef std::vector < osg::ref_ptr< IOPinBase > > | PinList |
Protected Member Functions | |
bool | isInMainThread () |
void | processBatchOfEvents (std::vector< EventStruct * > *ref_incoming_events, bool bTurnOffForegroundQueing) |
void | processEvent (EventStruct *pES) |
bool | reportEventCore (BaseClass *receiver_ptr, const std::string &sender, VreckoMessage *pMessage, EventType eType) |
void | debugPrintInterconnectionMap (EI_Type *map) |
void | debugPrintRequestMap (REQUEST_Map *map) |
bool | checkInterconnection (const std::string &sender, const std::string &receiver, bool bRequest) |
Checks interconnection for any problems (missing sender/receiver), incorrect output/input types. More... | |
Protected Member Functions inherited from vrecko::BaseClass | |
bool | sendNotifications (unsigned long notificationType, void *notificationData) |
virtual int | processNotification (BaseClass *sender, unsigned long notificationType, void *notificationData) |
Process an incoming notification. More... | |
IOPinBase * | findPinInList (const char *strName, PinList *pinList) |
Internal method to find a given pin in a given list. More... | |
EventDispatcher class is an entity that is used for message/request sending and manages the interconnections.
|
protected |
typedef std::multimap<StringWithHash, ICS *, StringWithHashComparator> vrecko::EventDispatcher::EI_Type |
Type of event_interconnection_map.
TODO OPTIM?: The message sending can probably be sped up without much effort. This is the idea: Multimap is a tree in reality, searching is done in log-time, which is good. The keys are strings and comparing strings is not that fast. We could use some struct { string originalValue; unsigned long calculatedHash; } and create own comparator to compare the hash first and the string second. But we would need to make some tests to see if this brings any performance increase. (There will be drawback that we would need to calculate the hash for every message.)
typedef std::map<StringWithHash, REQUEST_Struct, StringWithHashComparator> vrecko::EventDispatcher::REQUEST_Map |
The type of the request/default_request maps.
Types of an interconnection in the EventDispatcher.
EventDispatcher::EventDispatcher | ( | ) |
EventDispatcher::~EventDispatcher | ( | ) |
EventDispatcher::EventDispatcher | ( | EventDispatcher & | ed | ) |
bool EventDispatcher::addOuterObject | ( | const std::string & | object_id, |
BaseClass * | pOObject | ||
) |
Adds an outer object. Not useful for 99 % of people.
Outer object can receive messages from Vrecko.
|
protected |
Checks interconnection for any problems (missing sender/receiver), incorrect output/input types.
Great for debug, but can be turned off.
|
protected |
Prints out the interconnection map for debug purposes.
|
protected |
Prints out the requests interconnection map for debug purposes.
bool EventDispatcher::deleteEventInterconnection | ( | const std::string & | sender, |
const std::string & | receiver, | ||
InterconnectionType | type = FORWARD_OUTPUT |
||
) |
This function serves to delete an event interconnection from the database. Returns true if no problem occurs.
void EventDispatcher::dirtyInterconnectionsForObject | ( | BaseClass * | object, |
bool | bProcessEvents = true , |
||
bool | bProcessRequests = true |
||
) |
An object/ability/device/... might be deleted or added, so we have to recheck the interconnections whether the pointers to receivers are still valid. This is not done immediately, but on the next usage of the respective interconnection.
|
inline |
|
inline |
|
inline |
Return reference to eventsVector.
|
inline |
Debug method to get number of processed events.
|
inline |
bool EventDispatcher::insertEventInterconnection | ( | const std::string & | sender, |
const std::string & | receiver, | ||
InterconnectionType | type = FORWARD_OUTPUT , |
||
const std::string & | sceneFile = *((std::string*)NULL) |
||
) |
This function serves to insert new event interconnection to the database.
Returns true if no problem occurs. The [sceneFile] is a file that this connection was loaded from and will be saved to. 1) Might be NULL which means the defaultSceneFile will be used (see getSafeDefaultSceneFile() etc.) 2) Might be an empty string meaning "don't save to a file"
|
protected |
returns true if we are currently in the main thread.
bool EventDispatcher::parseSR | ( | const std::string & | sr, |
bool | isSender, | ||
BaseClass ** | pEntity, | ||
SRType * | pSRType, | ||
std::string * | pIOName, | ||
osg::ref_ptr< VreckoMessage > * | pRefMessage, | ||
bool | isRequest = false , |
||
bool | noErrorOuptut = false |
||
) |
Core method to parse render (or receiver) string and return all the components independently.
This method also checks if the specified object and input/output exists and prints out an error message if it doesn't (you can disable this behaviour - see the "noErrorOutput" parameter).
sr | (const std::string &) Complete sender string in the form "Wr#Ab|navigation::KMTracker#Orientation" or "Wr#Ab|navigation::KMTracker#Right|0" |
isSender | (bool) Is it a sender string or a receiver string? (this will be mostly used to check whether the specified output or input exists) |
pEntity | (BaseClass * *) Output variable to hold a pointer to a specified entity. |
pSRType | (SRType *) Output variable to hold SRType |
pIOName | (std::string *) Output variable to hold the input name |
pRefMessage | (osg::ref_ptr<VreckoMessage> *) Output variable to hold a "reference message", this is only created for inputs/outputs with a value specified (the "|0" in the above example) |
isRequest | (bool) Input - is it a request? |
noErrorOuptut | (bool) If "true" then no errors will be printed if a specified object or input/output doesn't exist. |
|
protected |
|
protected |
bool EventDispatcher::removeOuterObject | ( | const std::string & | object_id | ) |
Removes an outer object specified by its ID.
bool EventDispatcher::removeOuterObject | ( | BaseClass * | pOObject | ) |
Removes an outer object specified by the pointer.
|
inline |
(Very low-level, you should use input pins with DECLARE_INPUT etc. macros if possible) Through this function, any object can send an event to EventDispatcher.
Returns true if the event will be processed.
|
inline |
(A bit low-level, you should use input pins with DECLARE_INPUT etc. macros if possible) Through this function, any object can send an event to EventDispatcher. Returns true if the event will be processed.
|
protected |
osg::ref_ptr< VreckoMessage > EventDispatcher::request | ( | const std::string & | req_sender, |
VreckoMessage * | pMessage | ||
) |
(Very low-level, you should use input pins with DECLARE_REQUEST_INPUT etc. macros) Send a request.
osg::ref_ptr< VreckoMessage > EventDispatcher::request | ( | BaseClass * | receiver_ptr, |
const std::string & | request_name, | ||
VreckoMessage * | pMessage | ||
) |
(A bit low-level, you should use input pins with DECLARE_REQUEST_INPUT etc. macros if possible) Send a direct request.
|
inline |
Debug method to reset the number of processed messages.
|
inline |
void EventDispatcher::setNetSupport | ( | bool | status | ) |
OBSOLETE - Network support is not working (was never fully working and with requests it is not probable it will ever be).
|
inline |
Sets the Scene that holds this EventDispatcher.
|
virtual |
|
protected |
|
protected |
|
protected |
|
protected |
Multimap where the interconnection between sender and receiver are stored .
|
protected |
Vector with all defined events.
|
protected |
|
protected |
List of the incoming events.
|
protected |
|
protected |
|
protected |
Net support flag.
|
protected |
Pointer to the Outer receiveEvents function.
|
protected |
Multimap with all last received events.
|
protected |
Decomposition of the receiver string.
|
protected |
|
protected |
Pointer to the Scene that holds this EventDispatcher.
|
protected |
Decomposition of the sender string.