linux.ui: Add Operating System Overview Perspective
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtEvent.java
CommitLineData
6151d86c 1/*******************************************************************************
53f17e49 2 * Copyright (c) 2010, 2016 Ericsson
6151d86c
PT
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
2bdf0193 13package org.eclipse.tracecompass.tmf.core.parsers.custom;
6151d86c
PT
14
15import java.util.regex.Matcher;
16
ca5b04ad 17import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
18import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
19import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
20import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
21import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
22import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
23import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
6151d86c 25
a0a88f65
AM
26/**
27 * Trace event for custom text parsers.
28 *
29 * @author Patrick Tassé
30 */
6151d86c
PT
31public class CustomTxtEvent extends CustomEvent {
32
a0a88f65
AM
33 /**
34 * Constructor
35 *
36 * @param definition
37 * Trace definition
38 */
6151d86c
PT
39 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
40 super(definition);
6151d86c
PT
41 }
42
a0a88f65
AM
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 */
ca5b04ad 51 public CustomTxtEvent(CustomTxtTraceDefinition definition, @NonNull TmfEvent other) {
6151d86c
PT
52 super(definition, other);
53 }
54
a0a88f65
AM
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
a0a88f65
AM
64 * @param type
65 * Event type
a0a88f65
AM
66 */
67 public CustomTxtEvent(CustomTxtTraceDefinition definition,
e1de2fd4
AM
68 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
69 super(definition, parentTrace, timestamp, type);
6151d86c
PT
70 }
71
72 @Override
73 public void setContent(ITmfEventField content) {
74 super.setContent(content);
75 }
76
a0a88f65
AM
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 */
6151d86c 85 public void processGroups(InputLine input, Matcher matcher) {
d5efe032
AF
86 if (input.columns == null) {
87 return;
88 }
6151d86c
PT
89 for (int i = 0; i < input.columns.size(); i++) {
90 InputData column = input.columns.get(i);
91 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
92 String value = matcher.group(i + 1).trim();
93 if (value.length() == 0) {
94 continue;
95 }
96 String name = column.name;
97 if (column.action == CustomTraceDefinition.ACTION_SET) {
98 fData.put(name, value);
99 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
100 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
101 }
102 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
103 String s = fData.get(name);
104 if (s != null) {
105 fData.put(name, s + value);
106 } else {
107 fData.put(name, value);
108 }
109 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
110 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
111 if (timeStampInputFormat != null) {
112 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
113 } else {
114 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
115 }
116 }
117 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
118 String s = fData.get(name);
119 if (s != null) {
120 fData.put(name, s + " | " + value); //$NON-NLS-1$
121 } else {
122 fData.put(name, value);
123 }
124 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
125 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
126 if (timeStampInputFormat != null) {
127 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
128 } else {
129 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
130 }
131 }
132 }
133 }
134 }
135 }
136
137}
This page took 0.148447 seconds and 5 git commands to generate.