From e029acc6990d3476d68bab0a68a03945d795b364 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 1 Oct 2018 13:33:19 -0700 Subject: [PATCH] Add PluggableDiscoveryMessage for BoardPort change metadata --- .../discoverers/PluggableDiscovery.java | 17 ++++---- .../PluggableDiscoveryMessage.java | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscoveryMessage.java diff --git a/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java index d4967c257..d2c09b874 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java @@ -72,17 +72,17 @@ public class PluggableDiscovery implements Discovery { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); while (program != null && program.isAlive()) { - BoardPort port = mapper.readValue(parser, BoardPort.class); - if (port != null) { + PluggableDiscoveryMessage msg = mapper.readValue(parser, PluggableDiscoveryMessage.class); + if (msg != null) { System.out.println(discoveryName + ": received json"); - String address = port.getAddress(); - if (address != null) { - if (address.equals("Error: START_SYNC not supported")) { + String event = msg.getEventType(); + if (event != null) { + if (event.equals("Error: START_SYNC not supported")) { if (pollingThread == null) { startPolling(); } } else { - update(port); + update(msg); } } } @@ -158,7 +158,7 @@ public class PluggableDiscovery implements Discovery { } } - private synchronized void update(BoardPort port) { + private synchronized void update(PluggableDiscoveryMessage port) { // Update the list of discovered ports, which may involve // adding a new port, replacing the info for a previously // discovered port, or removing a port. This function @@ -166,13 +166,14 @@ public class PluggableDiscovery implements Discovery { // avoid changing the list while it's being accessed by // another thread. String address = port.getAddress(); + if (address == null) return; // address required for "add" & "remove" for (BoardPort bp : portList) { if (address.equals(bp.getAddress())) { // if address already on the list, discard old info portList.remove(bp); } } - if (port.isOnline()) { + if (port.getEventType().equals("add")) { if (port.getLabel() == null) { // if no label, use address port.setLabel(address); diff --git a/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscoveryMessage.java b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscoveryMessage.java new file mode 100644 index 000000000..270739286 --- /dev/null +++ b/arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscoveryMessage.java @@ -0,0 +1,39 @@ +/* + * This file is part of Arduino. + * + * Arduino is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2018 Arduino SA (http://www.arduino.cc/) + */ + +package cc.arduino.packages.discoverers; +import cc.arduino.packages.BoardPort; + +public class PluggableDiscoveryMessage extends BoardPort { + private String eventType; // "add", "remove", "Error: START_SYNC not supported" + public String getEventType() { + return eventType; + } +} +