tmf.all: use ITmfTimestamp#toNanos when possible
[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.trace.ITmfTrace;
19
20 /**
21 * Base class for graph providers. It implements most methods common for all
22 * graph builder.
23 *
24 * @author Geneviève Bastien
25 * @author Francis Giraldeau
26 */
27 public abstract class AbstractTmfGraphProvider implements ITmfGraphProvider {
28
29 private final ITmfTrace fTrace;
30
31 private final List<ITraceEventHandler> fHandlers;
32
33 private boolean fGraphAssigned;
34
35 /** Graph in which to insert the state changes */
36 private @Nullable TmfGraph fGraph = null;
37
38 /**
39 * Instantiate a new graph builder plugin.
40 *
41 * @param trace
42 * The trace
43 * @param id
44 * Name given to this state change input. Only used internally.
45 */
46 public AbstractTmfGraphProvider(ITmfTrace trace, String id) {
47 this.fTrace = trace;
48 fGraphAssigned = false;
49 fHandlers = new ArrayList<>();
50 }
51
52 @Override
53 public ITmfTrace getTrace() {
54 return fTrace;
55 }
56
57 @Override
58 public long getStartTime() {
59 return fTrace.getStartTime().toNanos();
60 }
61
62 @Override
63 public void assignTargetGraph(TmfGraph graph) {
64 fGraph = graph;
65 fGraphAssigned = true;
66 }
67
68 @Override
69 public @Nullable TmfGraph getAssignedGraph() {
70 return fGraph;
71 }
72
73 @Override
74 public void processEvent(ITmfEvent event) {
75 /* Make sure the target graph has been assigned */
76 if (!fGraphAssigned) {
77 return;
78 }
79 eventHandle(event);
80 }
81
82 @Override
83 public void dispose() {
84 fGraphAssigned = false;
85 fGraph = null;
86 }
87
88 @Override
89 public void done() {
90 }
91
92 /**
93 * Internal event handler, using the phase's handlers
94 *
95 * @param event
96 * The event
97 */
98 protected void eventHandle(ITmfEvent event) {
99 for (ITraceEventHandler handler : fHandlers) {
100 handler.handleEvent(event);
101 }
102 }
103
104 @Override
105 public void handleCancel() {
106 }
107
108 /**
109 * Register a handler to a series of events
110 *
111 * @param handler
112 * The trace event handler
113 */
114 public void registerHandler(ITraceEventHandler handler) {
115 fHandlers.add(handler);
116 }
117
118 }
This page took 0.044964 seconds and 6 git commands to generate.