bc49915795ab7ad5213cb89685c8ea07f5d972fd
[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 import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
28 import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
29
30 /**
31 * <b><u>TmfEventParserStub</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 public class TmfEventParserStub implements ITmfEventParser {
36
37 // ========================================================================
38 // Attributes
39 // ========================================================================
40
41 private final int NB_FORMATS = 10;
42 private final TmfEventFormat[] fFormats;
43
44 // ========================================================================
45 // Constructors
46 // ========================================================================
47
48 public TmfEventParserStub() {
49 fFormats = new TmfEventFormat[NB_FORMATS];
50 for (int i = 0; i < NB_FORMATS; i++) {
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];
56 fFormats[i] = new TmfEventFormat(format.toArray(fields));
57 }
58 }
59
60 // ========================================================================
61 // Operators
62 // ========================================================================
63
64 /* (non-Javadoc)
65 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
66 */
67 static final String typePrefix = "Type-";
68 public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException {
69
70 if (! (eventStream instanceof TmfEventStreamStub)) {
71 return null;
72 }
73
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) {
100 }
101 return null;
102 }
103
104 }
This page took 0.033761 seconds and 4 git commands to generate.