Internalize some CTF APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / stubs / 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
6c13869b 13package org.eclipse.linuxtools.tmf.stubs.trace;
d18dd09b
ASL
14
15import java.io.EOFException;
16import java.io.IOException;
17import java.io.RandomAccessFile;
18import java.util.Vector;
19
72f1e62a 20import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
4c564a2d 21import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
6c13869b 22import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
4c564a2d 23import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
6c13869b
FC
24import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
25import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
26import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser;
a1440d1f 27import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6c13869b 28import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
6c13869b 29import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
d18dd09b
ASL
30
31/**
32 * <b><u>TmfEventParserStub</u></b>
33 * <p>
34 * TODO: Implement me. Please.
35 */
3b38ea61 36@SuppressWarnings("nls")
72f1e62a 37public class TmfEventParserStub implements ITmfEventParser<TmfEvent> {
d18dd09b 38
e31e01e8 39 // ------------------------------------------------------------------------
d18dd09b 40 // Attributes
e31e01e8 41 // ------------------------------------------------------------------------
d18dd09b 42
6e85c58d 43 private static final int NB_TYPES = 10;
28b94d61 44 private final TmfEventType[] fTypes;
d18dd09b 45
e31e01e8 46 // ------------------------------------------------------------------------
d18dd09b 47 // Constructors
e31e01e8 48 // ------------------------------------------------------------------------
d18dd09b
ASL
49
50 public TmfEventParserStub() {
28b94d61
FC
51 fTypes = new TmfEventType[NB_TYPES];
52 for (int i = 0; i < NB_TYPES; i++) {
cbbcc354 53 Vector<String> fields = new Vector<String>();
d18dd09b 54 for (int j = 1; j <= i; j++) {
cbbcc354 55 String field = "Fmt-" + i + "-Fld-" + j;
56 fields.add(field);
d18dd09b 57 }
cbbcc354 58 String[] fieldArray = new String[i];
4c564a2d
FC
59 ITmfEventField rootField = TmfEventField.makeRoot(fields.toArray(fieldArray));
60 fTypes[i] = new TmfEventType("UnitTest", "Type-" + i, rootField);
d18dd09b
ASL
61 }
62 }
63
e31e01e8 64 // ------------------------------------------------------------------------
d18dd09b 65 // Operators
e31e01e8 66 // ------------------------------------------------------------------------
d18dd09b
ASL
67
68 static final String typePrefix = "Type-";
d4011df2
FC
69 @Override
70 @SuppressWarnings("unchecked")
a1440d1f 71 public ITmfEvent parseNextEvent(ITmfTrace<TmfEvent> eventStream, ITmfContext context) throws IOException {
d18dd09b 72
146a887c 73 if (! (eventStream instanceof TmfTraceStub)) {
d18dd09b
ASL
74 return null;
75 }
76
8d2e2848
FC
77 // Highly inefficient...
78 RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
6e85c58d
FC
79// String name = eventStream.getName();
80// name = name.substring(name.lastIndexOf('/') + 1);
8d2e2848 81
73005152
BH
82 // no need to use synchronized since it's already cover by the calling method
83
84 long location = 0;
85 if (context != null)
86 location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
87 stream.seek(location);
88
89 try {
90 long ts = stream.readLong();
91 String source = stream.readUTF();
92 String type = stream.readUTF();
6e85c58d 93 Integer reference = stream.readInt();
73005152
BH
94 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
95 String[] fields = new String[typeIndex];
96 for (int i = 0; i < typeIndex; i++) {
97 fields[i] = stream.readUTF();
98 }
99
6e85c58d 100 StringBuffer content = new StringBuffer("[");
73005152 101 if (typeIndex > 0) {
6e85c58d 102 content.append(fields[0]);
73005152
BH
103 }
104 for (int i = 1; i < typeIndex; i++) {
6e85c58d 105 content.append(", ").append(fields[i]);
73005152 106 }
6e85c58d 107 content.append("]");
73005152 108
a4115405 109 TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
72f1e62a 110 ITmfEvent event = new TmfEvent(eventStream,
6e85c58d
FC
111 new TmfTimestamp(ts, -3, 0), // millisecs
112 source, fTypes[typeIndex], root, reference.toString());
73005152
BH
113 return event;
114 } catch (EOFException e) {
115 }
d18dd09b
ASL
116 return null;
117 }
118
e31e01e8 119}
This page took 0.036672 seconds and 5 git commands to generate.