Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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 | * 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; |
6c13869b | 26 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; |
4918b8f2 | 27 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; |
73005152 | 28 | |
72f1e62a | 29 | public class TmfUml2SDTestTrace implements ITmfEventParser<TmfEvent> { |
73005152 | 30 | |
7e6347b0 FC |
31 | ITmfTrace<TmfEvent> fEventStream; |
32 | ||
33 | public TmfUml2SDTestTrace() { | |
34 | } | |
35 | ||
36 | public TmfUml2SDTestTrace(ITmfTrace<TmfEvent> eventStream) { | |
37 | fEventStream = eventStream; | |
38 | } | |
39 | ||
40 | public void setTrace(ITmfTrace<TmfEvent> eventStream) { | |
41 | fEventStream = eventStream; | |
42 | } | |
43 | ||
73005152 BH |
44 | @Override |
45 | @SuppressWarnings({ "unchecked", "nls" }) | |
7e6347b0 FC |
46 | public TmfEvent parseEvent(ITmfContext context) { |
47 | if (! (fEventStream instanceof TmfTraceStub)) { | |
73005152 BH |
48 | return null; |
49 | } | |
50 | ||
51 | // Highly inefficient... | |
7e6347b0 | 52 | RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream(); |
73005152 | 53 | |
1f2f091b BH |
54 | // String name = eventStream.getName(); |
55 | // name = name.substring(name.lastIndexOf('/') + 1); | |
73005152 BH |
56 | |
57 | long location = 0; | |
58 | if (context != null) | |
59 | location = ((TmfLocation<Long>) (context.getLocation())).getLocation(); | |
73005152 BH |
60 | |
61 | try { | |
7e6347b0 FC |
62 | stream.seek(location); |
63 | ||
73005152 BH |
64 | long ts = stream.readLong(); |
65 | String source = stream.readUTF(); | |
66 | String type = stream.readUTF(); | |
67 | String reference = stream.readUTF(); | |
68 | String sender = stream.readUTF(); | |
69 | String receiver = stream.readUTF(); | |
70 | String signal = stream.readUTF(); | |
71 | ||
73005152 BH |
72 | String[] labels = {"sender", "receiver", "signal"}; |
73 | ||
4c564a2d | 74 | TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels)); |
73005152 BH |
75 | |
76 | String content = "["; | |
77 | content += sender; | |
78 | content += "," + receiver; | |
79 | content += "," + signal; | |
80 | content += "]"; | |
81 | ||
4c564a2d FC |
82 | // Pre-parse the content |
83 | TmfEventField[] fields = new TmfEventField[3]; | |
84 | fields[0] = new TmfEventField("sender", sender); | |
85 | fields[1] = new TmfEventField("receiver", receiver); | |
86 | fields[2] = new TmfEventField("signal", signal); | |
87 | ||
a4115405 | 88 | ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields); |
7e6347b0 | 89 | TmfEvent tmfEvent = new TmfEvent(fEventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference); |
73005152 BH |
90 | |
91 | return tmfEvent; | |
7e6347b0 FC |
92 | } catch (final EOFException e) { |
93 | } catch (final IOException e) { | |
73005152 BH |
94 | } |
95 | return null; | |
96 | } | |
97 | ||
98 | } |