|
| 1 | +/* |
| 2 | + * This file is part of Arduino. |
| 3 | + * |
| 4 | + * Arduino is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + * |
| 18 | + * As a special exception, you may use this file as part of a free software |
| 19 | + * library without restriction. Specifically, if other files instantiate |
| 20 | + * templates or use macros or inline functions from this file, or you compile |
| 21 | + * this file and link it with other files to produce an executable, this |
| 22 | + * file does not by itself cause the resulting executable to be covered by |
| 23 | + * the GNU General Public License. This exception does not however |
| 24 | + * invalidate any other reasons why the executable file might be covered by |
| 25 | + * the GNU General Public License. |
| 26 | + * |
| 27 | + * Copyright 2018 Arduino SA (http://www.arduino.cc/) |
| 28 | + */ |
| 29 | + |
| 30 | +package cc.arduino.packages.discoverers; |
| 31 | + |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.List; |
| 34 | + |
| 35 | +import cc.arduino.packages.BoardPort; |
| 36 | +import cc.arduino.packages.Discovery; |
| 37 | +import processing.app.legacy.PApplet; |
| 38 | + |
| 39 | +public class PluggableDiscovery implements Discovery { |
| 40 | + |
| 41 | + private String discoveryName; |
| 42 | + |
| 43 | + public PluggableDiscovery(String discoveryName, String[] cmd) { |
| 44 | + this.discoveryName = discoveryName; |
| 45 | + System.out.println("Starting: " + PApplet.join(cmd, " ")); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void run() { |
| 50 | + // TODO this method is started as a new thread, it will constantly |
| 51 | + // communicate with the discovery tool and keep track of the discovered |
| 52 | + // port to be returned from listDiscoveredBoard() |
| 53 | + try { |
| 54 | + start(); |
| 55 | + while (true) { // TODO: Find a better way to terminate discovery |
| 56 | + System.out.println(discoveryName + ": looping..."); |
| 57 | + Thread.sleep(500); |
| 58 | + } |
| 59 | + // stop(); |
| 60 | + } catch (InterruptedException e) { |
| 61 | + e.printStackTrace(); |
| 62 | + } catch (Exception e) { |
| 63 | + e.printStackTrace(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public void start() throws Exception { |
| 69 | + // TODO send a START_SYNC command to the discovery tool |
| 70 | + // or fallback to START if not available |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public void stop() throws Exception { |
| 75 | + // TODO send a STOP to the discovery |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public List<BoardPort> listDiscoveredBoards() { |
| 80 | + // TODO return the ports discovered so far |
| 81 | + final List<BoardPort> empty = new ArrayList<>(); |
| 82 | + return empty; |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public List<BoardPort> listDiscoveredBoards(boolean complete) { |
| 87 | + // XXX: parameter "complete "is really needed? |
| 88 | + // should be checked on all existing discoveries |
| 89 | + |
| 90 | + // TODO |
| 91 | + final List<BoardPort> empty = new ArrayList<>(); |
| 92 | + return empty; |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public String toString() { |
| 97 | + return discoveryName; |
| 98 | + } |
| 99 | +} |
0 commit comments