- Tweaked the FW a little to accommodate LTTng indexing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / stubs / org / eclipse / linuxtools / lttng / stubs / LTTngEventParserStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.stubs;
14
15 import java.io.EOFException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18 import java.util.Vector;
19
20 import org.eclipse.linuxtools.tmf.event.TmfEvent;
21 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
22 import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
23 import org.eclipse.linuxtools.tmf.event.TmfEventReference;
24 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
25 import org.eclipse.linuxtools.tmf.event.TmfEventType;
26 import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
27 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
28 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
29
30 /**
31 * <b><u>TmfEventParserStub</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 public class LTTngEventParserStub implements ITmfEventParser {
36
37 // ========================================================================
38 // Attributes
39 // ========================================================================
40
41 private final int NB_FORMATS = 10;
42 private final TmfEventFormat[] fFormats;
43
44 // ========================================================================
45 // Constructors
46 // ========================================================================
47
48 public LTTngEventParserStub() {
49 fFormats = new TmfEventFormat[NB_FORMATS];
50 for (int i = 0; i < NB_FORMATS; i++) {
51 Vector<String> format = new Vector<String>();
52 for (int j = 1; j <= i; j++) {
53 format.add(new String("Fmt-" + i + "-Fld-" + j));
54 }
55 String[] fields = new String[i];
56 fFormats[i] = new TmfEventFormat(format.toArray(fields));
57 }
58 }
59
60 // ========================================================================
61 // Accessors
62 // ========================================================================
63
64 // ========================================================================
65 // Operators
66 // ========================================================================
67
68 /* (non-Javadoc)
69 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
70 */
71 static final String typePrefix = "Type-";
72 public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException {
73
74 if (! (eventStream instanceof LTTngTraceStub)) {
75 return null;
76 }
77
78 // Highly inefficient...
79 RandomAccessFile stream = ((LTTngTraceStub) eventStream).getStream();
80 String name = eventStream.getName();
81 name = name.substring(name.lastIndexOf('/') + 1);
82
83 synchronized(stream) {
84 long location = 0;
85 if (context != null)
86 location = (Long) (context.getLocation());
87 stream.seek(location);
88
89 try {
90 // Read the individual fields
91 long ts = stream.readLong();
92 String source = stream.readUTF();
93 String type = stream.readUTF();
94 @SuppressWarnings("unused")
95 int reference = stream.readInt();
96
97 // Read the event parts
98 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
99 String[] fields = new String[typeIndex];
100 for (int i = 0; i < typeIndex; i++) {
101 fields[i] = stream.readUTF();
102 }
103
104 // Format the content from the individual fields
105 String content = "[";
106 if (typeIndex > 0) {
107 content += fields[0];
108 }
109 for (int i = 1; i < typeIndex; i++) {
110 content += ", " + fields[i];
111 }
112 content += "]";
113
114 // Update the context
115 context.setLocation(stream.getFilePointer());
116 context.incrIndex();
117 try {
118 long ts2 = stream.readLong();
119 context.setTimestamp(new LTTngTimestampStub(ts2));
120 } catch (EOFException e) {
121 context.setTimestamp(null);
122 }
123
124 // Create the event
125 TmfEvent event = new TmfEvent(
126 new LTTngTimestampStub(ts),
127 new TmfEventSource(source),
128 new TmfEventType(type, fFormats[typeIndex]),
129 new TmfEventContent(content, fFormats[typeIndex]),
130 new TmfEventReference(name));
131
132 return event;
133
134 } catch (EOFException e) {
135 context.setTimestamp(null);
136 }
137 }
138 return null;
139 }
140
141 }
This page took 0.034093 seconds and 5 git commands to generate.