1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.graph
.core
.building
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
.trace
.ITmfTrace
;
21 * Base class for graph providers. It implements most methods common for all
24 * @author Geneviève Bastien
25 * @author Francis Giraldeau
27 public abstract class AbstractTmfGraphProvider
implements ITmfGraphProvider
{
29 private final ITmfTrace fTrace
;
31 private final List
<ITraceEventHandler
> fHandlers
;
33 private boolean fGraphAssigned
;
35 /** Graph in which to insert the state changes */
36 private @Nullable TmfGraph fGraph
= null;
39 * Instantiate a new graph builder plugin.
44 * Name given to this state change input. Only used internally.
46 public AbstractTmfGraphProvider(ITmfTrace trace
, String id
) {
48 fGraphAssigned
= false;
49 fHandlers
= new ArrayList
<>();
53 public ITmfTrace
getTrace() {
58 public long getStartTime() {
59 return fTrace
.getStartTime().toNanos();
63 public void assignTargetGraph(TmfGraph graph
) {
65 fGraphAssigned
= true;
69 public @Nullable TmfGraph
getAssignedGraph() {
74 public void processEvent(ITmfEvent event
) {
75 /* Make sure the target graph has been assigned */
76 if (!fGraphAssigned
) {
83 public void dispose() {
84 fGraphAssigned
= false;
93 * Internal event handler, using the phase's handlers
98 protected void eventHandle(ITmfEvent event
) {
99 for (ITraceEventHandler handler
: fHandlers
) {
100 handler
.handleEvent(event
);
105 public void handleCancel() {
109 * Register a handler to a series of events
112 * The trace event handler
114 public void registerHandler(ITraceEventHandler handler
) {
115 fHandlers
.add(handler
);