posted on Monday, December 13, 2010 - 12:24 pm
Does anyone have any experiences or best practice to share regarding how topic names are managed in code in a DDS application. Especially given the special significance of topics in a data centric system, and the fact that many different types of producers and consumers across many processes could be interested in such topics, where does the name "belong" so to speak?
For example, if I want to subscribe to temperature readings on my imaginary sensor, is that topic called "Temperatures" or "TempSensor1" or ...
Do you put all these string literals in big constants files and use that? Do you have many such files for each program module? Or do you have a big chart on the wall listing all the system topics and use the literal values everywhere? Do you attempt to hide these names and create a higher level API for accessing data received on these topics?
I think topic names should be regarded like class-names: you can have any number of instances of a class, but the classname describes what the class is all about and therefore what the state of each instance of the class represents.
In case of DDS you already have your datatype-name in IDL which serves a similar purpose, but one datatype might be represented by different topics. (Remember that a Topic is a unique combination of a datatype and a set of QosPolicies applied to it. This combination is given a name that should be unique in your Domain). If you only have 1 Topic per datatype it makes sense to use the Datatype's name as part of your Topic name and append a fixed postfix (e.g. for datatype "Foo" you derive topicname "FooTopic") to distinguish between the typename and the topicname.
In some cases you need to use the same datatype with different Qos values, so make sure that in those cases the Topic name expresses what makes this topic unique when compared to the other topics using the same datatype. For example, You might have a datatype "Foo" that for some purposes might need to be transmitted Reliably, and for some other purposes it might not. You could then name the first topic "ReliableFooTopic" and the other one "BestEffortFooTopic".
Of course there are numerous other naming schema's, but this one might help you to enforce consistent naming all throughout your Domains since you derive your topic names from the typenames that come straight from the IDL and that are shared between all participants of your Domain. You can use the TypeSupport's get_type_name operation to extract the IDL type-names from each of the datatypes.
Be aware that the DDS spec only allows you to use alphanumeric and numeric characters for the topic name (the '_' is the only exception to this rule) so that you cannot use IDL names (containing the scope operator '::') straight away. We therefore often substitute the scoping operator with an underscore in our topic names.