Skip to content

Instantly share code, notes, and snippets.

View sandorkan's full-sized avatar

sandro brunner sandorkan

View GitHub Profile
@sandorkan
sandorkan / HelloSubscriberCallbackMethod.java
Created November 7, 2012 09:46
Implementation of callback-method on_data_available() of HelloSubscriber
public void on_data_available(DataReader reader) {
// Method Parameter of Type DataReader must be cast to Data Type of DataReader for this Topic
StringDataReader stringReader = (StringDataReader) reader;
SampleInfo info = new SampleInfo();
for (;;) {
try {
String sample = stringReader.take_next_sample(info);
if (info.valid_data) {
@sandorkan
sandorkan / HelloSubscriberDataReader.java
Created November 7, 2012 09:30
Creation of DataReader
// Create the data reader using the default publisher
StringDataReader dataReader = (StringDataReader) participant.create_datareader(
topic, //Topic
Subscriber.DATAREADER_QOS_DEFAULT, // QoS
new HelloSubscriber(), // Listener
StatusKind.DATA_AVAILABLE_STATUS); // mask
if (dataReader == null) {
System.err.println("Unable to create DDS Data Reader");
return;
@sandorkan
sandorkan / HelloSubscriberBeginning.java
Created November 7, 2012 09:17
Class Definition, creation of DomainParticipant and Topic of HelloSubscriber
public class HelloSubscriber extends DataReaderAdapter {
// For clean shutdown sequence
private static boolean shutdown_flag = false;
public static final void main(String[] args) {
// Create the DDS Domain participant on domain ID 0
DomainParticipant participant = DomainParticipantFactory.get_instance().create_participant(
0, // Domain ID = 0
@sandorkan
sandorkan / HelloPublisherWritingData.java
Created November 7, 2012 09:05
Writing Data with DataWriter from HelloPublisher
System.out.println("Ready to write data.");
System.out.println("When the subscriber is ready, you can start writing.");
System.out.print("Press CTRL+C to terminate or enter an empty line to do a clean shutdown.\n\n");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try
{
while (true) {
System.out.print("Please type a message> ");
String toWrite = reader.readLine();
@sandorkan
sandorkan / HelloPublisherDataWriter.java
Created November 7, 2012 08:55
Creation of DataWriter for HelloPublisher
// Create the data writer using the default publisher
StringDataWriter dataWriter = (StringDataWriter)participant.create_datawriter(
helloWorldTopic, // Topic
Publisher.DATAWRITER_QOS_DEFAULT, // QoS
null, // listener
StatusKind.STATUS_MASK_NONE); // mask
if (dataWriter == null) {
System.err.println("Unable to create data writer\n");
return;
}
@sandorkan
sandorkan / HelloPublisherTopicCreation.java
Created November 6, 2012 15:29
Creation of the Topic for HelloPublisher
// Create the topic "Hello World" with the built-in String type
Topic helloWorldTopic = participant.create_topic(
"Hello, World", //topic_name
StringTypeSupport.get_type_name(), //type_name
DomainParticipant.TOPIC_QOS_DEFAULT, //QoS
null, //listener
StatusKind.STATUS_MASK_NONE); //mask
if (topic == null) {
System.err.println("Unable to create topic.");
return;
@sandorkan
sandorkan / HelloPublisherDomainParticipant.java
Created November 6, 2012 15:15
Creation of DomainParticipant
// Create the DDS Domain participant on domain ID 0
DomainParticipant participant = DomainParticipantFactory.get_instance().create_participant(
0, // Domain ID = 0
DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT, // QoS Settings = Default
null, // listener
StatusKind.STATUS_MASK_NONE); // mask
if (participant == null) {
System.err.println("Unable to create domain participant");
return;
}
public class HelloPublisher {
public static final void main(String[] args) {