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.
7 class _MojoSharedBufferNatives {
8 static List Create(int num_bytes, int flags)
9 native "MojoSharedBuffer_Create";
11 static List Duplicate(int buffer_handle, int flags)
12 native "MojoSharedBuffer_Duplicate";
14 static List Map(int buffer_handle, int offset, int num_bytes, int flags)
15 native "MojoSharedBuffer_Map";
17 static int Unmap(ByteData buffer)
18 native "MojoSharedBuffer_Unmap";
22 class MojoSharedBuffer {
23 static const int CREATE_FLAG_NONE = 0;
24 static const int DUPLICATE_FLAG_NONE = 0;
25 static const int MAP_FLAG_NONE = 0;
31 MojoSharedBuffer._() {
33 status = MojoResult.OK;
37 factory MojoSharedBuffer(int num_bytes, [int flags = 0]) {
38 List result = _MojoSharedBufferNatives.Create(num_bytes, flags);
42 assert((result is List) && (result.length == 2));
43 var r = new MojoResult(result[0]);
48 MojoSharedBuffer buf = new MojoSharedBuffer._();
50 buf.handle = new RawMojoHandle(result[1]);
55 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) {
56 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
60 assert((result is List) && (result.length == 2));
61 var r = new MojoResult(result[0]);
66 MojoSharedBuffer dupe = new MojoSharedBuffer._();
68 dupe.handle = new RawMojoHandle(result[1]);
69 dupe.mapping = msb.mapping;
75 status = MojoResult.INVALID_ARGUMENT;
78 MojoResult r = handle.close();
84 MojoResult map(int offset, int num_bytes, [int flags = 0]) {
86 status = MojoResult.INVALID_ARGUMENT;
89 List result = _MojoSharedBufferNatives.Map(
90 handle.h, offset, num_bytes, flags);
92 status = MojoResult.INVALID_ARGUMENT;
95 assert((result is List) && (result.length == 2));
96 status = new MojoResult(result[0]);
102 int r = _MojoSharedBufferNatives.Unmap(mapping);
103 status = new MojoResult(r);