tmf: Add support for custom event type by text line or XML element
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.parsers.custom;
14
15 import java.util.regex.Matcher;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
19 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
20 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
21 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
22 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
23 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
24 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
25
26 /**
27 * Trace event for custom text parsers.
28 *
29 * @author Patrick Tassé
30 */
31 public class CustomTxtEvent extends CustomEvent {
32
33 /**
34 * Constructor
35 *
36 * @param definition
37 * Trace definition
38 */
39 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
40 super(definition);
41 }
42
43 /**
44 * Construct a custom text event from an existing TmfEvent.
45 *
46 * @param definition
47 * Trace definition
48 * @param other
49 * The TmfEvent object to copy
50 */
51 public CustomTxtEvent(CustomTxtTraceDefinition definition, @NonNull TmfEvent other) {
52 super(definition, other);
53 }
54
55 /**
56 * Full constructor.
57 *
58 * @param definition
59 * Trace definition
60 * @param parentTrace
61 * Parent trace object
62 * @param timestamp
63 * Timestamp of this event
64 * @param type
65 * Event type
66 */
67 public CustomTxtEvent(CustomTxtTraceDefinition definition,
68 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
69 super(definition, parentTrace, timestamp, type);
70 }
71
72 @Override
73 public void setContent(ITmfEventField content) {
74 super.setContent(content);
75 }
76
77 /**
78 * Process an entry in the trace file
79 *
80 * @param input
81 * The input line to read
82 * @param matcher
83 * The regex matcher to use
84 */
85 public void processGroups(InputLine input, Matcher matcher) {
86 if (input.eventType != null) {
87 fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType);
88 }
89 if (input.columns == null) {
90 return;
91 }
92 for (int i = 0; i < input.columns.size(); i++) {
93 InputData column = input.columns.get(i);
94 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
95 String value = matcher.group(i + 1).trim();
96 if (value.length() == 0) {
97 continue;
98 }
99 String name = column.name;
100 if (column.action == CustomTraceDefinition.ACTION_SET) {
101 fData.put(name, value);
102 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
103 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
104 }
105 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
106 String s = fData.get(name);
107 if (s != null) {
108 fData.put(name, s + value);
109 } else {
110 fData.put(name, value);
111 }
112 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
113 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
114 if (timeStampInputFormat != null) {
115 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
116 } else {
117 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
118 }
119 }
120 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
121 String s = fData.get(name);
122 if (s != null) {
123 fData.put(name, s + " | " + value); //$NON-NLS-1$
124 } else {
125 fData.put(name, value);
126 }
127 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
128 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
129 if (timeStampInputFormat != null) {
130 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
131 } else {
132 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
133 }
134 }
135 }
136 }
137 }
138 }
139
140 }
This page took 0.038513 seconds and 5 git commands to generate.