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; | |
23 | import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser; | |
a1440d1f | 24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
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 BH |
30 | |
31 | @Override | |
32 | @SuppressWarnings({ "unchecked", "nls" }) | |
a1440d1f | 33 | public TmfEvent parseNextEvent(ITmfTrace<TmfEvent> eventStream, ITmfContext context) throws IOException { |
73005152 BH |
34 | if (! (eventStream instanceof TmfTraceStub)) { |
35 | return null; | |
36 | } | |
37 | ||
38 | // Highly inefficient... | |
39 | RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream(); | |
40 | ||
41 | String name = eventStream.getName(); | |
42 | name = name.substring(name.lastIndexOf('/') + 1); | |
43 | ||
44 | long location = 0; | |
45 | if (context != null) | |
46 | location = ((TmfLocation<Long>) (context.getLocation())).getLocation(); | |
47 | stream.seek(location); | |
48 | ||
49 | try { | |
50 | long ts = stream.readLong(); | |
51 | String source = stream.readUTF(); | |
52 | String type = stream.readUTF(); | |
53 | String reference = stream.readUTF(); | |
54 | String sender = stream.readUTF(); | |
55 | String receiver = stream.readUTF(); | |
56 | String signal = stream.readUTF(); | |
57 | ||
73005152 BH |
58 | String[] labels = {"sender", "receiver", "signal"}; |
59 | ||
4c564a2d | 60 | TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels)); |
73005152 BH |
61 | |
62 | String content = "["; | |
63 | content += sender; | |
64 | content += "," + receiver; | |
65 | content += "," + signal; | |
66 | content += "]"; | |
67 | ||
4c564a2d FC |
68 | // Pre-parse the content |
69 | TmfEventField[] fields = new TmfEventField[3]; | |
70 | fields[0] = new TmfEventField("sender", sender); | |
71 | fields[1] = new TmfEventField("receiver", receiver); | |
72 | fields[2] = new TmfEventField("signal", signal); | |
73 | ||
a4115405 | 74 | ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields); |
7b477cc3 | 75 | TmfEvent tmfEvent = new TmfEvent(eventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference); |
73005152 BH |
76 | |
77 | return tmfEvent; | |
78 | } catch (EOFException e) { | |
79 | } | |
80 | return null; | |
81 | } | |
82 | ||
83 | } |