[Bug293101] Context menu fix: removed the unimplemented menu choices and enabled...
[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 */
33public 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-";
8d2e2848 63 public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException {
d18dd09b 64
146a887c 65 if (! (eventStream instanceof TmfTraceStub)) {
d18dd09b
ASL
66 return null;
67 }
68
8d2e2848
FC
69 // Highly inefficient...
70 RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
71 String name = eventStream.getName();
72 name = name.substring(name.lastIndexOf('/') + 1);
73
74 synchronized(stream) {
75 long location = 0;
76 if (context != null)
77 location = (Long) (context.getLocation());
78 stream.seek(location);
79
80 try {
81 long ts = stream.readLong();
82 String source = stream.readUTF();
83 String type = stream.readUTF();
84 @SuppressWarnings("unused")
85 int reference = stream.readInt();
86 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
87 String[] fields = new String[typeIndex];
88 for (int i = 0; i < typeIndex; i++) {
89 fields[i] = stream.readUTF();
90 }
91
8d2e2848
FC
92 String content = "[";
93 if (typeIndex > 0) {
94 content += fields[0];
95 }
96 for (int i = 1; i < typeIndex; i++) {
97 content += ", " + fields[i];
98 }
99 content += "]";
100
101 TmfEvent event = new TmfEvent(
102 new TmfTimestamp(ts, (byte) -3, 0), // millisecs
103 new TmfEventSource(source),
28b94d61 104 fTypes[typeIndex],
8d2e2848 105 new TmfEventReference(name));
28b94d61
FC
106 TmfEventContent cnt = new TmfEventContent(event, content);
107 event.setContent(cnt);
108 return event;
8d2e2848
FC
109 } catch (EOFException e) {
110 }
d18dd09b
ASL
111 }
112 return null;
113 }
114
e31e01e8 115}
This page took 0.037057 seconds and 5 git commands to generate.