Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfEventParserStub.java
CommitLineData
d18dd09b
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 - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.trace;
14
15import java.io.EOFException;
16import java.io.IOException;
17import java.io.RandomAccessFile;
18import java.util.Vector;
19
20import org.eclipse.linuxtools.tmf.event.TmfEvent;
21import org.eclipse.linuxtools.tmf.event.TmfEventContent;
22import org.eclipse.linuxtools.tmf.event.TmfEventReference;
23import org.eclipse.linuxtools.tmf.event.TmfEventSource;
24import org.eclipse.linuxtools.tmf.event.TmfEventType;
25import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
e31e01e8 26import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
d18dd09b
ASL
27
28/**
29 * <b><u>TmfEventParserStub</u></b>
30 * <p>
31 * TODO: Implement me. Please.
32 */
3b38ea61 33@SuppressWarnings("nls")
d18dd09b
ASL
34public class TmfEventParserStub implements ITmfEventParser {
35
e31e01e8 36 // ------------------------------------------------------------------------
d18dd09b 37 // Attributes
e31e01e8 38 // ------------------------------------------------------------------------
d18dd09b 39
28b94d61
FC
40 private final int NB_TYPES = 10;
41 private final TmfEventType[] fTypes;
d18dd09b 42
e31e01e8 43 // ------------------------------------------------------------------------
d18dd09b 44 // Constructors
e31e01e8 45 // ------------------------------------------------------------------------
d18dd09b
ASL
46
47 public TmfEventParserStub() {
28b94d61
FC
48 fTypes = new TmfEventType[NB_TYPES];
49 for (int i = 0; i < NB_TYPES; i++) {
d18dd09b
ASL
50 Vector<String> format = new Vector<String>();
51 for (int j = 1; j <= i; j++) {
52 format.add(new String("Fmt-" + i + "-Fld-" + j));
53 }
54 String[] fields = new String[i];
28b94d61 55 fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
d18dd09b
ASL
56 }
57 }
58
e31e01e8 59 // ------------------------------------------------------------------------
d18dd09b 60 // Operators
e31e01e8 61 // ------------------------------------------------------------------------
d18dd09b
ASL
62
63 static final String typePrefix = "Type-";
d4011df2
FC
64 @Override
65 @SuppressWarnings("unchecked")
9f584e4c 66 public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
d18dd09b 67
146a887c 68 if (! (eventStream instanceof TmfTraceStub)) {
d18dd09b
ASL
69 return null;
70 }
71
8d2e2848
FC
72 // Highly inefficient...
73 RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
74 String name = eventStream.getName();
75 name = name.substring(name.lastIndexOf('/') + 1);
76
73005152
BH
77 // no need to use synchronized since it's already cover by the calling method
78
79 long location = 0;
80 if (context != null)
81 location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
82 stream.seek(location);
83
84 try {
85 long ts = stream.readLong();
86 String source = stream.readUTF();
87 String type = stream.readUTF();
88 @SuppressWarnings("unused")
89 int reference = stream.readInt();
90 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
91 String[] fields = new String[typeIndex];
92 for (int i = 0; i < typeIndex; i++) {
93 fields[i] = stream.readUTF();
94 }
95
96 String content = "[";
97 if (typeIndex > 0) {
98 content += fields[0];
99 }
100 for (int i = 1; i < typeIndex; i++) {
101 content += ", " + fields[i];
102 }
103 content += "]";
104
105 TmfEvent event = new TmfEvent(
106 new TmfTimestamp(ts, (byte) -3, 0), // millisecs
107 new TmfEventSource(source),
108 fTypes[typeIndex],
109 new TmfEventReference(name));
110 TmfEventContent cnt = new TmfEventContent(event, content);
111 event.setContent(cnt);
112 return event;
113 } catch (EOFException e) {
114 }
d18dd09b
ASL
115 return null;
116 }
117
e31e01e8 118}
This page took 0.035417 seconds and 5 git commands to generate.