• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.mojo.bindings;
6 
7 import org.chromium.mojo.system.Handle;
8 import org.chromium.mojo.system.MessagePipeHandle;
9 
10 import java.nio.ByteBuffer;
11 import java.util.List;
12 
13 /**
14  * A raw message to be sent/received from a {@link MessagePipeHandle}. Note that this can contain
15  * any data, not necessarily a Mojo message with a proper header. See also {@link ServiceMessage}.
16  */
17 public class Message {
18 
19     /**
20      * The data of the message.
21      */
22     private final ByteBuffer mBuffer;
23 
24     /**
25      * The handles of the message.
26      */
27     private final List<? extends Handle> mHandle;
28 
29     /**
30      * This message interpreted as a message for a mojo service with an appropriate header.
31      */
32     private ServiceMessage mWithHeader = null;
33 
34     /**
35      * Constructor.
36      *
37      * @param buffer The buffer containing the bytes to send. This must be a direct buffer.
38      * @param handles The list of handles to send.
39      */
Message(ByteBuffer buffer, List<? extends Handle> handles)40     public Message(ByteBuffer buffer, List<? extends Handle> handles) {
41         assert buffer.isDirect();
42         mBuffer = buffer;
43         mHandle = handles;
44     }
45 
46     /**
47      * The data of the message.
48      */
getData()49     public ByteBuffer getData() {
50         return mBuffer;
51     }
52 
53     /**
54      * The handles of the message.
55      */
getHandles()56     public List<? extends Handle> getHandles() {
57         return mHandle;
58     }
59 
60     /**
61      * Returns the message interpreted as a message for a mojo service.
62      */
asServiceMessage()63     public ServiceMessage asServiceMessage() {
64         if (mWithHeader == null) {
65             mWithHeader = new ServiceMessage(this);
66         }
67         return mWithHeader;
68     }
69 }
70