• 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> mHandles;
28 
29     /**
30      * This message interpreted as a message for a mojo service with an appropriate header.
31      */
32     private ServiceMessage mWithHeader;
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         mBuffer = buffer;
42         mHandles = handles;
43     }
44 
45     /**
46      * The data of the message.
47      */
getData()48     public ByteBuffer getData() {
49         return mBuffer;
50     }
51 
52     /**
53      * The handles of the message.
54      */
getHandles()55     public List<? extends Handle> getHandles() {
56         return mHandles;
57     }
58 
59     /**
60      * Returns the message interpreted as a message for a mojo service.
61      */
asServiceMessage()62     public ServiceMessage asServiceMessage() {
63         if (mWithHeader == null) {
64             mWithHeader = new ServiceMessage(this);
65         }
66         return mWithHeader;
67     }
68 }
69