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
.ITmfEventField
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.parser
.ITmfEventParser
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
31 * <b><u>TmfEventParserStub</u></b>
33 * TODO: Implement me. Please.
35 @SuppressWarnings("nls")
36 public class TmfEventParserStub
implements ITmfEventParser
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 private final int NB_TYPES
= 10;
43 private final TmfEventType
[] fTypes
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 public TmfEventParserStub() {
50 fTypes
= new TmfEventType
[NB_TYPES
];
51 for (int i
= 0; i
< NB_TYPES
; i
++) {
52 Vector
<String
> fields
= new Vector
<String
>();
53 for (int j
= 1; j
<= i
; j
++) {
54 String field
= "Fmt-" + i
+ "-Fld-" + j
;
57 String
[] fieldArray
= new String
[i
];
58 ITmfEventField rootField
= TmfEventField
.makeRoot(fields
.toArray(fieldArray
));
59 fTypes
[i
] = new TmfEventType("UnitTest", "Type-" + i
, rootField
);
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 static final String typePrefix
= "Type-";
69 @SuppressWarnings("unchecked")
70 public TmfEvent
parseNextEvent(ITmfTrace
<?
> eventStream
, TmfContext context
) throws IOException
{
72 if (! (eventStream
instanceof TmfTraceStub
)) {
76 // Highly inefficient...
77 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
78 String name
= eventStream
.getName();
79 name
= name
.substring(name
.lastIndexOf('/') + 1);
81 // no need to use synchronized since it's already cover by the calling method
85 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
86 stream
.seek(location
);
89 long ts
= stream
.readLong();
90 String source
= stream
.readUTF();
91 String type
= stream
.readUTF();
92 @SuppressWarnings("unused")
93 int reference
= stream
.readInt();
94 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
95 String
[] fields
= new String
[typeIndex
];
96 for (int i
= 0; i
< typeIndex
; i
++) {
97 fields
[i
] = stream
.readUTF();
100 String content
= "[";
102 content
+= fields
[0];
104 for (int i
= 1; i
< typeIndex
; i
++) {
105 content
+= ", " + fields
[i
];
109 TmfEventField root
= new TmfEventField(ITmfEventField
.ROOT_ID
, content
);
110 TmfEvent event
= new TmfEvent(eventStream
,
111 new TmfTimestamp(ts
, (byte) -3, 0), // millisecs
112 source
, fTypes
[typeIndex
], root
, name
);
113 event
.setContent(root
);
115 } catch (EOFException e
) {
This page took 0.044263 seconds and 6 git commands to generate.