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.
5 package org.chromium.mojo.system;
7 import java.nio.ByteBuffer;
10 * A buffer that can be shared between applications.
12 public interface SharedBufferHandle extends Handle {
15 * Flags for the shared buffer creation operation.
17 public static class CreateFlags extends Flags<CreateFlags> {
18 private static final int FLAG_NONE = 0;
21 * Immutable flag with not bit set.
23 public static final CreateFlags NONE = CreateFlags.none().immutable();
26 * Dedicated constructor.
28 * @param flags initial value of the flags.
30 protected CreateFlags(int flags) {
35 * @return flags with no bit set.
37 public static CreateFlags none() {
38 return new CreateFlags(FLAG_NONE);
44 * Used to specify creation parameters for a shared buffer to |Core#createSharedBuffer()|.
46 public static class CreateOptions {
47 private CreateFlags mFlags = CreateFlags.none();
52 public CreateFlags getFlags() {
59 * Flags for the shared buffer duplication operation.
61 public static class DuplicateFlags extends Flags<DuplicateFlags> {
62 private static final int FLAG_NONE = 0;
65 * Immutable flag with not bit set.
67 public static final DuplicateFlags NONE = DuplicateFlags.none().immutable();
70 * Dedicated constructor.
72 * @param flags initial value of the flags.
74 protected DuplicateFlags(int flags) {
79 * @return flags with no bit set.
81 public static DuplicateFlags none() {
82 return new DuplicateFlags(FLAG_NONE);
88 * Used to specify parameters in duplicating access to a shared buffer to
89 * |SharedBufferHandle#duplicate|
91 public static class DuplicateOptions {
92 private DuplicateFlags mFlags = DuplicateFlags.none();
97 public DuplicateFlags getFlags() {
104 * Flags for the shared buffer map operation.
106 public static class MapFlags extends Flags<MapFlags> {
107 private static final int FLAG_NONE = 0;
110 * Immutable flag with not bit set.
112 public static final MapFlags NONE = MapFlags.none().immutable();
115 * Dedicated constructor.
117 * @param flags initial value of the flags.
119 protected MapFlags(int flags) {
124 * @return flags with no bit set.
126 public static MapFlags none() {
127 return new MapFlags(FLAG_NONE);
133 * Duplicates the handle. This creates another handle (returned on success), which can then be
134 * sent to another application over a message pipe, while retaining access to this handle (and
135 * any mappings that it may have).
137 public SharedBufferHandle duplicate(DuplicateOptions options);
140 * Map the part (at offset |offset| of length |numBytes|) of the buffer given by this handle
141 * into memory. |offset + numBytes| must be less than or equal to the size of the buffer. On
142 * success, the returned buffer points to memory with the requested part of the buffer. A single
143 * buffer handle may have multiple active mappings (possibly depending on the buffer type). The
144 * permissions (e.g., writable or executable) of the returned memory may depend on the
145 * properties of the buffer and properties attached to the buffer handle as well as |flags|.
147 public ByteBuffer map(long offset, long numBytes, MapFlags flags);
150 * Unmap a buffer pointer that was mapped by |map()|.
152 public void unmap(ByteBuffer buffer);