tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / component / TmfComponent.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Add interface for broadcasting signals asynchronously
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.core.component;
15
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
18 import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
19 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
20
21 /**
22 * This is the base class of the TMF components.
23 * <p>
24 * Currently, it only addresses the inter-component signaling.
25 *
26 * @author Francois Chouinard
27 */
28 public abstract class TmfComponent implements ITmfComponent {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 private @NonNull String fName = ""; //$NON-NLS-1$
35
36 // ------------------------------------------------------------------------
37 // Constructor
38 // ------------------------------------------------------------------------
39
40 /**
41 * Default constructor. To be used in conjunction with init()
42 */
43 public TmfComponent() {
44 this(""); //$NON-NLS-1$
45 }
46
47 /**
48 * Perform component initialization and register it as a signal listener.
49 * Need to be called when the default constructor was used.
50 *
51 * @param name
52 * the component name
53 */
54 public void init(String name) {
55 String cmpName = name;
56 if (cmpName == null) {
57 cmpName = ""; //$NON-NLS-1$
58 }
59 TmfCoreTracer.traceComponent(cmpName, "created"); //$NON-NLS-1$
60 fName = cmpName;
61 TmfSignalManager.register(this);
62 }
63
64 /**
65 * The standard constructor
66 *
67 * @param name
68 * the component name
69 */
70 public TmfComponent(String name) {
71 init(name);
72 }
73
74 /**
75 * The copy constructor
76 *
77 * @param other
78 * the other component
79 */
80 public TmfComponent(TmfComponent other) {
81 init(other.fName);
82 }
83
84 // ------------------------------------------------------------------------
85 // Getters/setters
86 // ------------------------------------------------------------------------
87
88 @Override
89 public @NonNull String getName() {
90 return fName;
91 }
92
93 /**
94 * @param name
95 * the new component name
96 */
97 protected void setName(@NonNull String name) {
98 fName = name;
99 }
100
101 // ------------------------------------------------------------------------
102 // ITmfComponent
103 // ------------------------------------------------------------------------
104
105 @Override
106 public void dispose() {
107 TmfSignalManager.deregister(this);
108 TmfCoreTracer.traceComponent(fName, "disposed"); //$NON-NLS-1$
109 }
110
111 @Override
112 public void broadcast(TmfSignal signal) {
113 TmfSignalManager.dispatchSignal(signal);
114 }
115
116 @Override
117 public void broadcastAsync(TmfSignal signal) {
118 TmfSignalManager.dispatchSignalAsync(signal);
119 }
120 }
This page took 0.035994 seconds and 5 git commands to generate.