Skip to content

Commit a0bd5c2

Browse files
Merge pull request #668 from samuelraeburn/feature/CORE-13335-730
CORE-13335: Fix examples that assume invalid data cannot be ALIVE
2 parents 03e69b0 + bcc0129 commit a0bd5c2

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

examples/connext_dds/keyed_data/c++11/keys_subscriber.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ int process_data(dds::sub::DataReader<keys> reader)
3535
<< ", x: " << sample.data().x()
3636
<< ", y: " << sample.data().y() << std::endl;
3737
} else {
38-
// Since there is not valid data, it may include metadata.
3938
keys sample;
4039
reader.key_value(sample, info.instance_handle());
41-
42-
// Here we print a message if the instance state is
43-
// 'not_alive_no_writers' or 'not_alive_disposed'.
4440
const dds::sub::status::InstanceState &state =
4541
info.state().instance_state();
4642
if (state
@@ -50,7 +46,10 @@ int process_data(dds::sub::DataReader<keys> reader)
5046
} else if (
5147
state
5248
== dds::sub::status::InstanceState::not_alive_disposed()) {
53-
std::cout << "Instance " << sample.code() << " disposed"
49+
std::cout << "Instance " << sample.code() << " is disposed"
50+
<< std::endl;
51+
} else {
52+
std::cout << "Instance " << sample.code() << " is alive"
5453
<< std::endl;
5554
}
5655
}

examples/connext_dds/keyed_data/c++98/keys_subscriber.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ unsigned int process_data(keysDataReader *typed_reader)
5555

5656
samples_read++;
5757
} else {
58-
/* Since there is not valid data, it may include metadata */
58+
/* An invalid sample can be in any instance state. */
5959
keys dummy;
6060
retcode = typed_reader->get_key_value(
6161
dummy,
@@ -64,16 +64,18 @@ unsigned int process_data(keysDataReader *typed_reader)
6464
std::cout << "get_key_value error " << retcode << std::endl;
6565
continue;
6666
}
67-
68-
/* Here we print a message if the instance state is ALIVE_NO_WRITERS
69-
* or ALIVE_DISPOSED */
7067
if (info_seq[i].instance_state
7168
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
72-
std::cout << "Instance " << dummy.code << " has no writers\n";
69+
std::cout << "Instance " << dummy.code << " has no writers"
70+
<< std::endl;
7371
} else if (
7472
info_seq[i].instance_state
7573
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
76-
std::cout << "Instance " << dummy.code << " disposed\n";
74+
std::cout << "Instance " << dummy.code << " is disposed"
75+
<< std::endl;
76+
} else {
77+
std::cout << "Instance " << dummy.code << " is alive"
78+
<< std::endl;
7779
}
7880
}
7981
/* End changes for Keyed_Data */

examples/connext_dds/keyed_data/c/keys_subscriber.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,25 @@ void keysListener_on_data_available(void *listener_data, DDS_DataReader *reader)
148148
printf("Instance %d: x: %d, y: %d\n", data->code, data->x, data->y);
149149

150150
} else {
151-
/* Since there is not valid data, it may include metadata */
152-
keys dummy;
151+
/* An invalid data sample can be in any instance state. */
152+
keys key_value;
153153
retcode = keysDataReader_get_key_value(
154154
keys_reader,
155-
&dummy,
155+
&key_value,
156156
&info->instance_handle);
157157
if (retcode != DDS_RETCODE_OK) {
158158
printf("get_key_value error %d\n", retcode);
159159
continue;
160160
}
161-
162-
/* Here we print a message if the instance state is ALIVE_NO_WRITERS
163-
* or ALIVE_DISPOSED */
164161
if (info->instance_state
165162
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
166-
printf("Instance %d has no writers\n", dummy.code);
163+
printf("Instance %d has no writers\n", key_value.code);
167164
} else if (
168165
info->instance_state
169166
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
170-
printf("Instance %d disposed\n", dummy.code);
167+
printf("Instance %d is disposed\n", key_value.code);
168+
} else {
169+
printf("Instance %d is alive\n", key_value.code);
171170
}
172171
}
173172
/* End changes for Keyed_Data */

examples/connext_dds/keyed_data/java/keysPublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void runApplication()
105105
instance[2].code = 2;
106106

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

111111
// Modify the data to be sent here

examples/connext_dds/keyed_data/java/keysSubscriber.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ private int processData()
6767
"Instance " + sample.code + ": x: " + sample.x
6868
+ ", y: " + sample.y + "\n");
6969
} else {
70-
// Since there is not valid data, it may include metadata
7170
keys dummy = new keys();
7271
reader.get_key_value(dummy, info.instance_handle);
73-
74-
// Here we print a message if the instance state is
75-
// ALIVE_NO_WRITERS or ALIVE_DISPOSED
7672
if (info.instance_state
7773
== InstanceStateKind
7874
.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
@@ -83,7 +79,10 @@ private int processData()
8379
== InstanceStateKind
8480
.NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
8581
System.out.print(
86-
"Instance " + dummy.code + " disposed\n");
82+
"Instance " + dummy.code + " is disposed\n");
83+
} else {
84+
System.out.print(
85+
"Instance " + dummy.code + " is alive\n");
8786
}
8887
}
8988
samplesRead++;

0 commit comments

Comments
 (0)