1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.stubs
;
15 import java
.io
.EOFException
;
16 import java
.io
.IOException
;
17 import java
.io
.RandomAccessFile
;
18 import java
.util
.Vector
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventContent
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventFormat
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
26 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfEventParser
;
27 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
31 * <b><u>TmfEventParserStub</u></b>
33 * TODO: Implement me. Please.
35 public class LTTngEventParserStub
implements ITmfEventParser
{
37 // ========================================================================
39 // ========================================================================
41 private final int NB_FORMATS
= 10;
42 private final TmfEventFormat
[] fFormats
;
44 // ========================================================================
46 // ========================================================================
48 public LTTngEventParserStub() {
49 fFormats
= new TmfEventFormat
[NB_FORMATS
];
50 for (int i
= 0; i
< NB_FORMATS
; i
++) {
51 Vector
<String
> format
= new Vector
<String
>();
52 for (int j
= 1; j
<= i
; j
++) {
53 format
.add(new String("Fmt-" + i
+ "-Fld-" + j
));
55 String
[] fields
= new String
[i
];
56 fFormats
[i
] = new TmfEventFormat(format
.toArray(fields
));
60 // ========================================================================
62 // ========================================================================
64 // ========================================================================
66 // ========================================================================
69 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
71 static final String typePrefix
= "Type-";
72 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfTraceContext context
) throws IOException
{
74 if (! (eventStream
instanceof LTTngTraceStub
)) {
78 // Highly inefficient...
79 RandomAccessFile stream
= ((LTTngTraceStub
) eventStream
).getStream();
80 String name
= eventStream
.getName();
81 name
= name
.substring(name
.lastIndexOf('/') + 1);
83 synchronized(stream
) {
86 location
= (Long
) (context
.getLocation());
87 stream
.seek(location
);
90 // Read the individual fields
91 long ts
= stream
.readLong();
92 String source
= stream
.readUTF();
93 String type
= stream
.readUTF();
94 @SuppressWarnings("unused")
95 int reference
= stream
.readInt();
97 // Read the event parts
98 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
99 String
[] fields
= new String
[typeIndex
];
100 for (int i
= 0; i
< typeIndex
; i
++) {
101 fields
[i
] = stream
.readUTF();
104 // Format the content from the individual fields
105 String content
= "[";
107 content
+= fields
[0];
109 for (int i
= 1; i
< typeIndex
; i
++) {
110 content
+= ", " + fields
[i
];
114 // Update the context
115 context
.setLocation(stream
.getFilePointer());
118 long ts2
= stream
.readLong();
119 context
.setTimestamp(new LTTngTimestampStub(ts2
));
120 } catch (EOFException e
) {
121 context
.setTimestamp(null);
125 TmfEvent event
= new TmfEvent(
126 new LTTngTimestampStub(ts
),
127 new TmfEventSource(source
),
128 new TmfEventType(type
, fFormats
[typeIndex
]),
129 new TmfEventContent(content
, fFormats
[typeIndex
]),
130 new TmfEventReference(name
));
134 } catch (EOFException e
) {
135 context
.setTimestamp(null);
This page took 0.034093 seconds and 5 git commands to generate.