}
}
- /* Read stream ID */
- // TODO: it hasn't been checked that the stream_id field exists and
- // is an unsigned
- // integer
- IntegerDefinition streamIDDef = (IntegerDefinition) packetHeaderDef
- .lookupDefinition("stream_id"); //$NON-NLS-1$
- assert (streamIDDef != null);
-
- long streamID = streamIDDef.getValue();
-
- /* Get the stream to which this trace file belongs to */
- stream = streams.get(streamID);
+ /* Read the stream ID */
+ Definition streamIDDef = packetHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
+
+ if (streamIDDef instanceof IntegerDefinition) { //this doubles as a null check
+ long streamID = ((IntegerDefinition) streamIDDef).getValue();
+ stream = streams.get(streamID);
+ } else {
+ /* No stream_id in the packet header */
+ stream = streams.get(null);
+ }
+
} else {
/* No packet header, we suppose there is only one stream */
stream = streams.get(null);
* If there was a problem reading the trace
*/
public EventDefinition readNextEvent() throws CTFReaderException {
- /* WARNING: This is still LTTng-specific. */
- Long eventID = null;
+ /* Default values for those fields */
+ long eventID = 0;
long timestamp = 0;
if (lostEventsInThisPacket > lostSoFar) {
- EventDefinition eventDef = EventDeclaration
- .getLostEventDeclaration().createDefinition(
- streamInputReader);
+ EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition(
+ streamInputReader);
eventDef.setTimestamp(this.lastTimestamp);
++lostSoFar;
return eventDef;
}
- StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long
- // variable name
- BitBuffer currentBitBuffer = getBitBuffer();
- /*
- * Read the stream event header.
- */
+ final StructDefinition sehd = getStreamEventHeaderDef();
+ final BitBuffer currentBitBuffer = getBitBuffer();
+ /* Read the stream event header. */
if (sehd != null) {
sehd.read(currentBitBuffer);
- /*
- * Check for an event id.
- */
- SimpleDatatypeDefinition idDef = (SimpleDatatypeDefinition) sehd
- .lookupDefinition("id"); //$NON-NLS-1$
- IntegerDefinition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$
- eventID = idDef.getIntegerValue();
+ /* Check for the event id. */
+ Definition idDef = sehd.lookupDefinition("id"); //$NON-NLS-1$
+ if (idDef instanceof SimpleDatatypeDefinition) {
+ eventID = ((SimpleDatatypeDefinition) idDef).getIntegerValue();
+ } // else, eventID remains 0
- /*
- * Check for the variant v.
- */
- VariantDefinition variantDef = (VariantDefinition) sehd
- .lookupDefinition("v"); //$NON-NLS-1$
+ /* Get the timestamp from the event header (may be overridden later on) */
+ Definition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$
+
+ /* Check for the variant v. */
+ VariantDefinition variantDef = (VariantDefinition) sehd.lookupDefinition("v"); //$NON-NLS-1$
if (variantDef != null) {
- /*
- * Get the variant current field
- */
- StructDefinition variantCurrentField = (StructDefinition) variantDef
- .getCurrentField();
+ /* Get the variant current field */
+ StructDefinition variantCurrentField = (StructDefinition) variantDef.getCurrentField();
/*
* Try to get the id field in the current field of the variant.
* If it is present, it overrides the previously read event id.
*/
- IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
- .lookupDefinition("id"); //$NON-NLS-1$
+ IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
if (idIntegerDef != null) {
eventID = idIntegerDef.getValue();
}
- /*
- * Get the timestamp.
- */
- timestampDef = (IntegerDefinition) variantCurrentField
- .lookupDefinition("timestamp"); //$NON-NLS-1$
+ /* Get the timestamp. */
+ timestampDef = variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$
}
- /*
- * Calculate the event timestamp.
- */
- timestamp = calculateTimestamp(timestampDef);
+ /* Calculate the event timestamp. */
+ if (timestampDef instanceof IntegerDefinition) {
+ timestamp = calculateTimestamp((IntegerDefinition) timestampDef);
+ } // else timestamp remains 0
}
- /*
- * Read the stream event context.
- */
- if (getStreamEventContextDef() != null) {
- getStreamEventContextDef().read(currentBitBuffer);
+ /* Read the stream event context. */
+ if (streamEventContextDef != null) {
+ streamEventContextDef.read(currentBitBuffer);
}
- /*
- * Get the right event definition using the event id.
- */
+ /* Get the right event definition using the event id. */
EventDefinition eventDef = events.get(eventID);
if (eventDef == null) {
throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
}
- /*
- * Read the event context.
- */
+ /* Read the event context. */
if (eventDef.getContext() != null) {
eventDef.getContext().read(currentBitBuffer);
}
- /*
- * Read the event fields.
- */
+ /* Read the event fields. */
if (eventDef.getFields() != null) {
eventDef.getFields().read(currentBitBuffer);
}