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
.timestamp
.ITmfTimestamp
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
22 * Base class for graph providers. It implements most methods common for all
25 * @author Geneviève Bastien
26 * @author Francis Giraldeau
28 public abstract class AbstractTmfGraphProvider
implements ITmfGraphProvider
{
30 private final ITmfTrace fTrace
;
32 private final List
<ITraceEventHandler
> fHandlers
;
34 private boolean fGraphAssigned
;
36 /** Graph in which to insert the state changes */
37 private @Nullable TmfGraph fGraph
= null;
40 * Instantiate a new graph builder plugin.
45 * Name given to this state change input. Only used internally.
47 public AbstractTmfGraphProvider(ITmfTrace trace
, String id
) {
49 fGraphAssigned
= false;
50 fHandlers
= new ArrayList
<>();
54 public ITmfTrace
getTrace() {
59 public long getStartTime() {
60 return fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
64 public void assignTargetGraph(TmfGraph graph
) {
66 fGraphAssigned
= true;
70 public @Nullable TmfGraph
getAssignedGraph() {
75 public void processEvent(ITmfEvent event
) {
76 /* Make sure the target graph has been assigned */
77 if (!fGraphAssigned
) {
84 public void dispose() {
85 fGraphAssigned
= false;
94 * Internal event handler, using the phase's handlers
99 protected void eventHandle(ITmfEvent event
) {
100 for (ITraceEventHandler handler
: fHandlers
) {
101 handler
.handleEvent(event
);
106 public void handleCancel() {
110 * Register a handler to a series of events
113 * The trace event handler
115 public void registerHandler(ITraceEventHandler handler
) {
116 fHandlers
.add(handler
);