Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-13335: Fix examples that assume invalid data cannot be ALIVE #645

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pipeline {
sh 'tar zxvf connextdds-staging-${CONNEXTDDS_ARCH}.tgz unlicensed/'

sh '''
cp ${RTI_INSTALLATION_PATH}/rti_connext_dds-*/lib/${CONNEXTDDS_ARCH}/openssl-1.*/* \
cp ${RTI_INSTALLATION_PATH}/rti_connext_dds-*/lib/${CONNEXTDDS_ARCH}/openssl-3.*/* \
${RTI_INSTALLATION_PATH}/rti_connext_dds-*/lib/${CONNEXTDDS_ARCH}/
'''
}
Expand Down
9 changes: 4 additions & 5 deletions examples/connext_dds/keyed_data/c++11/keys_subscriber.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ int process_data(dds::sub::DataReader<keys> reader)
<< ", x: " << sample.data().x()
<< ", y: " << sample.data().y() << std::endl;
} else {
// Since there is not valid data, it may include metadata.
keys sample;
reader.key_value(sample, info.instance_handle());

// Here we print a message if the instance state is
// 'not_alive_no_writers' or 'not_alive_disposed'.
const dds::sub::status::InstanceState &state =
info.state().instance_state();
if (state
Expand All @@ -50,7 +46,10 @@ int process_data(dds::sub::DataReader<keys> reader)
} else if (
state
== dds::sub::status::InstanceState::not_alive_disposed()) {
std::cout << "Instance " << sample.code() << " disposed"
std::cout << "Instance " << sample.code() << " is disposed"
<< std::endl;
} else {
std::cout << "Instance " << sample.code() << " is alive"
<< std::endl;
}
}
Expand Down
14 changes: 8 additions & 6 deletions examples/connext_dds/keyed_data/c++98/keys_subscriber.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ unsigned int process_data(keysDataReader *typed_reader)

samples_read++;
} else {
/* Since there is not valid data, it may include metadata */
/* An invalid sample can be in any instance state. */
keys dummy;
retcode = typed_reader->get_key_value(
dummy,
Expand All @@ -64,16 +64,18 @@ unsigned int process_data(keysDataReader *typed_reader)
std::cout << "get_key_value error " << retcode << std::endl;
continue;
}

/* Here we print a message if the instance state is ALIVE_NO_WRITERS
* or ALIVE_DISPOSED */
if (info_seq[i].instance_state
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
std::cout << "Instance " << dummy.code << " has no writers\n";
std::cout << "Instance " << dummy.code << " has no writers"
<< std::endl;
} else if (
info_seq[i].instance_state
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
std::cout << "Instance " << dummy.code << " disposed\n";
std::cout << "Instance " << dummy.code << " is disposed"
<< std::endl;
} else {
std::cout << "Instance " << dummy.code << " is alive"
<< std::endl;
}
}
/* End changes for Keyed_Data */
Expand Down
15 changes: 7 additions & 8 deletions examples/connext_dds/keyed_data/c/keys_subscriber.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,25 @@ void keysListener_on_data_available(void *listener_data, DDS_DataReader *reader)
printf("Instance %d: x: %d, y: %d\n", data->code, data->x, data->y);

} else {
/* Since there is not valid data, it may include metadata */
keys dummy;
/* An invalid data sample can be in any instance state. */
keys key_value;
retcode = keysDataReader_get_key_value(
keys_reader,
&dummy,
&key_value,
&info->instance_handle);
if (retcode != DDS_RETCODE_OK) {
printf("get_key_value error %d\n", retcode);
continue;
}

/* Here we print a message if the instance state is ALIVE_NO_WRITERS
* or ALIVE_DISPOSED */
if (info->instance_state
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
printf("Instance %d has no writers\n", dummy.code);
printf("Instance %d has no writers\n", key_value.code);
} else if (
info->instance_state
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
printf("Instance %d disposed\n", dummy.code);
printf("Instance %d is disposed\n", key_value.code);
} else {
printf("Instance %d is alive\n", key_value.code);
}
}
/* End changes for Keyed_Data */
Expand Down
2 changes: 1 addition & 1 deletion examples/connext_dds/keyed_data/java/keysPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void runApplication()
instance[2].code = 2;

// The keys must have been set before making this call
System.out.println("Registering instance" + instance[0].code);
System.out.println("Registering instance " + instance[0].code);
handle[0] = writer.register_instance(instance[0]);

// Modify the data to be sent here
Expand Down
9 changes: 4 additions & 5 deletions examples/connext_dds/keyed_data/java/keysSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ private int processData()
"Instance " + sample.code + ": x: " + sample.x
+ ", y: " + sample.y + "\n");
} else {
// Since there is not valid data, it may include metadata
keys dummy = new keys();
reader.get_key_value(dummy, info.instance_handle);

// Here we print a message if the instance state is
// ALIVE_NO_WRITERS or ALIVE_DISPOSED
if (info.instance_state
== InstanceStateKind
.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
Expand All @@ -83,7 +79,10 @@ private int processData()
== InstanceStateKind
.NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
System.out.print(
"Instance " + dummy.code + " disposed\n");
"Instance " + dummy.code + " is disposed\n");
} else {
System.out.print(
"Instance " + dummy.code + " is alive\n");
}
}
samplesRead++;
Expand Down
Loading