Skip to content

Commit 0745a52

Browse files
committed
Revert "Various NetworkTables fixes (wpilibsuite#815)"
This reverts commit 60e3ba1.
1 parent 6649296 commit 0745a52

File tree

5 files changed

+24
-65
lines changed

5 files changed

+24
-65
lines changed

api/src/main/java/edu/wpi/first/shuffleboard/api/util/FxUtils.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController;
55

66
import java.io.IOException;
7-
import java.time.Duration;
8-
import java.time.temporal.ChronoUnit;
97
import java.util.List;
108
import java.util.Optional;
119
import java.util.concurrent.CompletableFuture;
12-
import java.util.concurrent.Executors;
13-
import java.util.concurrent.ScheduledExecutorService;
14-
import java.util.concurrent.TimeUnit;
1510
import java.util.function.Function;
1611

1712
import javafx.application.Platform;
@@ -43,14 +38,6 @@ public final class FxUtils {
4338

4439
private static final Object FX_CONTROLLER_KEY = new Object();
4540

46-
private static final ScheduledExecutorService laterScheduler =
47-
Executors.newSingleThreadScheduledExecutor(runnable -> {
48-
var thread = new Thread(runnable);
49-
thread.setDaemon(true);
50-
thread.setName("Shuffleboard Run Later Scheduler");
51-
return thread;
52-
});
53-
5441
private FxUtils() {
5542
throw new UnsupportedOperationException("This is a utility class!");
5643
}
@@ -81,15 +68,6 @@ public static CompletableFuture<Boolean> runOnFxThread(Runnable task) {
8168
return future;
8269
}
8370

84-
/**
85-
* Runs a task on the platform thread at some point in the future.
86-
* @param task the task to run
87-
* @param delay how far in the future the task should run
88-
*/
89-
public static void runLater(Runnable task, Duration delay) {
90-
laterScheduler.schedule(() -> runOnFxThread(task), delay.get(ChronoUnit.NANOS), TimeUnit.NANOSECONDS);
91-
}
92-
9371
/**
9472
* Binds a property to the value of an entry in a map.
9573
*

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/TabGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public void start() {
102102
});
103103

104104
metadataSubscriber =
105-
new MultiSubscriber(inst, new String[] {METADATA_TABLE_NAME + "/"});
105+
new MultiSubscriber(inst, new String[] {METADATA_TABLE_NAME + "/"}, PubSubOption.hidden(true));
106106
metadataListener = inst.addListener(
107107
metadataSubscriber,
108108
EnumSet.of(NetworkTableEvent.Kind.kValueAll, NetworkTableEvent.Kind.kImmediate),
109109
this::metadataChanged);
110-
dataSubscriber = new MultiSubscriber(inst, new String[] {ROOT_TABLE_NAME + "/"});
110+
dataSubscriber = new MultiSubscriber(inst, new String[] {ROOT_TABLE_NAME + "/"}, PubSubOption.hidden(true));
111111
dataListener = inst.addListener(
112112
dataSubscriber,
113113
EnumSet.of(NetworkTableEvent.Kind.kValueAll, NetworkTableEvent.Kind.kImmediate),

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/sources/CompositeNetworkTableSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public CompositeNetworkTableSource(String tableName, ComplexDataType<D> dataType
4747
setData(dataType.getDefaultValue());
4848

4949
setTableListener((key, event) -> {
50-
String relativeKey = NetworkTable.basenameKey(key);
50+
String relativeKey = NetworkTable.normalizeKey(key.substring(path.length() + 1), false);
5151
if (event.is(NetworkTableEvent.Kind.kUnpublish)) {
5252
backingMap.remove(relativeKey);
5353
} else if (event.valueData != null) {

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/sources/NetworkTableSource.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import edu.wpi.first.networktables.NetworkTableInstance;
1717
import edu.wpi.first.networktables.PubSubOption;
1818

19-
import java.util.Arrays;
2019
import java.util.EnumSet;
2120
import java.util.Map;
2221
import java.util.Optional;
@@ -73,19 +72,7 @@ protected final void setTableListener(TableListener listener) {
7372
}
7473
setConnected(true);
7574
if (isSingular()) {
76-
// Handle leading slashes. Topic names are exact and do no normalization
77-
String topicName;
78-
if (Arrays.stream(inst.getTopicInfo()).anyMatch(t -> t.name.equals(fullTableKey))) {
79-
topicName = fullTableKey;
80-
} else {
81-
if (fullTableKey.startsWith("/")) {
82-
topicName = NetworkTable.normalizeKey(fullTableKey, false);
83-
} else {
84-
topicName = NetworkTable.normalizeKey(fullTableKey, true);
85-
}
86-
}
87-
88-
singleSub = inst.getTopic(topicName).genericSubscribe(PubSubOption.hidden(false), PubSubOption.sendAll(true));
75+
singleSub = inst.getTopic(fullTableKey).genericSubscribe(PubSubOption.hidden(false), PubSubOption.sendAll(true));
8976
listenerUid = inst.addListener(
9077
singleSub,
9178
EnumSet.of(
@@ -211,19 +198,24 @@ public static void removeAllCachedSources() {
211198
public static DataSource<?> forKey(String fullTableKey) {
212199
String key = NetworkTable.normalizeKey(fullTableKey, false);
213200
final String uri = NetworkTableSourceType.getInstance().toUri(key);
214-
return sources.computeIfAbsent(uri, __ -> {
215-
DataType<?> lookup = NetworkTableUtils.dataTypeForEntry(key);
216-
if (lookup == DataTypes.Unknown) {
217-
// No known data type, fall back to generic map data
218-
lookup = DataTypes.Map;
219-
}
220-
if (lookup.isComplex()) {
201+
if (NetworkTableUtils.rootTable.containsKey(key)) {
202+
// Key-value pair
203+
return sources.computeIfAbsent(uri, __ ->
204+
new SingleKeyNetworkTableSource<>(NetworkTableUtils.rootTable, key,
205+
NetworkTableUtils.dataTypeForEntry(key)));
206+
}
207+
if (NetworkTableUtils.rootTable.containsSubTable(key) || key.isEmpty()) {
208+
// Composite
209+
return sources.computeIfAbsent(uri, __ -> {
210+
DataType<?> lookup = NetworkTableUtils.dataTypeForEntry(key);
211+
if (lookup == DataTypes.Unknown) {
212+
// No known data type, fall back to generic map data
213+
lookup = DataTypes.Map;
214+
}
221215
return new CompositeNetworkTableSource<>(key, (ComplexDataType<?>) lookup);
222-
} else {
223-
return new SingleKeyNetworkTableSource<>(NetworkTableUtils.rootTable, key,
224-
NetworkTableUtils.dataTypeForEntry(key));
225-
}
226-
});
216+
});
217+
}
218+
return DataSource.none();
227219
}
228220

229221
/**

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/sources/NetworkTableSourceType.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.HashMap;
2727
import java.util.List;
2828

29-
import java.time.Duration;
3029
import java.util.Map;
3130
import javafx.application.Platform;
3231
import javafx.collections.FXCollections;
@@ -82,10 +81,7 @@ public NetworkTableSourceType(NetworkTablesPlugin plugin) {
8281
topic.getInfo(),
8382
null,
8483
null,
85-
null
86-
),
87-
true
88-
);
84+
null));
8985
}
9086
}
9187
});
@@ -97,7 +93,7 @@ public NetworkTableSourceType(NetworkTablesPlugin plugin) {
9793
EnumSet.of(
9894
NetworkTableEvent.Kind.kImmediate,
9995
NetworkTableEvent.Kind.kTopic),
100-
event -> AsyncUtils.runAsync(() -> handleEvent(event, true)));
96+
event -> AsyncUtils.runAsync(() -> handleEvent(event)));
10197
}
10298

10399
@Override
@@ -195,16 +191,9 @@ public String toUri(String sourceName) {
195191
return super.toUri(NetworkTable.normalizeKey(sourceName));
196192
}
197193

198-
private void handleEvent(NetworkTableEvent event, boolean allowDeferral) {
194+
private void handleEvent(NetworkTableEvent event) {
199195
final boolean delete = event.is(NetworkTableEvent.Kind.kUnpublish);
200196
final TopicInfo topicInfo = event.topicInfo;
201-
202-
if (!topicInfo.name.endsWith("/.type") && allowDeferral) {
203-
// Defer later to avoid race conditions where type metadata is not received first
204-
FxUtils.runLater(() -> handleEvent(event, false), Duration.ofMillis(50));
205-
return;
206-
}
207-
208197
if (topicInfo.name.endsWith("/.type") && !delete) {
209198
// Got type metadata for composite data
210199
// Remove trailing "/.type"

0 commit comments

Comments
 (0)