From 4be5ce0867e8debbdff63ba3c7c4bbe68e4be003 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 8 Sep 2014 09:27:41 -0700 Subject: [PATCH] Implement LocalMsgConnection::receive(LocalMessageProtocolMessage) --- .../org/mozilla/io/LocalMsgConnection.java | 8 ++++++-- midp/localmsg.js | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/java/custom/org/mozilla/io/LocalMsgConnection.java b/java/custom/org/mozilla/io/LocalMsgConnection.java index 1eff2de1..5a3356e5 100644 --- a/java/custom/org/mozilla/io/LocalMsgConnection.java +++ b/java/custom/org/mozilla/io/LocalMsgConnection.java @@ -25,7 +25,7 @@ public class LocalMsgConnection implements LocalMessageProtocolConnection, Local closeConnection(); } - public native void receiveData(byte[] message); + public native int receiveData(byte[] message); public int receive(byte[] message) { receiveData(message); @@ -33,7 +33,11 @@ public class LocalMsgConnection implements LocalMessageProtocolConnection, Local } public void receive(LocalMessageProtocolMessage message) throws IOException { - throw new IOException("LocalMsgConnection::receive(LocalMessageProtocolMessage) not implemented yet"); + byte[] msg = new byte[4096]; + int length = receiveData(msg); + byte[] data = new byte[length]; + System.arraycopy(msg, 0, data, 0, length); + message.setData(data); } public native void sendData(byte[] message, int offset, int length); diff --git a/midp/localmsg.js b/midp/localmsg.js index 20c2cd5f..8a205a36 100644 --- a/midp/localmsg.js +++ b/midp/localmsg.js @@ -32,6 +32,8 @@ LocalMsgConnection.prototype.copyMessage = function(messageQueue, data) { for (var i = 0; i < msg.length; i++) { data[i] = msg.data[i + msg.offset]; } + + return msg.length; } LocalMsgConnection.prototype.sendMessageToClient = function(message) { @@ -42,12 +44,12 @@ LocalMsgConnection.prototype.sendMessageToClient = function(message) { } } -LocalMsgConnection.prototype.clientReceiveMessage = function(ctx, data) { +LocalMsgConnection.prototype.clientReceiveMessage = function(ctx, stack, data) { if (this.clientMessages.length == 0) { this.clientWaiting = function() { this.clientWaiting = null; - this.copyMessage(this.clientMessages, data); + stack.push(this.copyMessage(this.clientMessages, data)); ctx.resume(); } @@ -55,7 +57,7 @@ LocalMsgConnection.prototype.clientReceiveMessage = function(ctx, data) { throw VM.Pause; } - this.copyMessage(this.clientMessages, data); + stack.push(this.copyMessage(this.clientMessages, data)); } LocalMsgConnection.prototype.sendMessageToServer = function(message) { @@ -66,12 +68,12 @@ LocalMsgConnection.prototype.sendMessageToServer = function(message) { } } -LocalMsgConnection.prototype.serverReceiveMessage = function(ctx, data) { +LocalMsgConnection.prototype.serverReceiveMessage = function(ctx, stack, data) { if (this.serverMessages.length == 0) { this.serverWaiting = function() { this.serverWaiting = null; - this.copyMessage(this.serverMessages, data); + stack.push(this.copyMessage(this.serverMessages, data)); ctx.resume(); } @@ -79,7 +81,7 @@ LocalMsgConnection.prototype.serverReceiveMessage = function(ctx, data) { throw VM.Pause; } - this.copyMessage(this.serverMessages, data); + stack.push(this.copyMessage(this.serverMessages, data)); } MIDP.LocalMsgConnections = {}; @@ -146,17 +148,17 @@ Native["org/mozilla/io/LocalMsgConnection.sendData.([BII)V"] = function(ctx, sta } } -Native["org/mozilla/io/LocalMsgConnection.receiveData.([B)V"] = function(ctx, stack) { +Native["org/mozilla/io/LocalMsgConnection.receiveData.([B)I"] = function(ctx, stack) { var data = stack.pop(), _this = stack.pop(); if (_this.server) { - MIDP.LocalMsgConnections[_this.protocolName].serverReceiveMessage(ctx, data); + MIDP.LocalMsgConnections[_this.protocolName].serverReceiveMessage(ctx, stack, data); } else { if (MIDP.FakeLocalMsgServers.indexOf(_this.protocolName) != -1) { console.warn("receiveData from an unimplemented localmsg server (" + _this.protocolName + ")"); } - MIDP.LocalMsgConnections[_this.protocolName].clientReceiveMessage(ctx, data); + MIDP.LocalMsgConnections[_this.protocolName].clientReceiveMessage(ctx, stack, data); } }