1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
;
14 import java
.io
.EOFException
;
15 import java
.io
.IOException
;
16 import java
.io
.RandomAccessFile
;
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
;
30 public class TmfUml2SDTestTrace
implements ITmfEventParser
{
33 @SuppressWarnings({ "unchecked", "nls" })
34 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfContext context
) throws IOException
{
35 if (! (eventStream
instanceof TmfTraceStub
)) {
39 // Highly inefficient...
40 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
42 String name
= eventStream
.getName();
43 name
= name
.substring(name
.lastIndexOf('/') + 1);
47 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
48 stream
.seek(location
);
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();
59 TmfEventReference tmfReference
= new TmfEventReference(reference
);
60 String tmfSource
= source
;
61 String
[] labels
= {"sender", "receiver", "signal"};
63 TmfEventType tmfEventType
= new TmfEventType(type
, labels
);
64 TmfEvent tmfEvent
= new TmfEvent(new TmfTimestamp(ts
, (byte)-9), tmfSource
, tmfEventType
, tmfReference
);
68 content
+= "," + receiver
;
69 content
+= "," + signal
;
72 TmfEventContent tmfContent
= new TmfEventContent(tmfEvent
, content
) {
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
);;
88 tmfEvent
.setContent(tmfContent
);
91 } catch (EOFException e
) {