#include <vhdOpenSGViewerServiceBody.h>
Inheritance diagram for vhdOpenSGViewerServiceBody:
Public Member Functions | |
vhdOpenSGViewerServiceBody (const std::string &serviceClassName, const std::string &serviceName) | |
virtual | ~vhdOpenSGViewerServiceBody () |
int | nbProperty (void) const |
vhdPropertyRef | getProperty (const int id) const |
vhdPropertyRef | getProperty (const std::string &pname) const |
virtual OSG::NodePtr | getSceneGraphRoot (void) |
virtual vhdOpenSGViewerServiceData | getOpenSGViewerServiceData () |
Protected Member Functions | |
virtual vhtSize32 | _getServiceBodyVersionImplem () |
virtual void | _declareCollaborationsImplem () |
virtual vhtBool | _initImplem (vhdServiceContextRef serviceContext) |
virtual vhtBool | _initPropertyScanImplem (vhdPropertyRef property) |
virtual vhtBool | _terminateImplem () |
virtual vhtBool | _updateImplem () |
virtual void | _handleWarpClockExchangeImplem (const std::string &warpClockName, vhdWarpClockRef warpClock) |
virtual void | _handleAddServiceImplem (vhdServiceHandleRef serviceHandle) |
virtual void | _handleRemoveServiceImplem (vhdServiceHandleRef serviceHandle) |
virtual void | _handleServiceStateChangeImplem (vhdServiceHandleRef serviceHandle) |
virtual vhtBool | _handleAddPropertyScanImplem (vhdPropertyRef property) |
virtual vhtBool | _handleRemovePropertyScanImplem (vhdPropertyRef property) |
virtual void | _handlePropertyChangeImplem (vhdPropertyRef property) |
virtual vhtBool | _filterEventImplem (vhdEventRef event) |
virtual vhtBool | _handleEventImplem (vhdEventRef event) |
Private Attributes | |
vhdCLASS_TYPE | |
vhdOpenSGViewerServiceData | m_data |
_Impl * | _impl |
Classes | |
class | _Impl |
vhdOpenSGViewerServiceBody::vhdOpenSGViewerServiceBody | ( | const std::string & | serviceClassName, | |
const std::string & | serviceName | |||
) |
Constructor.
vhdOpenSGViewerServiceBody::~vhdOpenSGViewerServiceBody | ( | ) | [virtual] |
Destructor.
int vhdOpenSGViewerServiceBody::nbProperty | ( | void | ) | const |
Get the number of OpenSGViewerService registered vhdProperty
vhdPropertyRef vhdOpenSGViewerServiceBody::getProperty | ( | const int | id | ) | const |
Get one OpenSGViewerService registered vhdProperty by index [in the internal propertyController table] Return NULL if index out of bound.
vhdPropertyRef vhdOpenSGViewerServiceBody::getProperty | ( | const std::string & | pname | ) | const |
Get one vhdOpenSGViewerService registered vhdProperty by name Return NULL if no registered property found for the given 'pname'.
virtual vhtSize32 vhdOpenSGViewerServiceBody::_getServiceBodyVersionImplem | ( | ) | [inline, protected, virtual] |
___IMPLEMENT IT___
Imeplement it as a simple inline method returning version number of your ServiceBody implementation. Example: virtual vhtSize32 _getServiceVersion() { return 27; }
virtual void vhdOpenSGViewerServiceBody::_declareCollaborationsImplem | ( | ) | [inline, protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
vhtBool vhdOpenSGViewerServiceBody::_initImplem | ( | vhdServiceContextRef | serviceContext | ) | [protected, virtual] |
___IMPLEMENT IT___
Called by vhdServiceHandle to notify ServiceBody that it should initialize itself. It is assured that the non-NULL cnotext is passed thanks to the thread safe interface
vhtBool vhdOpenSGViewerServiceBody::_initPropertyScanImplem | ( | vhdPropertyRef | property | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
Right after _initImplem() the kernel will make the vhdProperty tree scan for you using vhdPropertyTreeIterator and it will feed you with all vhdProperties found using this method. Note that the service is initialized after the scan which means that within this method you may be adding new properties to the tree and still your _handleAddPropertyImplem() will not be called since notifications are forwarded only to the initialized services.
You may stop the scan at any moment by returning FALSE. Otherwise return TRUE to continue the scan.
Return TRUE for each property that your vhdService will operate on (FALSE means that you are not interested in a property)
Normally for properties that you would like to use add them to your vhdPropertyController (for READ/WRITE) or vhdPropertyObserver (for READ ONLY)
Example of implementation that filters properties that can be of interest for you. void postInitPropertyScanImplem( vhdPropertyRef property) { if (false) else if ( vhdREF_IS_OF_CLASS( vhdGeometryProperty, property)) { vhdGeometryPropertyRef geomProp = vhdREF_DYNAMIC_CAST( vhdGeometryProperty, property); ... getServiceContext()->getPropertyController/Observer()->addProperty(property); } else if ( vhdREF_IS_OF_CLASS( vhdCameraProperty, property)) { vhdCameraPropertyRef camProp = vhdREF_DYNAMIC_CAST( vhdCameraProperty, property); ... getServiceContext()->getPropertyController/Observer()->addProperty(property); } else if ( vhdREF_IS_OF_CLASS( vhdProperty, property)) { vhdCameraPropertyRef camProp = vhdREF_DYNAMIC_CAST( vhdCameraProperty, property); ... getServiceContext()->getPropertyController/Observer()->addProperty(property); }
return TRUE; // to tell the kernel to continue the scan }
vhtBool vhdOpenSGViewerServiceBody::_terminateImplem | ( | ) | [protected, virtual] |
Called by vhdServiceHandle to notify ServiceBody that it should terminate.
vhtBool vhdOpenSGViewerServiceBody::_updateImplem | ( | ) | [protected, virtual] |
Called by ServiceHead to notify ServiceBody that is should update itself. It is called only when service is initialized and running.
void vhdOpenSGViewerServiceBody::_handleWarpClockExchangeImplem | ( | const std::string & | warpClockName, | |
vhdWarpClockRef | warpClock | |||
) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
By implementing this method you may react to the changes of the vhdWarpClock stored for you in the vhdServiceContext. Through this methdo you receive new warpClockName and warpClock or empty string and NULL which means that from now on getWarpClockCurrentTime() will be returnign time readings from the SIM clock.
void vhdOpenSGViewerServiceBody::_handleAddServiceImplem | ( | vhdServiceHandleRef | serviceHandle | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
Each time new vhdProperty is added ot the property tree kept by vhdPropertyManager then vhdPropertyManager goes to the vhdServiceManager and notifies each vhdServiceBody about new properties. If you return TRUE then the property will be added automatically to the private vhdPropertyController of the vhdServiceBody.
This method is called right after the vhdPropery has been added
property | just added to the property tree kept by vhdPropertyManager (so you can inspect the parent, etc.) |
void vhdOpenSGViewerServiceBody::_handleRemoveServiceImplem | ( | vhdServiceHandleRef | serviceHandle | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
This method is called just before any vhdProperty is going to be removed. You may return FALSE to block the removal of the property.
property | just about to be removed from the property tree kept by vhdPropertyManager (so you can inspect the parent, etc.) |
void vhdOpenSGViewerServiceBody::_handleServiceStateChangeImplem | ( | vhdServiceHandleRef | serviceHandle | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
This method is called just after the state of the service changed
property | just about to be removed from the property tree kept by vhdPropertyManager (so you can inspect the parent, etc.) |
vhtBool vhdOpenSGViewerServiceBody::_handleAddPropertyScanImplem | ( | vhdPropertyRef | property | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
Each time a new vhdProperty is added ot the property tree kept by vhdPropertyManager the vhdPropertyManager goes to the vhdServiceManager and notifies each vhdServiceBody about a new property and its subtree using this method.
If you are just interested in the just added property and you do not care about its subproeprty tree then return FALSE which will tell the kernel to stop the scan.
Normally you should check the propery type and if you are interested in controlling or observing it you should add it respectively to your vhdPropertyController or vhdPropertyObserver.
This method is called right after the vhdPropery has been added.
property | just added to the property tree kept by vhdPropertyManager (so you can inspect the parent, etc.) |
vhtBool vhdOpenSGViewerServiceBody::_handleRemovePropertyScanImplem | ( | vhdPropertyRef | property | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
Each time new vhdProperty is about to be removed from the property tree kept by vhdPropertyManager the vhdPropertyManager goes to the vhdServiceManager and notifies each vhdServiceBody about a property that is about to be removed and its subtree using this method.
If you are just interested in the proeprty to be removed and you do not care about its subproeprty tree then return FALSE which will tell the kernel to stop the scan.
Normally here you should check the propery type and have a look into your vhdPropertyController or/and vhdPropertyObserver to find out if you were controlling or/and observing a property. This is your decision here then to remove it or still keep the property in vhdPropertyController or/and vhdPropertyObserver.
This method is called just before any vhdProperty is going to be removed.
property | just about to be removed from the property tree kept by vhdPropertyManager (so you can inspect the parent, etc.) |
void vhdOpenSGViewerServiceBody::_handlePropertyChangeImplem | ( | vhdPropertyRef | property | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
In vhdServiceContext of your service you will find access to your own vhdPropertyObserver. vhdPropertyObserver of your service should store all vhdProperies that you are interested to monitor/inspect during the service runtime.
HOW IT WORKS: If you modify any property you may wish to notify all vhdPropertyObservers interested in observing of that property. In order to notify observers you call property->notifyPropertyObservers(). notifyPropertyObservers() will go over all connected vhdPropertyObservers and call on each one propertyObserver->observeProperty(property), and this one in turn will be forwarded to this method below that by default is registerd to the default vhdProperyObserver of your service. As the notification propagation is synchronous you should better react fast.
Please not that once you get the property you do not know what type it is. You may perform powerful hierarchical filtering here. See the example below: void _observePropertyImplem( vhdPropertyRef property) { if (false) else if ( vhdREF_IS_OF_CLASS( vhdGeometryProperty, property)) { vhdGeometryPropertyRef geomProp = vhdREF_DYNAMIC_CAST( vhdGeometryProperty, property); ... } else if ( vhdREF_IS_OF_CLASS( vhdCameraProperty, property)) { vhdCameraPropertyRef camProp = vhdREF_DYNAMIC_CAST( vhdCameraProperty, property); ... } else if ( vhdREF_IS_OF_CLASS( vhdProperty, property)) { ... } else { vhdDIAG_WARNING("::unknown property"); } }
property | that has changed (or somebody wants just to draw your attention to it) |
vhtBool vhdOpenSGViewerServiceBody::_filterEventImplem | ( | vhdEventRef | event | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
Allows for filtering of the events arriving to the vhdEventReceiver of this vhdServiceBody. You filter out event by returnign TRUE. By returning FALSE you let the event go to the _handleEventImplem() method.
SYNC EVENT DISPATCH FORBIDDEN: It is forbidden to call dispatchEvent() (SYNC) opertations from inside of this method. Calling such operations will cause vhdEventDispatcherException. On the other hand you may use postEvent() (ASYNC) opertations. This is to avoid recurrent dispatch opertations where initial dispatch causes handler to trigger another dispatch, etc. which may easily lead to deadlocks and long event handling chains prohibitive for RT simulation.
Hierarchical catching of events is similar to catching of exceptions in C++. You should always catch the root class at the end of the statement. vhtBool _filterEventImplem( vhdEventRef event) { if (false) else if ( vhdREF_IS_OF_CLASS( vhdMySimulationEvent, event)) { ... return TRUE; } else if ( vhdREF_IS_OF_CLASS( vhdSimulationEvent, event)) { ... return TRUE; } else if ( vhdREF_IS_OF_CLASS( vhdSystemEvent, event)) { ... return TRUE; }
return FALSE; }
event | to be checked. |
vhtBool vhdOpenSGViewerServiceBody::_handleEventImplem | ( | vhdEventRef | event | ) | [protected, virtual] |
___OPTIONALLY_IMPLEMENT IT___
If the event passed the filtering step defined by _filterEventImpl() then it is passed to this method for handling. By implementing this method you define an IMMEDIATE REACTION of your service to the events it receives. If you return TRUE it means you handled the event. IF you return FALSE it menas that event should be added to getServiceContext()->getEventReceiver() that is buffering unhandled events for you so that you can process them during _updateImplem().
SYNC EVENT DISPATCH FORBIDDEN: It is forbidden to call dispatchEvent() (SYNC) opertations from inside of this method. Calling such operations will cause vhdEventDispatcherException. On the other hand you may use postEvent() (ASYNC) opertations. This is to avoid recurrent dispatch opertations where initial dispatch causes handler to trigger another dispatch, etc. which may easily lead to deadlocks and long event handling chains prohibitive for RT simulation.
Hierarchical catching of events is similar to catching of exceptions in C++. You should always catch the root class at the end of the statement. vhtBool _filterEventImplem( vhdEventRef event) { if (false) else if ( vhdREF_IS_OF_CLASS( vhdMySimulationEvent, event)) { ... return TRUE; } else if ( vhdREF_IS_OF_CLASS( vhdSimulationEvent, event)) { ... return TRUE; } else if ( vhdREF_IS_OF_CLASS( vhdSystemEvent, event)) { ... return TRUE; }
return FALSE; }
event | to handle. |
NodePtr vhdOpenSGViewerServiceBody::getSceneGraphRoot | ( | void | ) | [virtual] |
Implements vhdIOpenSGViewerService.
vhdOpenSGViewerServiceData vhdOpenSGViewerServiceBody::getOpenSGViewerServiceData | ( | ) | [virtual] |
_Impl* vhdOpenSGViewerServiceBody::_impl [private] |