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 | * | |
8fd82db5 | 26 | * @author Francois Chouinard |
8c8bf09f ASL |
27 | */ |
28 | public abstract class TmfComponent implements ITmfComponent { | |
29 | ||
00641a97 FC |
30 | // ------------------------------------------------------------------------ |
31 | // Attributes | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
6d8922ce | 34 | private @NonNull String fName = ""; //$NON-NLS-1$ |
5500a7f0 | 35 | |
11252342 AM |
36 | // ------------------------------------------------------------------------ |
37 | // Constructor | |
38 | // ------------------------------------------------------------------------ | |
e31e01e8 | 39 | |
8fd82db5 FC |
40 | /** |
41 | * Default constructor. To be used in conjunction with init() | |
42 | */ | |
12c155f5 | 43 | public TmfComponent() { |
11252342 | 44 | this(""); //$NON-NLS-1$ |
12c155f5 FC |
45 | } |
46 | ||
8fd82db5 FC |
47 | /** |
48 | * Perform component initialization and register it as a signal listener. | |
49 | * Need to be called when the default constructor was used. | |
5500a7f0 | 50 | * |
11252342 AM |
51 | * @param name |
52 | * the component name | |
8fd82db5 | 53 | */ |
12c155f5 | 54 | public void init(String name) { |
6d8922ce GB |
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; | |
12c155f5 FC |
61 | TmfSignalManager.register(this); |
62 | } | |
63 | ||
11252342 AM |
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) { | |
00641a97 | 81 | init(other.fName); |
11252342 | 82 | } |
5500a7f0 | 83 | |
00641a97 | 84 | // ------------------------------------------------------------------------ |
8fd82db5 | 85 | // Getters/setters |
00641a97 FC |
86 | // ------------------------------------------------------------------------ |
87 | ||
8fd82db5 | 88 | @Override |
d40ddf8a | 89 | public @NonNull String getName() { |
8fd82db5 FC |
90 | return fName; |
91 | } | |
92 | ||
11252342 AM |
93 | /** |
94 | * @param name | |
95 | * the new component name | |
96 | */ | |
6d8922ce | 97 | protected void setName(@NonNull String name) { |
11252342 AM |
98 | fName = name; |
99 | } | |
100 | ||
101 | // ------------------------------------------------------------------------ | |
102 | // ITmfComponent | |
103 | // ------------------------------------------------------------------------ | |
104 | ||
105 | @Override | |
106 | public void dispose() { | |
107 | TmfSignalManager.deregister(this); | |
8b56808c | 108 | TmfCoreTracer.traceComponent(fName, "disposed"); //$NON-NLS-1$ |
11252342 AM |
109 | } |
110 | ||
111 | @Override | |
112 | public void broadcast(TmfSignal signal) { | |
113 | TmfSignalManager.dispatchSignal(signal); | |
114 | } | |
e31e01e8 | 115 | |
d91063d0 BH |
116 | @Override |
117 | public void broadcastAsync(TmfSignal signal) { | |
118 | TmfSignalManager.dispatchSignalAsync(signal); | |
119 | } | |
8c8bf09f | 120 | } |