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
.stubs
.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
.core
.event
.TmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventContent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventReference
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventSource
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.parser
.ITmfEventParser
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
32 * <b><u>TmfEventParserStub</u></b>
34 * TODO: Implement me. Please.
36 @SuppressWarnings("nls")
37 public class TmfEventParserStub
implements ITmfEventParser
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 private final int NB_TYPES
= 10;
44 private final TmfEventType
[] fTypes
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 public TmfEventParserStub() {
51 fTypes
= new TmfEventType
[NB_TYPES
];
52 for (int i
= 0; i
< NB_TYPES
; i
++) {
53 Vector
<String
> format
= new Vector
<String
>();
54 for (int j
= 1; j
<= i
; j
++) {
55 format
.add(new String("Fmt-" + i
+ "-Fld-" + j
));
57 String
[] fields
= new String
[i
];
58 fTypes
[i
] = new TmfEventType("Type-" + i
, format
.toArray(fields
));
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 static final String typePrefix
= "Type-";
68 @SuppressWarnings("unchecked")
69 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfContext context
) throws IOException
{
71 if (! (eventStream
instanceof TmfTraceStub
)) {
75 // Highly inefficient...
76 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
77 String name
= eventStream
.getName();
78 name
= name
.substring(name
.lastIndexOf('/') + 1);
80 // no need to use synchronized since it's already cover by the calling method
84 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
85 stream
.seek(location
);
88 long ts
= stream
.readLong();
89 String source
= stream
.readUTF();
90 String type
= stream
.readUTF();
91 @SuppressWarnings("unused")
92 int reference
= stream
.readInt();
93 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
94 String
[] fields
= new String
[typeIndex
];
95 for (int i
= 0; i
< typeIndex
; i
++) {
96 fields
[i
] = stream
.readUTF();
101 content
+= fields
[0];
103 for (int i
= 1; i
< typeIndex
; i
++) {
104 content
+= ", " + fields
[i
];
108 TmfEvent event
= new TmfEvent(
109 new TmfTimestamp(ts
, (byte) -3, 0), // millisecs
110 new TmfEventSource(source
),
112 new TmfEventReference(name
));
113 TmfEventContent cnt
= new TmfEventContent(event
, content
);
114 event
.setContent(cnt
);
116 } catch (EOFException e
) {
This page took 0.033309 seconds and 5 git commands to generate.