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