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
.trace
.ITmfContext
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfEventParser
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 * <b><u>TmfEventParserStub</u></b>
32 * TODO: Implement me. Please.
34 @SuppressWarnings("javadoc")
35 public class TmfEventParserStub
implements ITmfEventParser
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 private static final int NB_TYPES
= 10;
42 private final TmfEventType
[] fTypes
;
43 private final ITmfTrace fEventStream
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 public TmfEventParserStub(final ITmfTrace eventStream
) {
50 fEventStream
= eventStream
;
51 fTypes
= new TmfEventType
[NB_TYPES
];
52 for (int i
= 0; i
< NB_TYPES
; i
++) {
53 final Vector
<String
> fields
= new Vector
<>();
54 for (int j
= 1; j
<= i
; j
++) {
55 final String field
= "Fmt-" + i
+ "-Fld-" + j
;
58 final String
[] fieldArray
= new String
[i
];
59 final ITmfEventField rootField
= TmfEventField
.makeRoot(fields
.toArray(fieldArray
));
60 fTypes
[i
] = new TmfEventType("Type-" + i
, rootField
);
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 static final String typePrefix
= "Type-";
70 public ITmfEvent
parseEvent(final ITmfContext context
) {
72 if (! (fEventStream
instanceof TmfTraceStub
)) {
76 // Highly inefficient...
77 final RandomAccessFile stream
= ((TmfTraceStub
) fEventStream
).getStream();
82 // String name = eventStream.getName();
83 // name = name.substring(name.lastIndexOf('/') + 1);
85 // no need to use synchronized since it's already cover by the calling method
88 if (context
!= null && context
.getLocation() != null) {
89 location
= (Long
) context
.getLocation().getLocationInfo();
91 stream
.seek(location
);
93 final long ts
= stream
.readLong();
94 stream
.readUTF(); /* Previously source, now unused */
95 final String type
= stream
.readUTF();
96 stream
.readInt(); /* Previously reference, now unused */
97 final int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
98 final String
[] fields
= new String
[typeIndex
];
99 for (int i
= 0; i
< typeIndex
; i
++) {
100 fields
[i
] = stream
.readUTF();
103 final StringBuffer content
= new StringBuffer("[");
105 content
.append(fields
[0]);
107 for (int i
= 1; i
< typeIndex
; i
++) {
108 content
.append(", ").append(fields
[i
]);
112 final TmfEventField root
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, content
.toString(), null);
113 final ITmfEvent event
= new TmfEvent(fEventStream
,
114 ITmfContext
.UNKNOWN_RANK
,
115 fEventStream
.createTimestamp(ts
* 1000000L),
116 fTypes
[typeIndex
], root
);
118 } catch (final EOFException e
) {
119 } catch (final IOException e
) {
This page took 0.054761 seconds and 5 git commands to generate.