vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrecko::EventDispatcher Class Reference

#include <EventDispatcher.h>

Inheritance diagram for vrecko::EventDispatcher:
vrecko::BaseClass

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< VreckoMessagerequest (const std::string &req_sender, VreckoMessage *pMessage)
 
osg::ref_ptr< VreckoMessagerequest (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_TypegetEventInterconnectionMap ()
 
REQUEST_MapgetRequestInterconnectionMap ()
 
REQUEST_MapgetDefaultRequestInterconnectionMap ()
 
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 VreckoMessageprocessRequest (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...
 
InputPinBasegetInputPin (const char *strName)
 Returns pointer to an input pin with specified name. More...
 
OutputPinBasegetOutputPin (const char *strName)
 Returns pointer to an output pin with specified name. More...
 
RequestInputPinBasegetRequestInputPin (const char *strName)
 Returns pointer to an request input pin with specified name. More...
 
RequestOutputPinBasegetRequestOutputPin (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...
 
IOPinBasefindPinInList (const char *strName, PinList *pinList)
 Internal method to find a given pin in a given list. More...
 

Protected Attributes

std::vector
< EventDefinitionStruct
eventsVector
 Vector with all defined events. More...
 
EI_Type event_interconnection_map
 Multimap where the interconnection between sender and receiver are stored . More...
 
std::vector< EventStruct * > incoming_events [2]
 List of the incoming events. More...
 
int bgListId
 
bool bAllowForegroundListQueing
 
std::map< std::string, void * > received_event_map
 Multimap with all last received events. More...
 
std::map< std::string,
Decomposition_vec
sender_decomposition
 Decomposition of the sender string. More...
 
std::map< std::string,
Decomposition_vec
receiver_decomposition
 Decomposition of the receiver string. More...
 
REQUEST_Map request_interconnection_map
 
REQUEST_Map default_request_interconnection_map
 
Scenescene_ptr
 Pointer to the Scene that holds this EventDispatcher. More...
 
std::map< std::string,
BaseClass * > 
outerObject_map
 Pointer to the Outer receiveEvents function. More...
 
int iProcessedEventsCounter
 
bool net_support
 Net support flag. More...
 
pthread_t hMainThreadId
 
MTLock mainLock
 
- Protected Attributes inherited from vrecko::BaseClass
AttributeMap attribute
 
MTReadWriteLock attributeLock
 
std::string senderString
 
MTLock notificationsLock
 
std::vector
< NOTIFICATION_DESCRIPTION
notifications
 
long int priority
 
const std::string * sceneFile
 
PinList inputPinsList
 
PinList outputPinsList
 
PinList requestInputPinsList
 
PinList requestOutputPinsList
 

Detailed Description

EventDispatcher class is an entity that is used for message/request sending and manages the interconnections.

Member Typedef Documentation

typedef std::vector<std::string> vrecko::EventDispatcher::Decomposition_vec
protected

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.)

The type of the request/default_request maps.

Member Enumeration Documentation

Types of an interconnection in the EventDispatcher.

Enumerator
FORWARD_OUTPUT 

Just forward the message to the other object.

ACTIVATE_INPUT 

If the received message has value X then send the message with value Y to the other object (X and Y might be of a completely differrent types).

REQUEST 

Immediately send a request and receive a return value.

Type of an sender/receiver.

Enumerator
UNKNOWN 
ENVIRONMENTOBJECT 
ABILITY 
DEVICE 
SCENE 
WORLD 
OUTER_OBJECT 

Constructor & Destructor Documentation

EventDispatcher::EventDispatcher ( )
EventDispatcher::~EventDispatcher ( )
EventDispatcher::EventDispatcher ( EventDispatcher ed)

Member Function Documentation

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.

bool EventDispatcher::checkInterconnection ( const std::string &  sender,
const std::string &  receiver,
bool  bRequest 
)
protected

Checks interconnection for any problems (missing sender/receiver), incorrect output/input types.

Great for debug, but can be turned off.

void EventDispatcher::debugPrintInterconnectionMap ( EI_Type map)
protected

Prints out the interconnection map for debug purposes.

void EventDispatcher::debugPrintRequestMap ( REQUEST_Map map)
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.

REQUEST_Map& vrecko::EventDispatcher::getDefaultRequestInterconnectionMap ( )
inline
EI_Type& vrecko::EventDispatcher::getEventInterconnectionMap ( )
inline
std::vector<EventDefinitionStruct>& vrecko::EventDispatcher::getEventsVector ( void  )
inline

Return reference to eventsVector.

int vrecko::EventDispatcher::getProcessedEventsCounter ( )
inline

Debug method to get number of processed events.

REQUEST_Map& vrecko::EventDispatcher::getRequestInterconnectionMap ( )
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"

bool EventDispatcher::isInMainThread ( )
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).

Parameters
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.
Returns
(bool) Returns "true" if there was no error.
void EventDispatcher::processBatchOfEvents ( std::vector< EventStruct * > *  ref_incoming_events,
bool  bTurnOffForegroundQueing 
)
protected
void EventDispatcher::processEvent ( EventStruct pES)
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.

bool vrecko::EventDispatcher::reportEvent ( const std::string &  senderAndOutputString,
VreckoMessage pMessage,
EventType  eType = EXPRESS_EVENT 
)
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.

bool vrecko::EventDispatcher::reportEvent ( BaseClass receiver_ptr,
const std::string &  input_name,
VreckoMessage pMessage,
EventType  eType = EXPRESS_EVENT 
)
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.

bool EventDispatcher::reportEventCore ( BaseClass receiver_ptr,
const std::string &  sender,
VreckoMessage pMessage,
EventType  eType 
)
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.

void vrecko::EventDispatcher::resetProcessedEventsCounter ( )
inline

Debug method to reset the number of processed messages.

void vrecko::EventDispatcher::setMainThreadId ( pthread_t  ptID)
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).

