Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
64636df8 | 3 | * |
73005152 BH |
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 | |
64636df8 | 8 | * |
73005152 BH |
9 | * Contributors: |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace; | |
13 | ||
14 | import java.io.EOFException; | |
15 | import java.io.IOException; | |
16 | import java.io.RandomAccessFile; | |
17 | ||
2771b032 | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4c564a2d | 19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
6c13869b | 20 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
6c13869b | 21 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
6c13869b | 22 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; |
3bd46eef | 23 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; |
a1440d1f | 24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
7e6347b0 | 25 | import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; |
6c13869b | 26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
4918b8f2 | 27 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
73005152 | 28 | |
64636df8 BH |
29 | /** |
30 | * Parser implementation for Uml2SD Test Traces. | |
31 | * | |
32 | */ | |
6256d8ad | 33 | public class TmfUml2SDTestTrace implements ITmfEventParser { |
64636df8 | 34 | |
6256d8ad | 35 | ITmfTrace fEventStream; |
7e6347b0 | 36 | |
64636df8 BH |
37 | /** |
38 | * Default Constructor | |
39 | */ | |
7e6347b0 FC |
40 | public TmfUml2SDTestTrace() { |
41 | } | |
42 | ||
64636df8 BH |
43 | /** |
44 | * Constructor | |
45 | * @param eventStream ITmfTrace implementation | |
46 | */ | |
6256d8ad | 47 | public TmfUml2SDTestTrace(ITmfTrace eventStream) { |
7e6347b0 FC |
48 | fEventStream = eventStream; |
49 | } | |
50 | ||
64636df8 BH |
51 | /** |
52 | * @param eventStream ITmfTrace implementation to set | |
53 | */ | |
6256d8ad | 54 | public void setTrace(ITmfTrace eventStream) { |
7e6347b0 FC |
55 | fEventStream = eventStream; |
56 | } | |
57 | ||
73005152 | 58 | @Override |
64636df8 | 59 | @SuppressWarnings({ "nls" }) |
2771b032 | 60 | public ITmfEvent parseEvent(ITmfContext context) { |
7e6347b0 | 61 | if (! (fEventStream instanceof TmfTraceStub)) { |
73005152 BH |
62 | return null; |
63 | } | |
64 | ||
65 | // Highly inefficient... | |
7e6347b0 | 66 | RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream(); |
73005152 | 67 | |
1f2f091b BH |
68 | // String name = eventStream.getName(); |
69 | // name = name.substring(name.lastIndexOf('/') + 1); | |
73005152 BH |
70 | |
71 | long location = 0; | |
64636df8 | 72 | if (context != null) { |
5976d44a | 73 | location = (Long) context.getLocation().getLocationInfo(); |
64636df8 | 74 | } |
73005152 BH |
75 | |
76 | try { | |
7e6347b0 FC |
77 | stream.seek(location); |
78 | ||
73005152 BH |
79 | long ts = stream.readLong(); |
80 | String source = stream.readUTF(); | |
81 | String type = stream.readUTF(); | |
82 | String reference = stream.readUTF(); | |
83 | String sender = stream.readUTF(); | |
84 | String receiver = stream.readUTF(); | |
85 | String signal = stream.readUTF(); | |
86 | ||
73005152 BH |
87 | String[] labels = {"sender", "receiver", "signal"}; |
88 | ||
4c564a2d | 89 | TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels)); |
73005152 BH |
90 | |
91 | String content = "["; | |
92 | content += sender; | |
93 | content += "," + receiver; | |
94 | content += "," + signal; | |
95 | content += "]"; | |
96 | ||
4c564a2d FC |
97 | // Pre-parse the content |
98 | TmfEventField[] fields = new TmfEventField[3]; | |
99 | fields[0] = new TmfEventField("sender", sender); | |
100 | fields[1] = new TmfEventField("receiver", receiver); | |
101 | fields[2] = new TmfEventField("signal", signal); | |
64636df8 | 102 | |
a4115405 | 103 | ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields); |
2771b032 | 104 | ITmfEvent tmfEvent = new TmfEvent(fEventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference); |
73005152 BH |
105 | |
106 | return tmfEvent; | |
7e6347b0 FC |
107 | } catch (final EOFException e) { |
108 | } catch (final IOException e) { | |
73005152 BH |
109 | } |
110 | return null; | |
111 | } | |
112 | ||
113 | } |