aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/java/system/src/org/chromium/mojo/system/SharedBufferHandle.java
blob: df317d134d5911171bc5fbcff6be8b51c181c1e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.mojo.system;

import java.nio.ByteBuffer;

/**
 * A buffer that can be shared between applications.
 */
public interface SharedBufferHandle extends Handle {

    /**
     * Flags for the shared buffer creation operation.
     */
    public static class CreateFlags extends Flags<CreateFlags> {
        private static final int FLAG_NONE = 0;

        /**
         * Immutable flag with not bit set.
         */
        public static final CreateFlags NONE = CreateFlags.none().immutable();

        /**
         * Dedicated constructor.
         *
         * @param flags initial value of the flags.
         */
        protected CreateFlags(int flags) {
            super(flags);
        }

        /**
         * @return flags with no bit set.
         */
        public static CreateFlags none() {
            return new CreateFlags(FLAG_NONE);
        }

    }

    /**
     * Used to specify creation parameters for a shared buffer to |Core#createSharedBuffer()|.
     */
    public static class CreateOptions {
        private CreateFlags mFlags = CreateFlags.NONE;

        /**
         * @return the flags
         */
        public CreateFlags getFlags() {
            return mFlags;
        }

    }

    /**
     * Flags for the shared buffer duplication operation.
     */
    public static class DuplicateFlags extends Flags<DuplicateFlags> {
        private static final int FLAG_NONE = 0;

        /**
         * Immutable flag with not bit set.
         */
        public static final DuplicateFlags NONE = DuplicateFlags.none().immutable();

        /**
         * Dedicated constructor.
         *
         * @param flags initial value of the flags.
         */
        protected DuplicateFlags(int flags) {
            super(flags);
        }

        /**
         * @return flags with no bit set.
         */
        public static DuplicateFlags none() {
            return new DuplicateFlags(FLAG_NONE);
        }

    }

    /**
     * Used to specify parameters in duplicating access to a shared buffer to
     * |SharedBufferHandle#duplicate|
     */
    public static class DuplicateOptions {
        private DuplicateFlags mFlags = DuplicateFlags.NONE;

        /**
         * @return the flags
         */
        public DuplicateFlags getFlags() {
            return mFlags;
        }

    }

    /**
     * Flags for the shared buffer map operation.
     */
    public static class MapFlags extends Flags<MapFlags> {
        private static final int FLAG_NONE = 0;

        /**
         * Immutable flag with not bit set.
         */
        public static final MapFlags NONE = MapFlags.none().immutable();

        /**
         * Dedicated constructor.
         *
         * @param flags initial value of the flags.
         */
        protected MapFlags(int flags) {
            super(flags);
        }

        /**
         * @return flags with no bit set.
         */
        public static MapFlags none() {
            return new MapFlags(FLAG_NONE);
        }

    }

    /**
     * @see org.chromium.mojo.system.Handle#pass()
     */
    @Override
    public SharedBufferHandle pass();

    /**
     * Duplicates the handle. This creates another handle (returned on success), which can then be
     * sent to another application over a message pipe, while retaining access to this handle (and
     * any mappings that it may have).
     */
    public SharedBufferHandle duplicate(DuplicateOptions options);

    /**
     * Map the part (at offset |offset| of length |numBytes|) of the buffer given by this handle
     * into memory. |offset + numBytes| must be less than or equal to the size of the buffer. On
     * success, the returned buffer points to memory with the requested part of the buffer. A single
     * buffer handle may have multiple active mappings (possibly depending on the buffer type). The
     * permissions (e.g., writable or executable) of the returned memory may depend on the
     * properties of the buffer and properties attached to the buffer handle as well as |flags|.
     */
    public ByteBuffer map(long offset, long numBytes, MapFlags flags);

    /**
     * Unmap a buffer pointer that was mapped by |map()|.
     */
    public void unmap(ByteBuffer buffer);

}