ceb98993f036077d430586a32e76405be1fbd97f
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 - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.trace
;
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
.TmfEventReference
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
26 import org
.eclipse
.linuxtools
.tmf
.parser
.ITmfEventParser
;
29 * <b><u>TmfEventParserStub</u></b>
31 * TODO: Implement me. Please.
33 public class TmfEventParserStub
implements ITmfEventParser
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 private final int NB_TYPES
= 10;
40 private final TmfEventType
[] fTypes
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 public TmfEventParserStub() {
47 fTypes
= new TmfEventType
[NB_TYPES
];
48 for (int i
= 0; i
< NB_TYPES
; i
++) {
49 Vector
<String
> format
= new Vector
<String
>();
50 for (int j
= 1; j
<= i
; j
++) {
51 format
.add(new String("Fmt-" + i
+ "-Fld-" + j
));
53 String
[] fields
= new String
[i
];
54 fTypes
[i
] = new TmfEventType("Type-" + i
, format
.toArray(fields
));
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 static final String typePrefix
= "Type-";
63 @SuppressWarnings("unchecked")
64 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfContext context
) throws IOException
{
66 if (! (eventStream
instanceof TmfTraceStub
)) {
70 // Highly inefficient...
71 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
72 String name
= eventStream
.getName();
73 name
= name
.substring(name
.lastIndexOf('/') + 1);
75 synchronized(stream
) {
78 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getValue();
79 stream
.seek(location
);
82 long ts
= stream
.readLong();
83 String source
= stream
.readUTF();
84 String type
= stream
.readUTF();
85 @SuppressWarnings("unused")
86 int reference
= stream
.readInt();
87 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
88 String
[] fields
= new String
[typeIndex
];
89 for (int i
= 0; i
< typeIndex
; i
++) {
90 fields
[i
] = stream
.readUTF();
97 for (int i
= 1; i
< typeIndex
; i
++) {
98 content
+= ", " + fields
[i
];
102 TmfEvent event
= new TmfEvent(
103 new TmfTimestamp(ts
, (byte) -3, 0), // millisecs
104 new TmfEventSource(source
),
106 new TmfEventReference(name
));
107 TmfEventContent cnt
= new TmfEventContent(event
, content
);
108 event
.setContent(cnt
);
110 } catch (EOFException e
) {
This page took 0.032772 seconds and 4 git commands to generate.