Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / StateStacksHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.state;
13
14 import java.util.Iterator;
15 import java.util.Set;
16 import java.util.Vector;
17
18 import org.eclipse.linuxtools.lttng.TraceDebug;
19 import org.eclipse.linuxtools.lttng.event.LttngEvent;
20 import org.eclipse.linuxtools.lttng.event.LttngEventContent;
21 import org.eclipse.linuxtools.lttng.event.LttngEventField;
22 import org.eclipse.linuxtools.lttng.jni.JniTrace;
23 import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventProcessorFactory;
24 import org.eclipse.linuxtools.lttng.state.evProcessor.EventProcessorProxy;
25 import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing;
26 import org.eclipse.linuxtools.lttng.state.model.ILttngStateInputRef;
27 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
28 import org.eclipse.linuxtools.tmf.event.TmfEvent;
29 import org.eclipse.linuxtools.tmf.event.TmfEventField;
30 import org.eclipse.linuxtools.tmf.trace.TmfTrace;
31
32 /**
33 * @author Alvaro
34 *
35 */
36 public class StateStacksHandler {
37 // ========================================================================
38 // Table data
39 // =======================================================================
40 protected LttngTraceState traceStateModel = null;
41 protected Set<String> eventsNotHandled = null;
42 protected Vector<IEventProcessing> listeners = new Vector<IEventProcessing>();
43
44 // ========================================================================
45 // Constructors
46 // ========================================================================
47 public StateStacksHandler(LttngTraceState model) {
48 // It's assumed to have one instance of this class per Trace
49 this.traceStateModel = model;
50 }
51
52 // ========================================================================
53 // Methods
54 // =======================================================================
55 /**
56 * Initialised by manager, any time a JniTrace selection is updated
57 *
58 * @param trace
59 * @param log
60 *
61 */
62 void init(JniTrace trace, TmfTrace log) throws LttngStateException {
63 if (trace == null || log == null) {
64 StringBuilder sb = new StringBuilder(
65 "No JniTrace object available, trace must be set via method setTrace(JniTrace trace)");
66 throw new LttngStateException(sb.toString());
67 }
68
69 // this.trace = trace;
70 ILttngStateInputRef ref = new LttngStateInputRef(trace, log);
71 this.traceStateModel.init(ref);
72 }
73
74
75 void processEvent(TmfEvent tmfEvent) /* throws LttngStateException */{
76 if (tmfEvent == null) {
77 return;
78 }
79
80 if (!(tmfEvent instanceof LttngEvent)) {
81 TraceDebug
82 .debug("The event received is not an instance of LttngEvent and can not be processed");
83 }
84
85 LttngEvent trcEvent = (LttngEvent) tmfEvent;
86 // LttngEventField[] fields = ((LttngEventContent)trcEvent.getContent()).getFields();
87
88 if (trcEvent != null) {
89 String inEventName = trcEvent.getMarkerName();
90 // String inChannel = trcEvent.getChannelName();
91 // TraceDebug.debug("Event: " + inEventName);
92
93 // Check if the received event is a transition state event
94 // TODO: Remove temporarily to allow other events to go to the
95 // statistics view.
96 // Needs restructuring.
97 // Events eventStruct = StateStrings.getInstance()
98 // .getStateTransEventMap().get(inEventName);
99 // if (eventStruct != null) {
100 // String expectedChannel = eventStruct.getParent().getInName();
101 // check that received channel is the expected channel in the
102 // structure
103 // if (inChannel.equals(expectedChannel)) {
104 // Notify the before Handlers
105 Set<AbsEventProcessorFactory> handlerRegister = EventProcessorProxy
106 .getInstance().getProcessingFactories();
107
108 // Notify the state BEFORE update handlers
109 for (Iterator<AbsEventProcessorFactory> iterator = handlerRegister
110 .iterator(); iterator.hasNext();) {
111 AbsEventProcessorFactory handlerRegistry = (AbsEventProcessorFactory) iterator
112 .next();
113 IEventProcessing handler = handlerRegistry
114 .getBeforeProcessor(inEventName);
115 if (handler != null) {
116 // process State Update
117 handler.process(trcEvent, traceStateModel);
118 }
119
120 }
121
122 // Notify the STATE UPDATE handlers
123 // Only one state update expected
124 for (Iterator<AbsEventProcessorFactory> iterator = handlerRegister
125 .iterator(); iterator.hasNext();) {
126 AbsEventProcessorFactory handlerRegistry = (AbsEventProcessorFactory) iterator
127 .next();
128 IEventProcessing handler = handlerRegistry
129 .getStateUpdaterProcessor(inEventName);
130 if (handler != null) {
131 // process State Update
132 handler.process(trcEvent, traceStateModel);
133 }
134
135 }
136
137 // Notify the AFTER update handlers
138 for (Iterator<AbsEventProcessorFactory> iterator = handlerRegister
139 .iterator(); iterator.hasNext();) {
140 AbsEventProcessorFactory handlerRegistry = (AbsEventProcessorFactory) iterator
141 .next();
142 IEventProcessing handler = handlerRegistry
143 .getAfterProcessor(inEventName);
144 if (handler != null) {
145 // process State Update
146 handler.process(trcEvent, traceStateModel);
147 }
148 }
149
150 // } else {
151 // StringBuilder sb = new StringBuilder(
152 // "Unexpected channel received for: " + inEventName
153 // + ", channel rec: " + inChannel
154 // + " chanel expected: " + expectedChannel);
155 // TraceDebug.debug(sb.toString());
156 // }
157 // }
158 }
159 }
160
161 /**
162 * Used for troubleshooting when debug mode is on
163 *
164 * @return
165 */
166 Set<String> getEventsNotHandled() {
167 return eventsNotHandled;
168 }
169
170 /**
171 * Needed for checkpoint
172 *
173 * @param LttngTraceState
174 */
175 public LttngTraceState getTraceStateModel() {
176 return traceStateModel;
177 }
178
179 /**
180 * Needed for checkpoint
181 *
182 * @param LttngTraceState
183 */
184 public void setTraceStateModel(LttngTraceState newTraceState) {
185 traceStateModel = newTraceState;
186 }
187
188 /**
189 * Needed for verification purposes
190 *
191 * @param listener
192 */
193 void registerListener(IEventProcessing listener) {
194 this.listeners.add(listener);
195 }
196
197 /**
198 * Needed for verification purposes
199 *
200 * @param listener
201 */
202 void deregisterListener(IEventProcessing listener) {
203 this.listeners.remove(listener);
204 }
205 }
This page took 0.03524 seconds and 5 git commands to generate.