Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / widgetStubs / org / eclipse / linuxtools / tmf / ui / tests / uml2sd / trace / TmfUml2SDTestTrace.java
CommitLineData
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 *******************************************************************************/
12package org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace;
13
14import java.io.EOFException;
15import java.io.IOException;
16import java.io.RandomAccessFile;
17
6c13869b
FC
18import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
19import org.eclipse.linuxtools.tmf.core.event.TmfEventContent;
20import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
21import org.eclipse.linuxtools.tmf.core.event.TmfEventReference;
22import org.eclipse.linuxtools.tmf.core.event.TmfEventSource;
23import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
24import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
25import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser;
26import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
27import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
28import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
29import org.eclipse.linuxtools.tmf.stubs.trace.TmfTraceStub;
73005152
BH
30
31public 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}
This page took 0.028571 seconds and 5 git commands to generate.