diff options
author | Mike Lockwood <lockwood@google.com> | 2015-03-04 14:50:39 -0800 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2015-03-04 20:38:37 -0800 |
commit | 3b7664589be22ddad34b72e11ced937d48660ebb (patch) | |
tree | 0ba58e00c256b3545ae49b838831d3c8d7b4aca5 /media | |
parent | 20821ecbe81ba52b260ae232096bc2bfb3e92ad0 (diff) | |
download | frameworks_base-3b7664589be22ddad34b72e11ced937d48660ebb.zip frameworks_base-3b7664589be22ddad34b72e11ced937d48660ebb.tar.gz frameworks_base-3b7664589be22ddad34b72e11ced937d48660ebb.tar.bz2 |
Make MidiSender and MidiReceiver abstract classes, rename MidiReceiver.post() to receive()
Change-Id: I1cef3bd48ca0acf2968c9de223f78445f3434404
Diffstat (limited to 'media')
6 files changed, 32 insertions, 42 deletions
diff --git a/media/java/android/media/midi/MidiDeviceServer.java b/media/java/android/media/midi/MidiDeviceServer.java index 24ef528..87fb3c5 100644 --- a/media/java/android/media/midi/MidiDeviceServer.java +++ b/media/java/android/media/midi/MidiDeviceServer.java @@ -85,10 +85,10 @@ public final class MidiDeviceServer implements Closeable { outputPort.connect(new MidiReceiver() { @Override - public void post(byte[] msg, int offset, int count, long timestamp) + public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { try { - inputPortReceviver.post(msg, offset, count, timestamp); + inputPortReceviver.receive(msg, offset, count, timestamp); } catch (IOException e) { IoUtils.closeQuietly(mInputPortOutputPorts[portNumberF]); mInputPortOutputPorts[portNumberF] = null; @@ -125,10 +125,10 @@ public final class MidiDeviceServer implements Closeable { final MidiSender sender = mOutputPortDispatchers[portNumber].getSender(); sender.connect(new MidiReceiver() { @Override - public void post(byte[] msg, int offset, int count, long timestamp) + public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { try { - inputPort.post(msg, offset, count, timestamp); + inputPort.receive(msg, offset, count, timestamp); } catch (IOException e) { IoUtils.closeQuietly(inputPort); sender.disconnect(this); diff --git a/media/java/android/media/midi/MidiDispatcher.java b/media/java/android/media/midi/MidiDispatcher.java index 165061f..b2d8b6f 100644 --- a/media/java/android/media/midi/MidiDispatcher.java +++ b/media/java/android/media/midi/MidiDispatcher.java @@ -24,12 +24,12 @@ import java.util.ArrayList; * This class subclasses {@link MidiReceiver} and dispatches any data it receives * to its receiver list. Any receivers that throw an exception upon receiving data will * be automatically removed from the receiver list, but no IOException will be returned - * from the dispatcher's {@link #post} in that case. + * from the dispatcher's {@link #receive} in that case. * * CANDIDATE FOR PUBLIC API * @hide */ -public class MidiDispatcher implements MidiReceiver { +public class MidiDispatcher extends MidiReceiver { private final ArrayList<MidiReceiver> mReceivers = new ArrayList<MidiReceiver>(); @@ -71,12 +71,12 @@ public class MidiDispatcher implements MidiReceiver { } @Override - public void post(byte[] msg, int offset, int count, long timestamp) throws IOException { + public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { synchronized (mReceivers) { for (int i = 0; i < mReceivers.size(); ) { MidiReceiver receiver = mReceivers.get(i); try { - receiver.post(msg, offset, count, timestamp); + receiver.receive(msg, offset, count, timestamp); i++; // increment only on success. on failure we remove the receiver // so i should not be incremented } catch (IOException e) { diff --git a/media/java/android/media/midi/MidiInputPort.java b/media/java/android/media/midi/MidiInputPort.java index 9ded0b1..fb70e89 100644 --- a/media/java/android/media/midi/MidiInputPort.java +++ b/media/java/android/media/midi/MidiInputPort.java @@ -30,12 +30,12 @@ import java.io.IOException; * CANDIDATE FOR PUBLIC API * @hide */ -public class MidiInputPort implements MidiReceiver, Closeable { +public class MidiInputPort extends MidiReceiver implements Closeable { private final int mPortNumber; private final FileOutputStream mOutputStream; - // buffer to use for sending messages out our output stream + // buffer to use for sending data out our output stream private final byte[] mBuffer = new byte[MidiPortImpl.MAX_PACKET_SIZE]; /* package */ MidiInputPort(ParcelFileDescriptor pfd, int portNumber) { @@ -52,38 +52,27 @@ public class MidiInputPort implements MidiReceiver, Closeable { return mPortNumber; } - //FIXME - public void onIOException() { - } - /** - * Writes a MIDI message to the input port + * Writes MIDI data to the input port * - * @param msg byte array containing the message - * @param offset offset of first byte of the message in msg byte array - * @param count size of the message in bytes - * @param timestamp future time to post the message (based on + * @param msg byte array containing the data + * @param offset offset of first byte of the data in msg byte array + * @param count size of the data in bytes + * @param timestamp future time to post the data (based on * {@link java.lang.System#nanoTime} */ - public void post(byte[] msg, int offset, int count, long timestamp) throws IOException { + public void receive(byte[] msg, int offset, int count, long timestamp) throws IOException { assert(offset >= 0 && count >= 0 && offset + count <= msg.length); synchronized (mBuffer) { - try { - while (count > 0) { - int length = MidiPortImpl.packMessage(msg, offset, count, timestamp, mBuffer); - mOutputStream.write(mBuffer, 0, length); - int sent = MidiPortImpl.getMessageSize(mBuffer, length); - assert(sent >= 0 && sent <= length); + while (count > 0) { + int length = MidiPortImpl.packMessage(msg, offset, count, timestamp, mBuffer); + mOutputStream.write(mBuffer, 0, length); + int sent = MidiPortImpl.getMessageSize(mBuffer, length); + assert(sent >= 0 && sent <= length); - offset += sent; - count -= sent; - } - } catch (IOException e) { - IoUtils.closeQuietly(mOutputStream); - // report I/O failure - onIOException(); - throw e; + offset += sent; + count -= sent; } } } diff --git a/media/java/android/media/midi/MidiOutputPort.java b/media/java/android/media/midi/MidiOutputPort.java index 3efd03f..8b99e90 100644 --- a/media/java/android/media/midi/MidiOutputPort.java +++ b/media/java/android/media/midi/MidiOutputPort.java @@ -31,7 +31,7 @@ import java.io.IOException; * CANDIDATE FOR PUBLIC API * @hide */ -public class MidiOutputPort implements MidiSender, Closeable { +public class MidiOutputPort extends MidiSender implements Closeable { private static final String TAG = "MidiOutputPort"; private final int mPortNumber; @@ -59,7 +59,7 @@ public class MidiOutputPort implements MidiSender, Closeable { long timestamp = MidiPortImpl.getMessageTimeStamp(buffer, count); // dispatch to all our receivers - mDispatcher.post(buffer, offset, size, timestamp); + mDispatcher.receive(buffer, offset, size, timestamp); } } catch (IOException e) { // FIXME report I/O failure? diff --git a/media/java/android/media/midi/MidiReceiver.java b/media/java/android/media/midi/MidiReceiver.java index 64c0c07..674c974 100644 --- a/media/java/android/media/midi/MidiReceiver.java +++ b/media/java/android/media/midi/MidiReceiver.java @@ -24,7 +24,7 @@ import java.io.IOException; * CANDIDATE FOR PUBLIC API * @hide */ -public interface MidiReceiver { +abstract public class MidiReceiver { /** * Called to pass MIDI data to the receiver. * @@ -32,7 +32,7 @@ public interface MidiReceiver { * The msg bytes should be copied by the receiver rather than retaining a reference * to this parameter. * Also, modifying the contents of the msg array parameter may result in other receivers - * in the same application receiving incorrect values in their post() method. + * in the same application receiving incorrect values in their receive() method. * * @param msg a byte array containing the MIDI data * @param offset the offset of the first byte of the data in the byte array @@ -40,5 +40,6 @@ public interface MidiReceiver { * @param timestamp the timestamp of the message (based on {@link java.lang.System#nanoTime} * @throws IOException */ - public void post(byte[] msg, int offset, int count, long timestamp) throws IOException; + abstract public void receive(byte[] msg, int offset, int count, long timestamp) + throws IOException; } diff --git a/media/java/android/media/midi/MidiSender.java b/media/java/android/media/midi/MidiSender.java index 4550476..9285973 100644 --- a/media/java/android/media/midi/MidiSender.java +++ b/media/java/android/media/midi/MidiSender.java @@ -23,18 +23,18 @@ package android.media.midi; * CANDIDATE FOR PUBLIC API * @hide */ -public interface MidiSender { +abstract public class MidiSender { /** * Called to connect a {@link MidiReceiver} to the sender * * @param receiver the receiver to connect */ - public void connect(MidiReceiver receiver); + abstract public void connect(MidiReceiver receiver); /** * Called to disconnect a {@link MidiReceiver} from the sender * * @param receiver the receiver to disconnect */ - public void disconnect(MidiReceiver receiver); + abstract public void disconnect(MidiReceiver receiver); } |