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