Revert all luna temporary annotation changes
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfEventFactory.java
CommitLineData
6cfa0200
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.ctfadaptor;
14
15import java.util.ArrayList;
6cfa0200 16import java.util.List;
843f986b 17import java.util.Map;
6cfa0200 18
6cfa0200
AM
19import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
20import org.eclipse.linuxtools.ctf.core.event.types.Definition;
6cfa0200
AM
21import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
22import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
23import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
24import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
25
26/**
27 * Factory for CtfTmfEvent's.
28 *
29 * This code was moved out of CtfTmfEvent to provide better separation between
30 * the parsing/instantiation of events, and the usual TMF API implementations.
31 *
32 * @author Alexandre Montplaisir
33 * @since 2.0
34 */
60fb38b8 35public final class CtfTmfEventFactory {
6cfa0200 36
60fb38b8
PT
37 /**
38 * Don't let anyone instantiate this class.
39 */
40 private CtfTmfEventFactory() {}
6cfa0200
AM
41
42 /**
43 * Factory method to instantiate new {@link CtfTmfEvent}'s.
44 *
45 * @param eventDef
46 * CTF EventDefinition object corresponding to this trace event
47 * @param fileName
48 * The path to the trace file
49 * @param originTrace
50 * The trace from which this event originates
51 * @return The newly-built CtfTmfEvent
52 */
53 public static CtfTmfEvent createEvent(EventDefinition eventDef,
54 String fileName, CtfTmfTrace originTrace) {
55
56 /* Prepare what to pass to CtfTmfEvent's constructor */
57 long ts = eventDef.getTimestamp();
58 CtfTmfTimestamp timestamp = new CtfTmfTimestamp(
59 originTrace.getCTFTrace().timestampCyclesToNanos(ts));
60
61 int sourceCPU = eventDef.getCPU();
62
63 ITmfEventField content = new TmfEventField(
214cc822 64 ITmfEventField.ROOT_FIELD_ID, null, parseFields(eventDef));
6cfa0200
AM
65
66 String reference = fileName == null ? CtfTmfEvent.NO_STREAM : fileName;
67
68 /* Construct and return the object */
69 CtfTmfEvent event = new CtfTmfEvent(
70 originTrace,
71 ITmfContext.UNKNOWN_RANK,
72 timestamp,
73 content,
74 reference,
75 sourceCPU,
76 eventDef.getDeclaration()
77 );
78 return event;
79 }
80
81 /* Singleton instance of a null event */
82 private static CtfTmfEvent nullEvent = null;
83
84 /**
85 * Get an instance of a null event.
86 *
87 * @return An empty event
88 */
89 public static CtfTmfEvent getNullEvent() {
90 if (nullEvent == null) {
91 nullEvent = new CtfTmfEvent();
92 }
93 return nullEvent;
94 }
95
96 /**
97 * Extract the field information from the structDefinition haze-inducing
98 * mess, and put them into something ITmfEventField can cope with.
99 */
60fb38b8 100 private static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
6cfa0200
AM
101 List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
102
103 StructDefinition structFields = eventDef.getFields();
437bb7c0
AM
104 for (Map.Entry<String, Definition> entry : structFields.getDefinitions().entrySet()) {
105 String curFieldName = entry.getKey();
106 Definition curFieldDef = entry.getValue();
107 CtfTmfEventField curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
6cfa0200
AM
108 fields.add(curField);
109 }
110
111 /* Add context information as CtfTmfEventField */
6cfa0200
AM
112 StructDefinition structContext = eventDef.getContext();
113 if (structContext != null) {
437bb7c0 114 for (Map.Entry<String, Definition> entry : structContext.getDefinitions().entrySet()) {
60fb38b8 115 /* Prefix field name */
437bb7c0
AM
116 String curContextName = CtfConstants.CONTEXT_FIELD_PREFIX + entry.getKey();
117 Definition curContextDef = entry.getValue();
118 CtfTmfEventField curContext = CtfTmfEventField.parseField(curContextDef, curContextName);
6cfa0200
AM
119 fields.add(curContext);
120 }
121 }
437bb7c0 122
6cfa0200
AM
123 return fields.toArray(new CtfTmfEventField[fields.size()]);
124 }
125}
This page took 0.033185 seconds and 5 git commands to generate.