linux: make KernelStateProvider handle aggregate prev_states of sched_switch
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.graph.core / src / org / eclipse / tracecompass / analysis / graph / core / building / AbstractTmfGraphProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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
10 package org.eclipse.tracecompass.analysis.graph.core.building;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
17 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
18 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
19 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
20
21 /**
22 * Base class for graph providers. It implements most methods common for all
23 * graph builder.
24 *
25 * @author Geneviève Bastien
26 * @author Francis Giraldeau
27 */
28 public abstract class AbstractTmfGraphProvider implements ITmfGraphProvider {
29
30 private final ITmfTrace fTrace;
31
32 private final List<ITraceEventHandler> fHandlers;
33
34 private boolean fGraphAssigned;
35
36 /** Graph in which to insert the state changes */
37 private @Nullable TmfGraph fGraph = null;
38
39 /**
40 * Instantiate a new graph builder plugin.
41 *
42 * @param trace
43 * The trace
44 * @param id
45 * Name given to this state change input. Only used internally.
46 */
47 public AbstractTmfGraphProvider(ITmfTrace trace, String id) {
48 this.fTrace = trace;
49 fGraphAssigned = false;
50 fHandlers = new ArrayList<>();
51 }
52
53 @Override
54 public ITmfTrace getTrace() {
55 return fTrace;
56 }
57
58 @Override
59 public long getStartTime() {
60 return fTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
61 }
62
63 @Override
64 public void assignTargetGraph(TmfGraph graph) {
65 fGraph = graph;
66 fGraphAssigned = true;
67 }
68
69 @Override
70 public @Nullable TmfGraph getAssignedGraph() {
71 return fGraph;
72 }
73
74 @Override
75 public void processEvent(ITmfEvent event) {
76 /* Make sure the target graph has been assigned */
77 if (!fGraphAssigned) {
78 return;
79 }
80 eventHandle(event);
81 }
82
83 @Override
84 public void dispose() {
85 fGraphAssigned = false;
86 fGraph = null;
87 }
88
89 @Override
90 public void done() {
91 }
92
93 /**
94 * Internal event handler, using the phase's handlers
95 *
96 * @param event
97 * The event
98 */
99 protected void eventHandle(ITmfEvent event) {
100 for (ITraceEventHandler handler : fHandlers) {
101 handler.handleEvent(event);
102 }
103 }
104
105 @Override
106 public void handleCancel() {
107 }
108
109 /**
110 * Register a handler to a series of events
111 *
112 * @param handler
113 * The trace event handler
114 */
115 public void registerHandler(ITraceEventHandler handler) {
116 fHandlers.add(handler);
117 }
118
119 }
This page took 0.038531 seconds and 5 git commands to generate.