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