Abstract base class to aid the real implementations (Bluetooth, IOIO).
| 31 | * IOIO). |
| 32 | */ |
| 33 | abstract class AbstractAndroidPort implements AndroidPort { |
| 34 | private final String name; |
| 35 | private PortListener portListener; |
| 36 | private InputListener inputListener; |
| 37 | private InputThread input; |
| 38 | private OutputThread output; |
| 39 | |
| 40 | protected AbstractAndroidPort(String _name) { |
| 41 | name = _name; |
| 42 | } |
| 43 | |
| 44 | @Override public String toString() { |
| 45 | return name; |
| 46 | } |
| 47 | |
| 48 | private synchronized InputThread stealInput() { |
| 49 | InputThread i = input; |
| 50 | input = null; |
| 51 | return i; |
| 52 | } |
| 53 | |
| 54 | private synchronized OutputThread stealOutput() { |
| 55 | OutputThread o = output; |
| 56 | output = null; |
| 57 | return o; |
| 58 | } |
| 59 | |
| 60 | protected synchronized void set(InputStream _input, OutputStream _output) { |
| 61 | input = new InputThread(name, inputListener, _input); |
| 62 | output = new OutputThread(name, _output); |
| 63 | output.setTimeout(5000); |
| 64 | stateChanged(); |
| 65 | } |
| 66 | |
| 67 | protected void setWriteTimeout(int timeout_ms) { |
| 68 | output.setTimeout(timeout_ms); |
| 69 | } |
| 70 | |
| 71 | @Override public void setListener(PortListener _listener) { |
| 72 | portListener = _listener; |
| 73 | } |
| 74 | |
| 75 | @Override public void setInputListener(InputListener _listener) { |
| 76 | inputListener = _listener; |
| 77 | if (input != null) |
| 78 | input.setListener(_listener); |
| 79 | } |
| 80 | |
| 81 | @Override public void close() { |
| 82 | InputThread i = stealInput(); |
| 83 | if (i != null) |
| 84 | i.close(); |
| 85 | |
| 86 | OutputThread o = stealOutput(); |
| 87 | if (o != null) |
| 88 | o.close(); |
| 89 | |
| 90 | stateChanged(); |
nothing calls this directly
no outgoing calls
no test coverage detected