Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / linuxtools / 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.linuxtools.tmf.core.component;
15
16 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
17 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
18 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
19
20 /**
21 * This is the base class of the TMF components.
22 * <p>
23 * Currently, it only addresses the inter-component signaling.
24 *
25 * @version 1.0
26 * @author Francois Chouinard
27 */
28 public abstract class TmfComponent implements ITmfComponent {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 private String fName;
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 TmfCoreTracer.traceComponent(this, "created"); //$NON-NLS-1$
56 fName = name;
57 TmfSignalManager.register(this);
58 }
59
60 /**
61 * The standard constructor
62 *
63 * @param name
64 * the component name
65 */
66 public TmfComponent(String name) {
67 init(name);
68 }
69
70 /**
71 * The copy constructor
72 *
73 * @param other
74 * the other component
75 */
76 public TmfComponent(TmfComponent other) {
77 init(other.fName);
78 }
79
80 // ------------------------------------------------------------------------
81 // Getters/setters
82 // ------------------------------------------------------------------------
83
84 @Override
85 public String getName() {
86 return fName;
87 }
88
89 /**
90 * @param name
91 * the new component name
92 */
93 protected void setName(String name) {
94 fName = name;
95 }
96
97 // ------------------------------------------------------------------------
98 // ITmfComponent
99 // ------------------------------------------------------------------------
100
101 @Override
102 public void dispose() {
103 TmfSignalManager.deregister(this);
104 TmfCoreTracer.traceComponent(this, "disposed"); //$NON-NLS-1$
105 }
106
107 @Override
108 public void broadcast(TmfSignal signal) {
109 TmfSignalManager.dispatchSignal(signal);
110 }
111
112 /**
113 * @since 3.0
114 */
115 @Override
116 public void broadcastAsync(TmfSignal signal) {
117 TmfSignalManager.dispatchSignalAsync(signal);
118 }
119 }
This page took 0.041336 seconds and 5 git commands to generate.