Skip to content

Commit e2a1cbf

Browse files
author
Sam Raeburn
committed
CORE-13335: PR feedback
1 parent 2a6219a commit e2a1cbf

File tree

4 files changed

+54
-67
lines changed

4 files changed

+54
-67
lines changed

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

+8-12
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,20 @@ int process_data(dds::sub::DataReader<keys> reader)
3535
<< ", x: " << sample.data().x()
3636
<< ", y: " << sample.data().y() << std::endl;
3737
} else {
38-
// A sample without valid data can be in any instance state, but the
39-
// key value is only available if it is ALIVE or NOT_ALIVE_DISPOSED
38+
keys sample;
39+
reader.key_value(sample, info.instance_handle());
4040
const dds::sub::status::InstanceState &state =
4141
info.state().instance_state();
4242
if (state
4343
== dds::sub::status::InstanceState::not_alive_no_writers()) {
44-
std::cout
45-
<< "Instance is in NOT_ALIVE_NO_WRITERS instance state"
44+
std::cout << "Instance " << sample.code() << " has no writers"
4645
<< std::endl;
46+
} else if (state
47+
== dds::sub::status::InstanceState::not_alive_disposed()) {
48+
std::cout << "Instance " << sample.code() << " is disposed"
49+
<< std::endl;
4750
} else {
48-
// Since there is not valid data, it may include metadata.
49-
keys sample;
50-
reader.key_value(sample, info.instance_handle());
51-
std::cout << "Instance " << sample.code() << " is "
52-
<< ((state
53-
== dds::sub::status::InstanceState::alive())
54-
? "alive"
55-
: "disposed")
51+
std::cout << "Instance " << sample.code() << " is alive"
5652
<< std::endl;
5753
}
5854
}

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

+20-19
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,29 @@ unsigned int process_data(keysDataReader *typed_reader)
5555

5656
samples_read++;
5757
} else {
58-
/*
59-
* An invalid sample can be in any instance state. The key value is
60-
* only available if it is ALIVE or NOT_ALIVE_DISPOSED.
61-
*/
58+
/* An invalid sample can be in any instance state. */
59+
keys dummy;
60+
retcode = typed_reader->get_key_value(
61+
dummy,
62+
info_seq[i].instance_handle);
63+
if (retcode != DDS_RETCODE_OK) {
64+
std::cout << "get_key_value error " << retcode << std::endl;
65+
continue;
66+
}
6267
if (info_seq[i].instance_state
6368
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
64-
std::cout << "Instance has no writers" << std::endl;
69+
std::cout
70+
<< "Instance " << dummy.code << " has no writers"
71+
<< std::endl;
72+
} else if (info_seq[i].instance_state
73+
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
74+
std::cout
75+
<< "Instance " << dummy.code << " is disposed"
76+
<< std::endl;
6577
} else {
66-
keys dummy;
67-
retcode = typed_reader->get_key_value(
68-
dummy,
69-
info_seq[i].instance_handle);
70-
if (retcode != DDS_RETCODE_OK) {
71-
std::cout << "get_key_value error " << retcode << std::endl;
72-
continue;
73-
}
74-
std::cout << "Instance " << dummy.code << " is "
75-
<< ((info_seq[i].instance_state
76-
== DDS_ALIVE_INSTANCE_STATE)
77-
? "alive"
78-
: "disposed")
79-
<< std::endl;
78+
std::cout
79+
<< "Instance " << dummy.code << " is alive"
80+
<< std::endl;
8081
}
8182
}
8283
/* End changes for Keyed_Data */

examples/connext_dds/keyed_data/c/keys_subscriber.c

+15-21
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,24 @@ 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-
printf("No valid data for sample\n");
152-
/*
153-
* An invalid data sample can be in any instance state. The key
154-
* value may be available if the instance is either ALIVE or
155-
* NOT_ALIVE_DISPOSED.
156-
*/
151+
/* An invalid data sample can be in any instance state. */
152+
keys key_value;
153+
retcode = keysDataReader_get_key_value(
154+
keys_reader,
155+
&key_value,
156+
&info->instance_handle);
157+
if (retcode != DDS_RETCODE_OK) {
158+
printf("get_key_value error %d\n", retcode);
159+
continue;
160+
}
157161
if (info->instance_state
158162
== DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
159-
printf("Instance is in NOT_ALIVE_NO_WRITERS instance state\n");
163+
printf("Instance %d has no writers\n", key_value.code);
164+
} else if (info->instance_state
165+
== DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
166+
printf("Instance %d is disposed\n", key_value.code);
160167
} else {
161-
keys key_value;
162-
retcode = keysDataReader_get_key_value(
163-
keys_reader,
164-
&key_value,
165-
&info->instance_handle);
166-
if (retcode != DDS_RETCODE_OK) {
167-
printf("get_key_value error %d\n", retcode);
168-
continue;
169-
}
170-
printf("Instance %d is in %s instance state\n",
171-
key_value.code,
172-
((info->instance_state == DDS_ALIVE_INSTANCE_STATE)
173-
? "ALIVE"
174-
: "NOT_ALIVE_DISPOSED"));
168+
printf("Instance %d is alive\n", key_value.code);
175169
}
176170
}
177171
/* End changes for Keyed_Data */

examples/connext_dds/keyed_data/java/keysSubscriber.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,21 @@ private int processData()
6767
"Instance " + sample.code + ": x: " + sample.x
6868
+ ", y: " + sample.y + "\n");
6969
} else {
70+
keys dummy = new keys();
71+
reader.get_key_value(dummy, info.instance_handle);
7072
if (info.instance_state
7173
== InstanceStateKind
7274
.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) {
73-
System.out.print("Instance has no writers\n");
75+
System.out.print(
76+
"Instance " + dummy.code + " has no writers\n");
77+
} else if (info.instance_state
78+
== InstanceStateKind
79+
.NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
80+
System.out.print(
81+
"Instance " + dummy.code + " is disposed\n");
7482
} else {
75-
keys dummy = new keys();
76-
reader.get_key_value(dummy, info.instance_handle);
77-
if (info.instance_state
78-
== InstanceStateKind.ALIVE_INSTANCE_STATE) {
79-
System.out.print(
80-
"Instance " + dummy.code + " is ALIVE\n");
81-
} else if (
82-
info.instance_state
83-
== InstanceStateKind
84-
.NOT_ALIVE_DISPOSED_INSTANCE_STATE) {
85-
System.out.print(
86-
"Instance " + dummy.code
87-
+ " is disposed\n");
88-
}
83+
System.out.print(
84+
"Instance " + dummy.code + " is alive\n");
8985
}
9086
}
9187
samplesRead++;

0 commit comments

Comments
 (0)