- Fixed a bunch of warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / evProcessor / state / AbsStateProcessing.java
CommitLineData
5d10d135
ASL
1/**
2 *
3 */
4package org.eclipse.linuxtools.lttng.state.evProcessor.state;
5
6import org.eclipse.linuxtools.lttng.TraceDebug;
7import org.eclipse.linuxtools.lttng.event.LttngEvent;
8import org.eclipse.linuxtools.lttng.event.LttngEventContent;
9import org.eclipse.linuxtools.lttng.event.LttngEventField;
10import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
11import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
12import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
13import org.eclipse.linuxtools.tmf.event.TmfEventField;
14
15/**
16 * Common utility methods for all state processing handlers, not intended to be
17 * instantiated on its own
18 *
19 * @author alvaro
20 *
21 */
22public abstract class AbsStateProcessing {
23
24 /**
25 * protected method used when a Field is requested among several available
26 * fields and the expected type is Long
27 *
28 * @param trcEvent
29 * @param traceSt
30 * @param expectedNumFields
31 * @return
32 */
28b94d61 33 protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt, Fields expectedField) {
63eecb47 34 Long fieldVal = null;
28b94d61
FC
35
36 String fieldname = expectedField.getInName();
37 LttngEventField field = ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
38
39// if ( field == null ) {
40// System.out.println("****************** JOIE : " + fieldname);
41// System.out.println("***************** CONTENT : " + ((LttngEventContent) trcEvent.getContent()).toString());
42// }
43// else {
44 Object fieldObj = field.getValue();
45 if ( (fieldObj instanceof Long) || (fieldObj instanceof Integer) ) {
46 // Expected numeric value found
47 fieldVal = (Long) field.getValue();
48 }
49 else {
50 if (TraceDebug.isDEBUG()) {
51 TraceDebug.debug("Unexpected field Type. Expected: Long, Received: "+ fieldObj.getClass().getSimpleName());
52 }
53 }
54// }
55
56 /*
5d10d135
ASL
57 // TmfEventField[] fields = trcEvent.getContent().getFields();
58 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
59 .getFields(trcEvent);
60
61 // At least one field expected
62 if (fields.length == 0) {
63 TraceDebug.debug("Unexpected number of fields received: "
64 + fields.length);
65 return null;
66 }
67
68 LttngEventField field;
69 String fieldname;
70 String expectedFieldName = expectedField.getInName();
71 for (int i = 0; i < fields.length; i++) {
72 field = (LttngEventField) fields[i];
73 fieldname = field.getName();
74 if (fieldname.equals(expectedFieldName)) {
75 Object fieldObj = field.getValue();
76 if (fieldObj instanceof Long) {
77 // Expected value found
78 fieldVal = (Long) field.getValue();
79 // if (expectedField == Fields.LTT_FIELD_TYPE) {
80 // TraceDebug.debug("Field Type value is: " + fieldVal);
81 // }
82 break;
83 } else {
84 if (TraceDebug.isDEBUG()) {
85 TraceDebug
86 .debug("Unexpected field Type. Expected: Long, Received: "
87 + fieldObj.getClass().getSimpleName());
88 }
89 return null;
90 }
91 }
92 }
28b94d61 93 */
5d10d135 94
28b94d61
FC
95// if (fieldVal == null) {
96// if (TraceDebug.isDEBUG()) {
97// sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
98// }
99// }
5d10d135
ASL
100 return fieldVal;
101 }
102
103 /**
104 * protected method used when a Field is requested among several available
105 * fields and the expected type is String
106 *
107 * @param trcEvent
108 * @param traceSt
109 * @param expectedNumFields
110 * @return
111 */
112 protected String getAFieldString(LttngEvent trcEvent,
113 LttngTraceState traceSt, Fields expectedField) {
63eecb47 114 String fieldVal = null;
28b94d61
FC
115
116 String fieldname = expectedField.getInName();
117 LttngEventField field = ((LttngEventContent) trcEvent.getContent()).getField(fieldname);
118
119 Object fieldObj = field.getValue();
120 if (fieldObj instanceof String) {
121 // Expected numeric value found
122 fieldVal = (String) field.getValue();
123 }
124 else {
125 if (TraceDebug.isDEBUG()) {
126 TraceDebug.debug("Unexpected field Type. Expected: String, Received: "+ fieldObj.getClass().getSimpleName());
127 }
128 }
129
130 /*
5d10d135
ASL
131 // TmfEventField[] fields = trcEvent.getContent().getFields();
132 TmfEventField[] fields = ((LttngEventContent) trcEvent.getContent())
133 .getFields(trcEvent);
134
135 // Only one field expected
136 if (fields.length == 0) {
137 TraceDebug.debug("Unexpected number of fields received: "
138 + fields.length);
139 return null;
140 }
141
142 LttngEventField field;
143 String fieldname;
144 String expectedFieldName = expectedField.getInName();
145 for (int i = 0; i < fields.length; i++) {
146 field = (LttngEventField) fields[i];
147 fieldname = field.getName();
148 if (fieldname.equals(expectedFieldName)) {
149 Object fieldObj = field.getValue();
150 if (fieldObj instanceof String) {
151 // Expected value found
152 fieldVal = (String) field.getValue();
153 break;
154 } else {
155 if (TraceDebug.isDEBUG()) {
156 TraceDebug
157 .debug("Unexpected field Type. Expected: String, Received: "
158 + fieldObj.getClass().getSimpleName());
159 }
160 return null;
161 }
162 }
163 }
28b94d61
FC
164 */
165
166// if (fieldVal == null) {
167// if (TraceDebug.isDEBUG()) {
168// sendNoFieldFoundMsg(((LttngEventContent) trcEvent.getContent()).getFields(), fieldname);
169// }
170// }
5d10d135
ASL
171 return fieldVal;
172 }
173
174 /**
175 * Find the process matching the given pid and cpu
176 *
177 * If cpu is 0, the cpu value is not matched and the selection is based on
178 * pid value only
179 *
180 * @param traceState
181 * @param cpu
182 * @param pid
183 * @return
184 */
185 protected LttngProcessState lttv_state_find_process(
2211df66 186 LttngTraceState traceState, Long cpu, Long pid) {
5d10d135 187
2211df66 188 return traceState.findProcessState(pid, cpu, traceState.getTraceId());
5d10d135
ASL
189 }
190
191 protected void sendNoFieldFoundMsg(TmfEventField[] fields,
192 String expectedFieldName) {
193 LttngEventField field;
194 StringBuilder sb = new StringBuilder("Field not found, requested: "
195 + expectedFieldName);
196 sb.append(" number of fields: " + fields.length + "Fields: ");
197 for (int i = 0; i < fields.length; i++) {
198 field = (LttngEventField) fields[i];
28b94d61 199 sb.append(field.getId() + " ");
5d10d135
ASL
200 }
201
202 TraceDebug.debug(sb.toString(), 5);
203 }
204
205}
This page took 0.031827 seconds and 5 git commands to generate.