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 | ||
18 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
19 | import org.eclipse.linuxtools.tmf.event.TmfEventContent; | |
20 | import org.eclipse.linuxtools.tmf.event.TmfEventField; | |
21 | import org.eclipse.linuxtools.tmf.event.TmfEventReference; | |
22 | import org.eclipse.linuxtools.tmf.event.TmfEventSource; | |
23 | import org.eclipse.linuxtools.tmf.event.TmfEventType; | |
24 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
25 | import org.eclipse.linuxtools.tmf.parser.ITmfEventParser; | |
26 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; | |
27 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
28 | import org.eclipse.linuxtools.tmf.trace.TmfLocation; | |
29 | import org.eclipse.linuxtools.tmf.trace.TmfTraceStub; | |
30 | ||
31 | public class TmfUml2SDTestTrace implements ITmfEventParser { | |
32 | ||
33 | @Override | |
34 | @SuppressWarnings({ "unchecked", "nls" }) | |
35 | public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException { | |
36 | if (! (eventStream instanceof TmfTraceStub)) { | |
37 | return null; | |
38 | } | |
39 | ||
40 | // Highly inefficient... | |
41 | RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream(); | |
42 | ||
43 | String name = eventStream.getName(); | |
44 | name = name.substring(name.lastIndexOf('/') + 1); | |
45 | ||
46 | long location = 0; | |
47 | if (context != null) | |
48 | location = ((TmfLocation<Long>) (context.getLocation())).getLocation(); | |
49 | stream.seek(location); | |
50 | ||
51 | try { | |
52 | long ts = stream.readLong(); | |
53 | String source = stream.readUTF(); | |
54 | String type = stream.readUTF(); | |
55 | String reference = stream.readUTF(); | |
56 | String sender = stream.readUTF(); | |
57 | String receiver = stream.readUTF(); | |
58 | String signal = stream.readUTF(); | |
59 | ||
60 | TmfEventReference tmfReference = new TmfEventReference(reference); | |
61 | TmfEventSource tmfSource = new TmfEventSource(source); | |
62 | String[] labels = {"sender", "receiver", "signal"}; | |
63 | ||
64 | TmfEventType tmfEventType = new TmfEventType(type, labels); | |
65 | TmfEvent tmfEvent = new TmfEvent(new TmfTimestamp(ts, (byte)-9), tmfSource, tmfEventType, tmfReference); | |
66 | ||
67 | String content = "["; | |
68 | content += sender; | |
69 | content += "," + receiver; | |
70 | content += "," + signal; | |
71 | content += "]"; | |
72 | ||
73 | TmfEventContent tmfContent = new TmfEventContent(tmfEvent, content) { | |
74 | @Override | |
75 | public void parseContent() { | |
76 | String raw = (String) fRawContent; | |
77 | int i = raw.indexOf(","); | |
78 | String sender = raw.substring(1, i); | |
79 | int k = raw.indexOf(",", i+1); | |
80 | String receiver = raw.substring(i+1, k); | |
81 | i = raw.indexOf(",", k+1); | |
82 | String signal = raw.substring(k+1, raw.length() - 1); | |
83 | fFields = new Object[3]; | |
84 | fFields[0] = new TmfEventField(this, "sender", sender); | |
85 | fFields[1] = new TmfEventField(this, "receiver", receiver);; | |
86 | fFields[2] = new TmfEventField(this, "signal", signal);; | |
87 | } | |
88 | }; | |
89 | tmfEvent.setContent(tmfContent); | |
90 | ||
91 | return tmfEvent; | |
92 | } catch (EOFException e) { | |
93 | } | |
94 | return null; | |
95 | } | |
96 | ||
97 | } |