Rename xxx.lttng to xxx.lttng.core
[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.TmfEventReference;
23 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
24 import org.eclipse.linuxtools.tmf.event.TmfEventType;
25 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
26 import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
27
28 /**
29 * <b><u>TmfEventParserStub</u></b>
30 * <p>
31 * TODO: Implement me. Please.
32 */
33 @SuppressWarnings("nls")
34 public class TmfEventParserStub implements ITmfEventParser {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 private final int NB_TYPES = 10;
41 private final TmfEventType[] fTypes;
42
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
46
47 public TmfEventParserStub() {
48 fTypes = new TmfEventType[NB_TYPES];
49 for (int i = 0; i < NB_TYPES; i++) {
50 Vector<String> format = new Vector<String>();
51 for (int j = 1; j <= i; j++) {
52 format.add(new String("Fmt-" + i + "-Fld-" + j));
53 }
54 String[] fields = new String[i];
55 fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
56 }
57 }
58
59 // ------------------------------------------------------------------------
60 // Operators
61 // ------------------------------------------------------------------------
62
63 static final String typePrefix = "Type-";
64 @Override
65 @SuppressWarnings("unchecked")
66 public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
67
68 if (! (eventStream instanceof TmfTraceStub)) {
69 return null;
70 }
71
72 // Highly inefficient...
73 RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
74 String name = eventStream.getName();
75 name = name.substring(name.lastIndexOf('/') + 1);
76
77 // no need to use synchronized since it's already cover by the calling method
78
79 long location = 0;
80 if (context != null)
81 location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
82 stream.seek(location);
83
84 try {
85 long ts = stream.readLong();
86 String source = stream.readUTF();
87 String type = stream.readUTF();
88 @SuppressWarnings("unused")
89 int reference = stream.readInt();
90 int typeIndex = Integer.parseInt(type.substring(typePrefix.length()));
91 String[] fields = new String[typeIndex];
92 for (int i = 0; i < typeIndex; i++) {
93 fields[i] = stream.readUTF();
94 }
95
96 String content = "[";
97 if (typeIndex > 0) {
98 content += fields[0];
99 }
100 for (int i = 1; i < typeIndex; i++) {
101 content += ", " + fields[i];
102 }
103 content += "]";
104
105 TmfEvent event = new TmfEvent(
106 new TmfTimestamp(ts, (byte) -3, 0), // millisecs
107 new TmfEventSource(source),
108 fTypes[typeIndex],
109 new TmfEventReference(name));
110 TmfEventContent cnt = new TmfEventContent(event, content);
111 event.setContent(cnt);
112 return event;
113 } catch (EOFException e) {
114 }
115 return null;
116 }
117
118 }
This page took 0.033041 seconds and 5 git commands to generate.