1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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
.tracecompass
.tmf
.tests
.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
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfEventParser
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 * <b><u>TmfEventParserStub</u></b>
33 * TODO: Implement me. Please.
35 @SuppressWarnings("javadoc")
36 public class TmfEventParserStub
implements ITmfEventParser
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 private static final int NB_TYPES
= 10;
43 private final TmfEventType
[] fTypes
;
44 private final ITmfTrace fEventStream
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 public TmfEventParserStub(final ITmfTrace eventStream
) {
51 fEventStream
= eventStream
;
52 fTypes
= new TmfEventType
[NB_TYPES
];
53 for (int i
= 0; i
< NB_TYPES
; i
++) {
54 final Vector
<String
> fields
= new Vector
<>();
55 for (int j
= 1; j
<= i
; j
++) {
56 final String field
= "Fmt-" + i
+ "-Fld-" + j
;
59 final String
[] fieldArray
= new String
[i
];
60 final ITmfEventField rootField
= TmfEventField
.makeRoot(fields
.toArray(fieldArray
));
61 fTypes
[i
] = new TmfEventType("Type-" + i
, rootField
);
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 static final String typePrefix
= "Type-";
71 public ITmfEvent
parseEvent(final ITmfContext context
) {
73 if (! (fEventStream
instanceof TmfTraceStub
)) {
77 // Highly inefficient...
78 final RandomAccessFile stream
= ((TmfTraceStub
) fEventStream
).getStream();
83 // String name = eventStream.getName();
84 // name = name.substring(name.lastIndexOf('/') + 1);
86 // no need to use synchronized since it's already cover by the calling method
89 if (context
!= null && context
.getLocation() != null) {
90 location
= (Long
) context
.getLocation().getLocationInfo();
92 stream
.seek(location
);
94 final long ts
= stream
.readLong();
95 final String source
= stream
.readUTF();
96 final String type
= stream
.readUTF();
97 final int reference
= stream
.readInt();
98 final int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
99 final String
[] fields
= new String
[typeIndex
];
100 for (int i
= 0; i
< typeIndex
; i
++) {
101 fields
[i
] = stream
.readUTF();
104 final StringBuffer content
= new StringBuffer("[");
106 content
.append(fields
[0]);
108 for (int i
= 1; i
< typeIndex
; i
++) {
109 content
.append(", ").append(fields
[i
]);
113 final TmfEventField root
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, content
.toString(), null);
114 final ITmfEvent event
= new TmfEvent(fEventStream
,
115 new TmfTimestamp(ts
, -3), // millisecs
116 source
, fTypes
[typeIndex
], root
, String
.valueOf(reference
));
118 } catch (final EOFException e
) {
119 } catch (final IOException e
) {
This page took 0.04459 seconds and 6 git commands to generate.