Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java

Issue 371603003: Adding a router class to handle messages that expect responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rebasing Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
index f826a8e034c9215a8a8e6496e05c716619a32d0d..14bdbf1e7cbc1eb376ea6c39590804f41a4293d9 100644
--- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
+++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
@@ -10,6 +10,7 @@ import org.chromium.mojo.system.MessagePipeHandle.ReadMessageResult;
import org.chromium.mojo.system.MojoResult;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.List;
import javax.annotation.Nullable;
@@ -29,6 +30,9 @@ public final class Message {
*/
public final List<? extends Handle> handles;
+ private MessageHeader mHeader = null;
+ private Message mPayload = null;
+
/**
* Constructor.
*
@@ -60,4 +64,39 @@ public final class Message {
}
return result.getMojoResult();
}
+
+ /**
+ * Returns the header of the given message. This should only be called on message that are known
+ * to have a header. This will throw a {@link DeserializationException} it the start of the
rmcilroy 2014/07/10 19:03:57 /s/it/if
qsr 2014/07/11 11:42:07 Done.
+ * message is not a valid header.
+ */
+ public MessageHeader getHeader() {
rmcilroy 2014/07/10 19:03:57 I'm not sure I like the idea of a Message optional
qsr 2014/07/11 11:42:07 Done, except that I need to use header in all the
+ if (mHeader == null) {
+ mHeader = new org.chromium.mojo.bindings.MessageHeader(this);
+ }
+ return mHeader;
+ }
+
+ /**
+ * Returns the payload of the message. This should only be called on message that are known to
+ * have a header.
+ */
+ public Message getPayload() {
+ if (mPayload == null) {
+ ByteBuffer truncatedBuffer = ((ByteBuffer) buffer.position(
+ getHeader().getSize())).slice();
+ truncatedBuffer.order(ByteOrder.nativeOrder());
+ mPayload = new Message(truncatedBuffer, handles);
+ }
+ return mPayload;
+ }
+
+ /**
+ * Reset the cache header. Used by {@link MessageHeader} when it modified the message buffer.
+ */
+ void resetHeader() {
rmcilroy 2014/07/10 19:03:57 Having to remember to resetHeader also seems error
qsr 2014/07/11 11:42:07 Done.
+ mHeader = null;
+ mPayload = null;
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698