What is a service description? (write some text here)
On startup - the ServiceManager parses the <YOUR_INSTALL_DIR>/share
directory for XML-files. If you specified another directory (./run-servicemgr path
), this one is parsed. The <YOUR_INSTALL_DIR>/share/service.dtd
specifies the grammer.
Forcing Service Instances to use another XML Service Description than the default:
Sometimes you want to start several instances of a service with different service descriptions.
This is solved by a new feature (Dec 11 2003): every service can be forced to use a certain XML description.
In the command line do a:
service -DserviceName="ABC"
Then the service will use the XML file called ABC.xml
When the service network is to be modified dynamically, or a new Service Description is required, a service can be described manually. All this can be done without creating a new class. You need however a custom class once you want to register a service for your new ServiceDescription.
TemplateService:
When you are in a coded section, where your own service is registered, you can call the TemplateService's getServiceManager
method.
Without TemplateService:
To describe your service, you need to first initialize your CORBA connection.
argc=len(sys.argv)-1
myOrbConnection = Chair.CorbaInit(argc, sys.argv)
Then get a reference to the ServiceManager:
smgr = myOrbConnection.getServiceManager()
The ServiceManager gives you a new ServiceDescription if you ask for it.
sd = smgr.newServiceDescription("Test")
You can now describe yourself.
sd.setStartOnDemand(false)
sd.setStopOnNoUse(true)
Then add a new Need:
nd=sd.newNeed("pose")
nd.newConnector("PushConsumer")
nd.setType("Chair.PoseData")
If you want, add some attributes:
nd.setAttribute("whatever", "*")
Likewise, you could add also some abilities. And dont forget to activate the ServiceDescription..
smgr.activateServiceDescription("Test")
Dynamite planted. You can see your new service in the ServiceDIVE when you set your filter preferences to showing unregistered services as well.
setStartOnDemand(False)
Start the service only when needed. (default: True
)
setStopOnNoUse(False)
Stop the service when not needed. (default: True
)
setIsTemplate(False)
Allow more Instances of this service. (default. False
)
setMinInstances(2)
Minumum Number of communication Partners required to set up connection (default: 1
)
setMaxInstances(42)
Maximum Number of communication partners allowed. (default: 1
)
setAttribute("application", "SHEEP");
To develop a new need on the fly, you may find this piece of code helpful:
void SoPoseDataReceiver::createNeed() { //Get own service description DWARF::ActiveServiceDescription_ptr serviceDesc = ViewerFacade::getInstance()->getServiceDesc(); //Variables needed to describe Need NeedDescription_var nd; ConnectorDescription_var cd; const char * thingID = (this->getName()).getString(); const char * pred = ("(&(ThingID="+string(thingID)+")(ThingType=PoseData))").c_str(); //set name, type and predicate nd=serviceDesc->newNeed(thingID); nd->setType("PoseData"); nd->setPredicate(pred); nd->setMinInstances(0); nd->setMaxInstances(1); //set connector protocol cd=nd->newConnector("PushConsumer"); //register need @ servicemgr try { serviceDesc->registerNeed( nd->getName(), this->_this() ); DEBUGSTREAM(5, "Registering need "<getName()); } catch(...) { DEBUGSTREAM(0, "Caught exception Registering Need."); } }