-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccidentTypeSupport.java
547 lines (425 loc) · 17.4 KB
/
AccidentTypeSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/*
WARNING: THIS FILE IS AUTO-GENERATED. DO NOT MODIFY.
This file was generated from .idl using "rtiddsgen".
The rtiddsgen tool is part of the RTI Connext distribution.
For more information, type 'rtiddsgen -help' at a command shell
or consult the RTI Connext manual.
*/
import com.rti.dds.cdr.CdrEncapsulation;
import com.rti.dds.cdr.CdrInputStream;
import com.rti.dds.cdr.CdrOutputStream;
import com.rti.dds.cdr.CdrPrimitiveType;
import com.rti.dds.cdr.CdrBuffer;
import com.rti.dds.cdr.CdrHelper;
import com.rti.dds.cdr.CdrMemberInfo;
import com.rti.dds.domain.DomainParticipant;
import com.rti.dds.publication.DataWriter;
import com.rti.dds.publication.DataWriterListener;
import com.rti.dds.subscription.DataReader;
import com.rti.dds.subscription.DataReaderListener;
import com.rti.dds.topic.KeyHash_t;
import com.rti.dds.topic.TypeSupportImpl;
import com.rti.dds.topic.TypeSupportType;
import com.rti.dds.util.Sequence;
import com.rti.dds.topic.DefaultEndpointData;
import com.rti.dds.topic.SampleAssignabilityProperty;
import com.rti.dds.infrastructure.RETCODE_ERROR;
import com.rti.dds.infrastructure.*;
import com.rti.dds.topic.TypeSupportParticipantInfo;
import com.rti.dds.topic.TypeSupportEndpointInfo;
import com.rti.dds.topic.PrintFormatProperty;
import com.rti.dds.typecode.TypeCode;
import com.rti.dds.cdr.IllegalCdrStateException;
import com.rti.dds.infrastructure.Copyable;
/**
* A collection of useful methods for dealing with objects of type
* Accident
*/
public class AccidentTypeSupport extends TypeSupportImpl {
// -----------------------------------------------------------------------
// Private Fields
// -----------------------------------------------------------------------
private static final String TYPE_NAME = "Accident";
private static final char[] PLUGIN_VERSION = {2, 0, 0, 0};
private static final AccidentTypeSupport _singleton
= new AccidentTypeSupport();
// -----------------------------------------------------------------------
// Public Methods
// -----------------------------------------------------------------------
// --- External methods: -------------------------------------------------
/* The methods in this section are for use by users of RTI Connext
*/
public static String get_type_name() {
return _singleton.get_type_nameI();
}
public static void register_type(DomainParticipant participant,
String type_name) {
_singleton.register_typeI(participant, type_name);
}
public static void unregister_type(DomainParticipant participant,
String type_name) {
_singleton.unregister_typeI(participant, type_name);
}
/* The methods in this section are for use by RTI Connext
* itself and by the code generated by rtiddsgen for other types.
* They should be used directly or modified only by advanced users and are
* subject to change in future versions of RTI Connext.
*/
public static AccidentTypeSupport get_instance() {
return _singleton;
}
public static AccidentTypeSupport getInstance() {
return get_instance();
}
public static TypeCode getTypeCode(){
return AccidentTypeCode.VALUE;
}
public Object create_data() {
return Accident.create();
}
public void destroy_data(Object data) {
return;
}
public Object create_key() {
return new Accident();
}
public void destroy_key(Object key) {
return;
}
public Class get_type() {
return Accident.class;
}
/**
* This is a concrete implementation of this method inherited from the base class.
* This method will perform a deep copy of <code>source</code> into
* <code>destination</code>.
*
* @param src The Object which contains the data to be copied.
* @return Returns <code>destination</code>.
* @exception NullPointerException If <code>destination</code> or
* <code>source</code> is null.
* @exception ClassCastException If either <code>destination</code> or
* <code>this</code> is not a <code>Accident</code>
* type.
*/
public Object copy_data(Object destination, Object source) {
Accident typedDst = (Accident) destination;
Accident typedSrc = (Accident) source;
return typedDst.copy_from(typedSrc);
}
public long get_serialized_sample_max_size(Object endpoint_data,boolean include_encapsulation,short encapsulation_id,long currentAlignment) {
long origAlignment = currentAlignment;
long encapsulation_size = currentAlignment;
if(include_encapsulation) {
if (!CdrEncapsulation.isValidEncapsulationKind(encapsulation_id)) {
throw new RETCODE_ERROR("Unsupported encapsulation");
}
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size -= currentAlignment;
currentAlignment = 0;
origAlignment = 0;
}
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, (255)+1);
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, (255)+1);
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, (255)+1);
currentAlignment += CdrPrimitiveType.INT.getMaxSizeSerialized(currentAlignment );
if (include_encapsulation) {
currentAlignment += encapsulation_size;
}
return currentAlignment - origAlignment;
}
public long get_serialized_sample_min_size(Object endpoint_data,boolean include_encapsulation,short encapsulation_id,long currentAlignment) {
long origAlignment = currentAlignment;
long encapsulation_size = currentAlignment;
if(include_encapsulation) {
if (!CdrEncapsulation.isValidEncapsulationKind(encapsulation_id)) {
throw new RETCODE_ERROR("Unsupported encapsulation");
}
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size -= currentAlignment;
currentAlignment = 0;
origAlignment = 0;
}
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, 1);
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, 1);
currentAlignment += CdrPrimitiveType.getStringMaxSizeSerialized(currentAlignment, 1);
currentAlignment += CdrPrimitiveType.INT.getMaxSizeSerialized(currentAlignment );
if (include_encapsulation) {
currentAlignment += encapsulation_size;
}
return currentAlignment - origAlignment;
}
public long get_serialized_sample_size(
Object endpoint_data, boolean include_encapsulation,
short encapsulation_id, long currentAlignment,
Object sample)
{
Accident typedSrc = (Accident) sample;
DefaultEndpointData epd = ((DefaultEndpointData) endpoint_data) ;
long origAlignment = currentAlignment;
long encapsulation_size = currentAlignment;
if(include_encapsulation) {
if (!CdrEncapsulation.isValidEncapsulationKind(encapsulation_id)) {
throw new RETCODE_ERROR("Unsupported encapsulation");
}
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size -= currentAlignment;
currentAlignment = 0;
origAlignment = 0;
epd.setBaseAlignment(currentAlignment);
}
currentAlignment += CdrPrimitiveType.getStringSerializedSize(epd.getAlignment(currentAlignment), typedSrc.timestamp );
currentAlignment += CdrPrimitiveType.getStringSerializedSize(epd.getAlignment(currentAlignment), typedSrc.route );
currentAlignment += CdrPrimitiveType.getStringSerializedSize(epd.getAlignment(currentAlignment), typedSrc.vehicle );
currentAlignment += CdrPrimitiveType.INT.getMaxSizeSerialized(epd.getAlignment(currentAlignment));
if (include_encapsulation) {
currentAlignment += encapsulation_size;
}
return currentAlignment - origAlignment;
}
public long get_serialized_key_max_size(
Object endpoint_data,
boolean include_encapsulation,
short encapsulation_id,
long currentAlignment)
{
long origAlignment = currentAlignment;
long encapsulation_size = currentAlignment;
if(include_encapsulation) {
if (!CdrEncapsulation.isValidEncapsulationKind(encapsulation_id)) {
throw new RETCODE_ERROR("Unsupported encapsulation");
}
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size += CdrPrimitiveType.SHORT.getMaxSizeSerialized(encapsulation_size);
encapsulation_size -= currentAlignment;
currentAlignment = 0;
origAlignment = 0;
}
currentAlignment += get_serialized_sample_max_size(
endpoint_data,false,encapsulation_id,currentAlignment);
if (include_encapsulation) {
currentAlignment += encapsulation_size;
}
return currentAlignment - origAlignment;
}
public void serialize(Object endpoint_data,Object src, CdrOutputStream dst,boolean serialize_encapsulation,
short encapsulation_id, boolean serialize_sample, Object endpoint_plugin_qos) {
int position = 0;
if(serialize_encapsulation) {
dst.serializeAndSetCdrEncapsulation(encapsulation_id);
position = dst.resetAlignment();
}
if(serialize_sample) {
Accident typedSrc = (Accident) src;
dst.writeString(typedSrc.timestamp,255);
dst.writeString(typedSrc.route,255);
dst.writeString(typedSrc.vehicle,255);
dst.writeInt(typedSrc.stopNumber);
}
if (serialize_encapsulation) {
dst.restoreAlignment(position);
}
}
public long serialize_to_cdr_buffer(
byte[] buffer,
long length,
Accident src)
{
return super.serialize_to_cdr_buffer(buffer,length,src);
}
public void serialize_key(
Object endpoint_data,
Object src,
CdrOutputStream dst,
boolean serialize_encapsulation,
short encapsulation_id,
boolean serialize_key,
Object endpoint_plugin_qos)
{
int position = 0;
if (serialize_encapsulation) {
dst.serializeAndSetCdrEncapsulation(encapsulation_id);
position = dst.resetAlignment();
}
if (serialize_key) {
Accident typedSrc = (Accident) src;
serialize(endpoint_data, src, dst, false, CdrEncapsulation.CDR_ENCAPSULATION_ID_CDR_BE, true, endpoint_plugin_qos);
}
if (serialize_encapsulation) {
dst.restoreAlignment(position);
}
}
public Object deserialize_sample(
Object endpoint_data,
Object dst,
CdrInputStream src, boolean deserialize_encapsulation,
boolean deserialize_sample,
Object endpoint_plugin_qos)
{
int position = 0;
if(deserialize_encapsulation) {
src.deserializeAndSetCdrEncapsulation();
position = src.resetAlignment();
}
if(deserialize_sample) {
Accident typedDst = (Accident) dst;
typedDst.clear();
try{
typedDst.timestamp = src.readString(255);
typedDst.route = src.readString(255);
typedDst.vehicle = src.readString(255);
typedDst.stopNumber = src.readInt();
} catch (IllegalCdrStateException stateEx) {
if (src.available() >= CdrEncapsulation.CDR_ENCAPSULATION_PARAMETER_ID_ALIGNMENT) {
throw new RETCODE_ERROR("Error deserializing sample! Remainder: " + src.available() + "\n" +
"Exception caused by: " + stateEx.getMessage());
}
} catch (Exception ex) {
throw new RETCODE_ERROR(ex.getMessage());
}
}
if (deserialize_encapsulation) {
src.restoreAlignment(position);
}
return dst;
}
public void deserialize_from_cdr_buffer(
Accident dst,
byte[] buffer,
long length)
{
super.deserialize_from_cdr_buffer(dst,buffer,length);
}
public String data_to_string(
Accident sample,
PrintFormatProperty property)
{
return super.data_to_string(sample, property);
}
public String data_to_string(
Accident sample)
{
return super.data_to_string(sample);
}
public Object deserialize_key_sample(
Object endpoint_data,
Object dst,
CdrInputStream src,
boolean deserialize_encapsulation,
boolean deserialize_key,
Object endpoint_plugin_qos)
{
int position = 0;
if(deserialize_encapsulation) {
src.deserializeAndSetCdrEncapsulation();
position = src.resetAlignment();
}
if(deserialize_key) {
Accident typedDst = (Accident) dst;
deserialize_sample(endpoint_data, dst, src, false, true, endpoint_plugin_qos);
}
if (deserialize_encapsulation) {
src.restoreAlignment(position);
}
return dst;
}
public void skip(Object endpoint_data,
CdrInputStream src,
boolean skip_encapsulation,
boolean skip_sample,
Object endpoint_plugin_qos)
{
int position = 0;
if (skip_encapsulation) {
src.skipEncapsulation();
position = src.resetAlignment();
}
if (skip_sample) {
src.skipString();
src.skipString();
src.skipString();
src.skipInt();
}
if (skip_encapsulation) {
src.restoreAlignment(position);
}
}
public Object serialized_sample_to_key(
Object endpoint_data,
Object sample,
CdrInputStream src,
boolean deserialize_encapsulation,
boolean deserialize_key,
Object endpoint_plugin_qos)
{
int position = 0;
if(deserialize_encapsulation) {
src.deserializeAndSetCdrEncapsulation();
position = src.resetAlignment();
}
if (deserialize_key) {
Accident typedDst = (Accident) sample;
deserialize_sample(
endpoint_data, sample, src, false,
true, endpoint_plugin_qos);
}
if (deserialize_encapsulation) {
src.restoreAlignment(position);
}
return sample;
}
// -----------------------------------------------------------------------
// Callbacks
// -----------------------------------------------------------------------
public Object on_participant_attached(Object registration_data,
TypeSupportParticipantInfo participant_info,
boolean top_level_registration,
Object container_plugin_context,
TypeCode type_code) {
return super.on_participant_attached(
registration_data, participant_info, top_level_registration,
container_plugin_context, type_code);
}
public void on_participant_detached(Object participant_data) {
super.on_participant_detached(participant_data);
}
public Object on_endpoint_attached(Object participantData,
TypeSupportEndpointInfo endpoint_info,
boolean top_level_registration,
Object container_plugin_context) {
return super.on_endpoint_attached(
participantData, endpoint_info,
top_level_registration, container_plugin_context);
}
public void on_endpoint_detached(Object endpoint_data) {
super.on_endpoint_detached(endpoint_data);
}
// -----------------------------------------------------------------------
// Protected Methods
// -----------------------------------------------------------------------
protected DataWriter create_datawriter(long native_writer,
DataWriterListener listener,
int mask) {
return new AccidentDataWriter (native_writer, listener, mask, this);
}
protected DataReader create_datareader(long native_reader,
DataReaderListener listener,
int mask) {
return new AccidentDataReader(native_reader, listener, mask, this);
}
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
protected AccidentTypeSupport() {
/* If the user data type supports keys, then the second argument
to the constructor below should be true. Otherwise it should
be false. */
super(TYPE_NAME, false,AccidentTypeCode.VALUE,Accident.class,TypeSupportType.TST_STRUCT, PLUGIN_VERSION);
}
protected AccidentTypeSupport (boolean enableKeySupport) {
super(TYPE_NAME, enableKeySupport,AccidentTypeCode.VALUE,Accident.class,TypeSupportType.TST_STRUCT, PLUGIN_VERSION);
}
}