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

Class for iterating through all environment objects in non-main threads. More...

#include <Scene.h>

Inheritance diagram for vrecko::Scene::EOIteratorHelper:
vrecko::BaseClass

Public Member Functions

 EOIteratorHelper ()
 
 ~EOIteratorHelper ()
 
bool initIteration ()
 
bool initIterationFrom (Scene::EOIteratorHelper *sourceHelper, unsigned long dwInitFlags=EOIH_IF_START_BEGINNING)
 
void endIteration ()
 
bool getAndLockNextObject (EnvironmentObject **outObject)
 
bool releaseObject (void)
 
- 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 void update (void)
 This method is called periodically in case this instance is registered in Scheduler. 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 DynamicArray
< EnvironmentObject * > 
EOVector
 
- 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

virtual int processNotification (BaseClass *sender, unsigned long notificationType, void *notificationData)
 Process an incoming notification. More...
 
- Protected Member Functions inherited from vrecko::BaseClass
bool sendNotifications (unsigned long notificationType, void *notificationData)
 
IOPinBasefindPinInList (const char *strName, PinList *pinList)
 Internal method to find a given pin in a given list. More...
 

Protected Attributes

bool bInited
 was the search initialized? More...
 
MTLock generalLock
 
EOVector objects
 A list of all objects in the scene. More...
 
int currentObjectIndex
 
bool bObjectLocked
 
HANDLE hCollisionEvent1
 
HANDLE hCollisionEvent2
 
bool bCollisionOccured_EventExpected
 
- 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
 

Additional Inherited Members

- 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
}
 

Detailed Description

Class for iterating through all environment objects in non-main threads.

Iterating through objects in the main thread is simple, but other threads must watch for sudden objects deletion and additions. This helper class will take care of the problems. HOWEWER, IT IS NECCESSARY to use the helper methods to lock and to RELEASE currently processed object.

NOTE: This class in not fully multihread-protected. It expects that all of the itetration will happen in one thread. Also, it expects that the object unregistrations notifications will came from the main thread (which should happen if other other plug-ins are written correctly)

Author
Vit Kovalcik
Date
2010

Member Typedef Documentation

Constructor & Destructor Documentation

vrecko::Scene::EOIteratorHelper::EOIteratorHelper ( )
vrecko::Scene::EOIteratorHelper::~EOIteratorHelper ( )

Member Function Documentation

void vrecko::Scene::EOIteratorHelper::endIteration ( )

Releases internal structures and deletes the notification interfaces from the scene. Automatically releases the locked object if necessary.

bool vrecko::Scene::EOIteratorHelper::getAndLockNextObject ( EnvironmentObject **  outObject)

Retrieves the object that is next in the iteration and LOCKS it (!!!). That said, other threads (including the main one) can still use the object, but any call to Scene::unregisterEnvironmentObject() will cause that thread to stop and wait until YOU call the EOIteratorHelper::ReleaseObject().

  • i.e. the object basically cannot be deleted from scene.

(Note: Multiple iterator helpers can lock the same object. That is not a problem.)

Returns "false" and resets the [*outObject] to NULL in case the helper reached the end of the list.

Automatically releases previously locked object if necessary.

bool vrecko::Scene::EOIteratorHelper::initIteration ( )

Initializes internal structures (retrieves list of all objects in the scene) and sets the scene to inform this helper about every object addition and deletion.

bool vrecko::Scene::EOIteratorHelper::initIterationFrom ( Scene::EOIteratorHelper sourceHelper,
unsigned long  dwInitFlags = EOIH_IF_START_BEGINNING 
)

Similar to [initIteration], but the iteration doesn't need to start from the exact beginning, but can start from the object that the other interatorHelper is processing. This is defined through [dwInitFlags], which is a combination of EOIH_IF_* flags.

int vrecko::Scene::EOIteratorHelper::processNotification ( BaseClass sender,
unsigned long  notificationType,
void *  notificationData 
)
protectedvirtual

Process an incoming notification.

Override this method to react to a registered notification (see addNotification() method).

Parameters
sender(BaseClass *) The sender of the notification
notificationType(unsigned long) Type of the notification, only ONE bit will be set
notificationData(void *) Appropriate notification data, dependent on the notificationType.
Returns
(int) Should return 0, other values are reserved for future use.

Reimplemented from vrecko::BaseClass.

bool vrecko::Scene::EOIteratorHelper::releaseObject ( void  )

Releases the object that was previously locked through this helper.

Member Data Documentation

bool vrecko::Scene::EOIteratorHelper::bCollisionOccured_EventExpected
protected
bool vrecko::Scene::EOIteratorHelper::bInited
protected

was the search initialized?

bool vrecko::Scene::EOIteratorHelper::bObjectLocked
protected

whether or not is the object with [currentObjectIndex] locked.

int vrecko::Scene::EOIteratorHelper::currentObjectIndex
protected

Current position of the iterator. The given object is "LOCKED" if the [bObjectLocked] is true i.e. the object cannot be unregistered from the scene (= deleted). At the beginning the currentObjectIndex is -1.

MTLock vrecko::Scene::EOIteratorHelper::generalLock
protected
HANDLE vrecko::Scene::EOIteratorHelper::hCollisionEvent1
protected
HANDLE vrecko::Scene::EOIteratorHelper::hCollisionEvent2
protected
EOVector vrecko::Scene::EOIteratorHelper::objects
protected

A list of all objects in the scene.


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