@@ -148,26 +148,29 @@ void keysListener_on_data_available(void *listener_data, DDS_DataReader *reader)
148
148
printf ("Instance %d: x: %d, y: %d\n" , data -> code , data -> x , data -> y );
149
149
150
150
} else {
151
- /* Since there is not valid data, it may include metadata */
152
- keys dummy ;
153
- retcode = keysDataReader_get_key_value (
154
- keys_reader ,
155
- & dummy ,
156
- & info -> instance_handle );
157
- if (retcode != DDS_RETCODE_OK ) {
158
- printf ("get_key_value error %d\n" , retcode );
159
- continue ;
160
- }
161
-
162
- /* Here we print a message if the instance state is ALIVE_NO_WRITERS
163
- * or ALIVE_DISPOSED */
164
- if (info -> instance_state
165
- == DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE ) {
166
- printf ("Instance %d has no writers\n" , dummy .code );
167
- } else if (
168
- info -> instance_state
169
- == DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE ) {
170
- printf ("Instance %d disposed\n" , dummy .code );
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
+ */
157
+ if (info -> instance_state == DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE ) {
158
+ printf ("Instance is in NOT_ALIVE_NO_WRITERS instance state\n" );
159
+ } else {
160
+ keys key_value ;
161
+ retcode = keysDataReader_get_key_value (
162
+ keys_reader ,
163
+ & key_value ,
164
+ & info -> instance_handle );
165
+ if (retcode != DDS_RETCODE_OK ) {
166
+ printf ("get_key_value error %d\n" , retcode );
167
+ continue ;
168
+ }
169
+ printf ("Instance %d is in %s instance state\n" ,
170
+ key_value .code ,
171
+ info -> instance_state == DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE
172
+ ? "NOT_ALIVE_DISPOSED"
173
+ : "ALIVE" );
171
174
}
172
175
}
173
176
/* End changes for Keyed_Data */
0 commit comments