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