RTI Connext RTSJ Extension Kit  Version 5.1.0
NodeStatusSeq.java

Node Status Sequence Example

Sequence code generation is exactly the same, regardless of whether you are using RTSJ. You may find the publishing and subscribing example code more interesting:

Source Code

/* NodeStatusSeq.java
*/
package com.rti.ndds.rtsj.example.nodestatus;
import java.util.Collection;
import com.rti.dds.infrastructure.Copyable;
import com.rti.dds.util.LoanableSequence;
import com.rti.dds.util.Sequence;
public final class NodeStatusSeq extends LoanableSequence implements Copyable {
// -----------------------------------------------------------------------
// Package Fields
// -----------------------------------------------------------------------
/*package*/ Sequence _loanedInfoSequence = null;
// -----------------------------------------------------------------------
// Public Fields
// -----------------------------------------------------------------------
// --- Constructors: -----------------------------------------------------
public NodeStatusSeq() {
super(NodeStatus.class);
}
public NodeStatusSeq(int initialMaximum) {
super(NodeStatus.class, initialMaximum);
}
public NodeStatusSeq(Collection elements) {
super(NodeStatus.class, elements);
}
// --- From Copyable: ----------------------------------------------------
public Object copy_from(Object src) {
Sequence typedSrc = (Sequence) src;
final int srcSize = typedSrc.size();
final int origSize = size();
// if this object's size is less than the source, ensure we have
// enough room to store all of the objects
if (getMaximum() < srcSize) {
setMaximum(srcSize);
}
// trying to avoid clear() method here since it allocates memory
// (an Iterator)
// if the source object has fewer items than the current object,
// remove from the end until the sizes are equal
if (srcSize < origSize){
removeRange(srcSize, origSize);
}
// copy the data from source into this (into positions that already
// existed)
for(int i = 0; (i < origSize) && (i < srcSize); i++){
if (typedSrc.get(i) == null){
set(i, null);
} else {
// check to see if our entry is null, if it is, a new instance has to be allocated
if (get(i) == null){
set(i, NodeStatus.create());
}
set(i, ((Copyable) get(i)).copy_from(typedSrc.get(i)));
}
}
// copy 'new' NodeStatus objects (beyond the original size of this object)
for(int i = origSize; i < srcSize; i++){
if (typedSrc.get(i) == null) {
add(null);
} else {
// NOTE: we need to create a new object here to hold the copy
add(NodeStatus.create());
// we need to do a set here since enums aren't truely Copyable
set(i, ((Copyable) get(i)).copy_from(typedSrc.get(i)));
}
}
return this;
}
}

RTI Connext RTSJ Extension Kit Version 5.1.0 Copyright © Tue Feb 4 2014 Real-Time Innovations, Inc