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