General improvements:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / stubs / org / eclipse / linuxtools / lttng / stubs / LTTngEventParserStub.java
CommitLineData
8035003b
ASL
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
13package org.eclipse.linuxtools.lttng.stubs;
14
8b29a712 15import java.io.EOFException;
8035003b 16import java.io.IOException;
8b29a712
FC
17import java.io.RandomAccessFile;
18import java.util.Vector;
8035003b
ASL
19
20import org.eclipse.linuxtools.tmf.event.TmfEvent;
8b29a712
FC
21import org.eclipse.linuxtools.tmf.event.TmfEventContent;
22import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
23import org.eclipse.linuxtools.tmf.event.TmfEventReference;
24import org.eclipse.linuxtools.tmf.event.TmfEventSource;
25import org.eclipse.linuxtools.tmf.event.TmfEventType;
62d1696a
FC
26import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
27import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
8d2e2848 28import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
8035003b
ASL
29
30/**
31 * <b><u>TmfEventParserStub</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35public class LTTngEventParserStub implements ITmfEventParser {
36
8b29a712
FC
37 // ========================================================================
38 // Attributes
39 // ========================================================================
8035003b 40
8b29a712
FC
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-";
8d2e2848 72 public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException {
8b29a712 73
146a887c 74 if (! (eventStream instanceof LTTngTraceStub)) {
8b29a712
FC
75 return null;
76 }
77
8d2e2848
FC
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 long ts = stream.readLong();
91 String source = stream.readUTF();
92 String type = stream.readUTF();
93 @SuppressWarnings("unused")
94 int reference = stream.readInt();
95 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
96 String[] fields = new String[typeIndex];
97 for (int i = 0; i < typeIndex; i++) {
98 fields[i] = stream.readUTF();
99 }
100
101 // Update the context
102 context.setLocation(stream.getFilePointer());
103 context.incrIndex();
104
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 TmfEvent event = new TmfEvent(
115 new LTTngTimestampStub(ts),
116 new TmfEventSource(source),
117 new TmfEventType(type, fFormats[typeIndex]),
118 new TmfEventContent(content, fFormats[typeIndex]),
119 new TmfEventReference(name));
120 return event;
121 } catch (EOFException e) {
122 }
8b29a712
FC
123 }
124 return null;
125 }
8035003b
ASL
126
127}
This page took 0.04127 seconds and 5 git commands to generate.