package Logger; import java.util.concurrent.ConcurrentSkipListMap; import com.rti.dds.domain.*; import com.rti.dds.dynamicdata.DynamicDataTypeSupport; import com.rti.dds.infrastructure.*; import com.rti.dds.publication.builtin.*; import com.rti.dds.subscription.*; import com.rti.dds.topic.Topic; import com.rti.dds.topic.TopicQos; import com.rti.dds.typecode.TypeCode; public class Logger { static int domainId = 0; public DomainParticipant participant; private PublicationBuiltinTopicDataDataReader publicationsDR; private ConcurrentSkipListMap discoveredTypes; public static final void main(String args[]) throws InterruptedException { Logger logger = new Logger(); if ( !logger.start() ) { return; } } private boolean start() { discoveredTypes = new ConcurrentSkipListMap(); DomainParticipantFactory factory = DomainParticipantFactory.get_instance(); DomainParticipantFactoryQos factoryQos = new DomainParticipantFactoryQos(); factoryQos.entity_factory.autoenable_created_entities = false; DomainParticipantQos pQos = new DomainParticipantQos(); factory.get_default_participant_qos(pQos); pQos.participant_name.name = "RTI Connext Logger"; participant = factory.create_participant( domainId, pQos, null, StatusKind.STATUS_MASK_NONE); publicationsDR = (PublicationBuiltinTopicDataDataReader) participant.get_builtin_subscriber().lookup_datareader("DCPSPublication"); participant.enable(); publicationsDR.set_listener(new TopicListener(this), StatusKind.STATUS_MASK_ALL); publicationsDR.get_statuscondition().set_enabled_statuses(StatusKind.DATA_AVAILABLE_STATUS); return true; } public void processDiscoveredTopic(String topic_name, String type_name, TypeCode type_code, TopicQos topicQOS, DataReaderQos drQOS) { TypeCode existingType = null; DynamicDataTypeSupport typeSupport = null; //System.out.println("Discovered topic: \"" + topic_name + "\" with type: \"" + type_name + "\""); if ( type_code == null ) { System.out.println("No type information was supplied for type: \"" + type_name + "\""); return; } existingType = discoveredTypes.get(type_name); if ( existingType == null ) { discoveredTypes.put(type_name, type_code); // register the discovered type with the Participant typeSupport = new DynamicDataTypeSupport(type_code, DynamicDataTypeSupport.TYPE_PROPERTY_DEFAULT); typeSupport.register_type(participant, type_name); } else { System.out.println("This type had been seen already. Comparing the type definitions..."); if ( existingType.equals(type_code) ) { System.out.println("The type matches the existing definition"); } else { System.out.println("The type DOES NOT match the existing definition"); System.out.println("This is the existing definition:"); existingType.print_IDL(0); System.out.println("This is the definition of the type just discovered:"); type_code.print_IDL(0); } } // Check if we had already a topic created with that name if ( this.participant.lookup_topicdescription(topic_name) == null ) { //System.out.println("This topic \"" + topic_name + "\" had not seen before. Creating it."); Topic topic = participant.create_topic( topic_name, type_name, topicQOS, null, // listener StatusKind.STATUS_MASK_NONE); if (topic == null) { System.err.println("Unable to create topic."); return; } // Create the data reader using the default publisher DataReader dataReader = (DataReader) participant.create_datareader( topic, drQOS, new DynamicListener(this), // Listener StatusKind.STATUS_MASK_ALL); dataReader.enable(); dataReader.get_statuscondition().set_enabled_statuses(StatusKind.DATA_AVAILABLE_STATUS); } } }