Android: Generate JNI code for DataChannel

Bug: webrtc:8278
Change-Id: I107c839656500971cbd3da7557e14776759c318a
Reviewed-on: https://webrtc-review.googlesource.com/25820
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20873}
This commit is contained in:
Magnus Jedvert
2017-11-24 14:42:47 +01:00
committed by Commit Bot
parent b54bc06079
commit 7bd6cccb40
12 changed files with 160 additions and 212 deletions

View File

@ -26,17 +26,34 @@ public class DataChannel {
// Optional unsigned short in WebIDL, -1 means unspecified.
public int id = -1;
public Init() {}
@CalledByNative("Init")
boolean getOrdered() {
return ordered;
}
// Called only by native code.
private Init(boolean ordered, int maxRetransmitTimeMs, int maxRetransmits, String protocol,
boolean negotiated, int id) {
this.ordered = ordered;
this.maxRetransmitTimeMs = maxRetransmitTimeMs;
this.maxRetransmits = maxRetransmits;
this.protocol = protocol;
this.negotiated = negotiated;
this.id = id;
@CalledByNative("Init")
int getMaxRetransmitTimeMs() {
return maxRetransmitTimeMs;
}
@CalledByNative("Init")
int getMaxRetransmits() {
return maxRetransmits;
}
@CalledByNative("Init")
String getProtocol() {
return protocol;
}
@CalledByNative("Init")
boolean getNegotiated() {
return negotiated;
}
@CalledByNative("Init")
int getId() {
return id;
}
}
@ -51,6 +68,7 @@ public class DataChannel {
*/
public final boolean binary;
@CalledByNative("Buffer")
public Buffer(ByteBuffer data, boolean binary) {
this.data = data;
this.binary = binary;
@ -60,23 +78,34 @@ public class DataChannel {
/** Java version of C++ DataChannelObserver. */
public interface Observer {
/** The data channel's bufferedAmount has changed. */
public void onBufferedAmountChange(long previousAmount);
@CalledByNative("Observer") public void onBufferedAmountChange(long previousAmount);
/** The data channel state has changed. */
public void onStateChange();
@CalledByNative("Observer") public void onStateChange();
/**
* A data buffer was successfully received. NOTE: |buffer.data| will be
* freed once this function returns so callers who want to use the data
* asynchronously must make sure to copy it first.
*/
public void onMessage(Buffer buffer);
@CalledByNative("Observer") public void onMessage(Buffer buffer);
}
/** Keep in sync with DataChannelInterface::DataState. */
public enum State { CONNECTING, OPEN, CLOSING, CLOSED }
public enum State {
CONNECTING,
OPEN,
CLOSING,
CLOSED;
@CalledByNative("State")
static State fromNativeIndex(int nativeIndex) {
return values()[nativeIndex];
}
}
private final long nativeDataChannel;
private long nativeObserver;
@CalledByNative
public DataChannel(long nativeDataChannel) {
this.nativeDataChannel = nativeDataChannel;
}
@ -123,5 +152,12 @@ public class DataChannel {
private native boolean sendNative(byte[] data, boolean binary);
/** Dispose of native resources attached to this channel. */
public native void dispose();
public void dispose() {
JniCommon.nativeReleaseRef(nativeDataChannel);
}
@CalledByNative
long getNativeDataChannel() {
return nativeDataChannel;
}
};