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