Jump to content
OpenSplice DDS Forum
Sign in to follow this  
getviswa

Getting Present Topic

Recommended Posts

Hi Viswa,

 

Yes this is possible as this kind of 'meta-data' is available via the standardized 'built-in-topics'. For the set of 'in-use-topics' you need to read the "DCPSTopic" built-in-topic samples (for which there's also a built-in reader).

 

-Hans

Share this post


Link to post
Share on other sites
getviswa   

Hi Viswa,

 

Yes this is possible as this kind of 'meta-data' is available via the standardized 'built-in-topics'. For the set of 'in-use-topics' you need to read the "DCPSTopic" built-in-topic samples (for which there's also a built-in reader).

 

-Hans

 

Thanks for the reply Hans. I couldnt find the reference in the documents provided from the prism-tech site.

 

can u provide me some reference to do.

 

Thanks

-Viswa

Share this post


Link to post
Share on other sites

Hi Viswa,

 

The concept (and and contents) of built-in topics is explained in chapter 7.1.5 of the OMG-DDS rev1.2 specification.

In our 6.1 trial-distribution (available from our website) there are bundled examples that explain how to read from the built-in topics .. copying the relevant parts of the java example here:

 

 

 

/* Resolve the built-in Subscriber. */

Subscriber builtinSubscriber = participant.get_builtin_subscriber();

/* Lookup the DataReader for the DCPSParticipant built-in Topic. */

DataReader reader = builtinSubscriber

.lookup_datareader("DCPSParticipant");

/* Safely cast the DataReader to a ParticipantBuiltinTopicDataReader. */

ParticipantBuiltinTopicDataDataReader participantReader = ParticipantBuiltinTopicDataDataReaderHelper

.narrow(reader);

/* Allocate a new typed holder for data samples. */

ParticipantBuiltinTopicDataSeqHolder data = new ParticipantBuiltinTopicDataSeqHolder();

/* Allocate a new holder for sample infos. */

SampleInfoSeqHolder info = new SampleInfoSeqHolder();

System.out.print("Waiting for historical data... ");

/* Make sure all historical data is delivered in the DataReader. */

participantReader.wait_for_historical_data(DURATION_INFINITE.value);

System.out.println("done");

/* Allocate a new Waitset */

WaitSet waitset = new WaitSet();

/* Create a new ReadCondition for the reader that matches all samples. */

ReadCondition condition = participantReader.create_readcondition(

ANY_SAMPLE_STATE.value, ANY_VIEW_STATE.value,

ANY_INSTANCE_STATE.value);

/* Attach the condition to the waitset. */

waitset.attach_condition(condition);

/* Allocate a holder for conditions. */

ConditionSeqHolder conditions = new ConditionSeqHolder();

/* Allocate a map to store node information later on. */

/* The key of the map is the id of the node and the value is the */

/* number of active participants on that node. */

HashMap<Integer, Integer> nodes = new HashMap<Integer, Integer>();

/* Allocate a map to store node information later on. */

/* The key of the map is the id of the node and the value is the */

/* name of the node. */

HashMap<Integer, String> nodeNames = new HashMap<Integer, String>();

/*

* Block the current thread until the attached condition becomes true or

* the user interrupts.

*/

int returnCode = waitset._wait(conditions, DURATION_INFINITE.value);

boolean done = false;

/* Continue processing until interrupted. */

while ( ! done) {

/* Take all available data from the reader. */

returnCode = participantReader.take(data, info,

LENGTH_UNLIMITED.value, ANY_SAMPLE_STATE.value,

ANY_VIEW_STATE.value, ANY_INSTANCE_STATE.value);

/* Verify that data has been taken. */

if (returnCode == RETCODE_OK.value) {

/* Iterate the list of taken samples. */

for (int i = 0; i < data.value.length; i++) {

/* Resolve the node identification. */

int nodeId = data.value.key[0];

/* Initialise the number of participants for a node. */

int participantCount = 0;

/* Check if we saw a participant for the node before. */

if (nodes.containsKey(nodeId)) {

/*

* Resolve the actual number of participants on the

* node.

*/

participantCount = nodes.get(nodeId);

}

/* Check sample info to see whether the instance is ALIVE. */

if (info.value.instance_state == ALIVE_INSTANCE_STATE.value) {

/*

* The splicedaemon publishes the host-name in the

* user_data field.

*/

if (data.value.user_data.value.length != 0) {

hostName = new String(data.value.user_data.value);

nodeNames.put(nodeId, hostName);

} else {

hostName = null;

}

/* Increase the number of participants. */

participantCount++;

/* Update the number of participants for the node. */

nodes.put(nodeId, participantCount);

/* If it's the first participant, report the node is up. */

if (participantCount == 1) {

System.out.println("Node '" + nodeId

+ "' started (Total nodes running: "

+ nodes.size() + ")");

}

if (hostName != null) {

System.out.println("Hostname for node '" + nodeId

+ " is '" + hostName + "'.");

}

} else {

/* Decrease the number of participants. */

participantCount--;

/*

* If no more participants exist, report the node is

* down.

*/

if (participantCount == 0) {

hostName = nodeNames.get(nodeId);

nodeNames.remove(nodeId);

nodes.remove(nodeId);

if (hostName != null) {

System.out.println("Node " + nodeId + " ("

+ hostName

+ ") stopped (Total nodes running: "

+ nodes.size() + ")");

} else {

System.out.println("Node " + nodeId

+ " stopped (Total nodes running: "

+ nodes.size() + ")");

}

} else if (participantCount > 0) {

nodes.put(nodeId, participantCount);

}

}

}

}

Note that this example is about reading the DCPSParticipant built-in topic (that provides information about what participants are active in the system), yet using the DCPSTopic built-in topic to obtain information about the existing topics in the system can be done similarly.

 

Regards,

Hans

 

Share this post


Link to post
Share on other sites
getviswa   

Hi Hans,

 

Thanks for your valuable inputs, it is much helpful.

 

i used the code you provided and it is working fine.

 

Thanks again.

 

Thanks

-Viswa

Share this post


Link to post
Share on other sites
getviswa   

Hi All,

 

it will be helpful to get the in-use topics

 

Here is the code:

 

Subscriber_var builtinSubscriber = mgr->participant->get_builtin_subscriber();
DataReader_var reader = builtinSubscriber->lookup_datareader("DCPSTopic");
TopicBuiltinTopicDataDataReader_var participantReader = TopicBuiltinTopicDataDataReader::_narrow(reader);
TopicBuiltinTopicDataSeq data;
ReturnCode_t status;
SampleInfoSeq info;
status=participantReader->take ( data, info, LENGTH_UNLIMITED,DDS::ANY_SAMPLE_STATE,DDS::ANY_VIEW_STATE,DDS::ANY_INSTANCE_STATE) ;

 

Here is the BuidInTopic IDL

struct TopicBuiltinTopicData {
 BuiltinTopicKey_t key;
 string name;
 string type_name;
 DurabilityQosPolicy durability;
 QosPolicy deadline;
 LatencyBudgetQosPolicy latency_budget;
 LivelinessQosPolicy liveliness;
 ReliabilityQosPolicy reliability;
 TransportPriorityQosPolicy transport_priority;
 LifespanQosPolicy lifespan;
 DestinationOrderQosPolicy destination_order;
 HistoryQosPolicy history;
 ResourceLimitsQosPolicy resource_limits;
 OwnershipQosPolicy ownership;
 TopicDataQosPolicy topic_data;
};

 

Thanks

-Viswa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×