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 @SuppressWarnings("nls")
34 public class TmfEventParserStub
implements ITmfEventParser
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private final int NB_TYPES
= 10;
41 private final TmfEventType
[] fTypes
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 public TmfEventParserStub() {
48 fTypes
= new TmfEventType
[NB_TYPES
];
49 for (int i
= 0; i
< NB_TYPES
; i
++) {
50 Vector
<String
> format
= new Vector
<String
>();
51 for (int j
= 1; j
<= i
; j
++) {
52 format
.add(new String("Fmt-" + i
+ "-Fld-" + j
));
54 String
[] fields
= new String
[i
];
55 fTypes
[i
] = new TmfEventType("Type-" + i
, format
.toArray(fields
));
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 static final String typePrefix
= "Type-";
65 @SuppressWarnings("unchecked")
66 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfContext context
) throws IOException
{
68 if (! (eventStream
instanceof TmfTraceStub
)) {
72 // Highly inefficient...
73 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
74 String name
= eventStream
.getName();
75 name
= name
.substring(name
.lastIndexOf('/') + 1);
77 // no need to use synchronized since it's already cover by the calling method
81 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
82 stream
.seek(location
);
85 long ts
= stream
.readLong();
86 String source
= stream
.readUTF();
87 String type
= stream
.readUTF();
88 @SuppressWarnings("unused")
89 int reference
= stream
.readInt();
90 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
91 String
[] fields
= new String
[typeIndex
];
92 for (int i
= 0; i
< typeIndex
; i
++) {
93 fields
[i
] = stream
.readUTF();
100 for (int i
= 1; i
< typeIndex
; i
++) {
101 content
+= ", " + fields
[i
];
105 TmfEvent event
= new TmfEvent(
106 new TmfTimestamp(ts
, (byte) -3, 0), // millisecs
107 new TmfEventSource(source
),
109 new TmfEventReference(name
));
110 TmfEventContent cnt
= new TmfEventContent(event
, content
);
111 event
.setContent(cnt
);
113 } catch (EOFException e
) {
This page took 0.033459 seconds and 5 git commands to generate.