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; | |
165c977c | 22 | import org.eclipse.linuxtools.tmf.event.TmfEventFormat; |
d18dd09b ASL |
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.event.TmfTimestamp; | |
165c977c FC |
27 | import org.eclipse.linuxtools.tmf.stream.ITmfEventParser; |
28 | import org.eclipse.linuxtools.tmf.stream.ITmfEventStream; | |
d18dd09b ASL |
29 | |
30 | /** | |
31 | * <b><u>TmfEventParserStub</u></b> | |
32 | * <p> | |
33 | * TODO: Implement me. Please. | |
34 | */ | |
35 | public class TmfEventParserStub implements ITmfEventParser { | |
36 | ||
165c977c | 37 | // ======================================================================== |
d18dd09b | 38 | // Attributes |
165c977c | 39 | // ======================================================================== |
d18dd09b | 40 | |
165c977c FC |
41 | private final int NB_FORMATS = 10; |
42 | private final TmfEventFormat[] fFormats; | |
d18dd09b | 43 | |
165c977c | 44 | // ======================================================================== |
d18dd09b | 45 | // Constructors |
165c977c | 46 | // ======================================================================== |
d18dd09b ASL |
47 | |
48 | public TmfEventParserStub() { | |
165c977c FC |
49 | fFormats = new TmfEventFormat[NB_FORMATS]; |
50 | for (int i = 0; i < NB_FORMATS; i++) { | |
d18dd09b ASL |
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]; | |
165c977c | 56 | fFormats[i] = new TmfEventFormat(format.toArray(fields)); |
d18dd09b ASL |
57 | } |
58 | } | |
59 | ||
165c977c | 60 | // ======================================================================== |
d18dd09b | 61 | // Operators |
165c977c | 62 | // ======================================================================== |
d18dd09b | 63 | |
165c977c FC |
64 | /* (non-Javadoc) |
65 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent() | |
66 | */ | |
d18dd09b | 67 | static final String typePrefix = "Type-"; |
165c977c | 68 | public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException { |
d18dd09b | 69 | |
165c977c | 70 | if (! (eventStream instanceof TmfEventStreamStub)) { |
d18dd09b ASL |
71 | return null; |
72 | } | |
73 | ||
165c977c FC |
74 | RandomAccessFile stream = ((TmfEventStreamStub) eventStream).getStream(); |
75 | ||
76 | try { | |
77 | long ts = stream.readLong(); | |
78 | String source = stream.readUTF(); | |
79 | String type = stream.readUTF(); | |
80 | int reference = stream.readInt(); | |
81 | int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); | |
82 | String[] fields = new String[typeIndex]; | |
83 | for (int i = 0; i < typeIndex; i++) { | |
84 | fields[i] = stream.readUTF(); | |
85 | } | |
86 | String content = "["; | |
87 | for (int i = 0; i < typeIndex - 1; i++) { | |
88 | content += fields[i] + ", "; | |
89 | } | |
90 | content += "]"; | |
91 | ||
92 | TmfEvent event = new TmfEvent( | |
93 | new TmfTimestamp(ts, (byte) -3, 0), // millisecs | |
94 | new TmfEventSource(source), | |
95 | new TmfEventType(type, fFormats[typeIndex]), | |
96 | new TmfEventContent(content, fFormats[typeIndex]), | |
97 | new TmfEventReference(reference)); | |
98 | return event; | |
99 | } catch (EOFException e) { | |
d18dd09b ASL |
100 | } |
101 | return null; | |
102 | } | |
103 | ||
165c977c | 104 | } |