4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 import java
.util
.Collection
;
27 import java
.util
.LinkedList
;
28 import java
.util
.Iterator
;
29 import android
.util
.Log
;
32 * An #AndroidPort implementation that combines multiple #AndroidPort
35 class MultiPort
implements AndroidPort
, InputListener
{
36 private InputListener listener
;
38 private static final String TAG
= "XCSoar";
40 private Collection
<AndroidPort
> ports
= new LinkedList
<AndroidPort
>();
41 private boolean error
= false;
43 private synchronized int checkValid() {
44 boolean ready
= false, limbo
= false;
46 for (Iterator
<AndroidPort
> i
= ports
.iterator(); i
.hasNext();) {
47 AndroidPort port
= i
.next();
49 switch (port
.getState()) {
55 Log
.i(TAG
, "Bluetooth disconnect from " + port
);
71 } else if (limbo
|| !error
) {
78 public synchronized void add(AndroidPort port
) {
83 port
.setListener(this);
86 @Override public void setListener(InputListener _listener
) {
90 @Override public synchronized void close() {
93 for (AndroidPort port
: ports
)
99 @Override public int getState() {
103 @Override public boolean drain() {
104 // XXX not implemented
108 @Override public synchronized int getBaudRate() {
109 // XXX not implemented
113 @Override public boolean setBaudRate(int baud
) {
114 // XXX not implemented
118 @Override public synchronized int write(byte[] data
, int length
) {
121 for (Iterator
<AndroidPort
> i
= ports
.iterator(); i
.hasNext();) {
122 AndroidPort port
= i
.next();
123 int nbytes
= port
.write(data
, length
);
124 if (nbytes
< 0 && port
.getState() == STATE_FAILED
) {
128 } else if (nbytes
> result
)
135 @Override public void dataReceived(byte[] data
, int length
) {
136 InputListener l
= listener
;
138 l
.dataReceived(data
, length
);