void vrecko::EventDispatcher::setScenePtr ( Scene ptr)
inline

Sets the Scene that holds this EventDispatcher.

void EventDispatcher::update ( void  )
virtual

Updates the EventDispatcher.

Will process pending messages.

Reimplemented from vrecko::BaseClass.

Member Data Documentation

bool vrecko::EventDispatcher::bAllowForegroundListQueing
protected
int vrecko::EventDispatcher::bgListId
protected
REQUEST_Map vrecko::EventDispatcher::default_request_interconnection_map
protected
EI_Type vrecko::EventDispatcher::event_interconnection_map
protected

Multimap where the interconnection between sender and receiver are stored .

std::vector<EventDefinitionStruct> vrecko::EventDispatcher::eventsVector
protected

Vector with all defined events.

pthread_t vrecko::EventDispatcher::hMainThreadId
protected
std::vector<EventStruct*> vrecko::EventDispatcher::incoming_events[2]
protected

List of the incoming events.

int vrecko::EventDispatcher::iProcessedEventsCounter
protected
MTLock vrecko::EventDispatcher::mainLock
protected
bool vrecko::EventDispatcher::net_support
protected

Net support flag.

std::map<std::string, BaseClass *> vrecko::EventDispatcher::outerObject_map
protected

Pointer to the Outer receiveEvents function.

std::map<std::string, void*> vrecko::EventDispatcher::received_event_map
protected

Multimap with all last received events.

std::map<std::string, Decomposition_vec> vrecko::EventDispatcher::receiver_decomposition
protected

Decomposition of the receiver string.

REQUEST_Map vrecko::EventDispatcher::request_interconnection_map
protected
Scene* vrecko::EventDispatcher::scene_ptr
protected

Pointer to the Scene that holds this EventDispatcher.

std::map<std::string, Decomposition_vec> vrecko::EventDispatcher::sender_decomposition
protected

Decomposition of the sender string.


The documentation for this class was generated from the following files: