| Index: mojo/public/dart/system/lib/src/buffer.dart
|
| diff --git a/mojo/public/dart/system/lib/src/buffer.dart b/mojo/public/dart/system/lib/src/buffer.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bfdbf708afd235c4469ac5461ba13032b46b0bf9
|
| --- /dev/null
|
| +++ b/mojo/public/dart/system/lib/src/buffer.dart
|
| @@ -0,0 +1,98 @@
|
| +// 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.
|
| +
|
| +part of core;
|
| +
|
| +class _MojoSharedBufferNatives {
|
| + static List Create(int num_bytes, int flags)
|
| + native "MojoSharedBuffer_Create";
|
| +
|
| + static List Duplicate(int buffer_handle, int flags)
|
| + native "MojoSharedBuffer_Duplicate";
|
| +
|
| + static List Map(int buffer_handle, int offset, int num_bytes, int flags)
|
| + native "MojoSharedBuffer_Map";
|
| +
|
| + static int Unmap(ByteData buffer)
|
| + native "MojoSharedBuffer_Unmap";
|
| +}
|
| +
|
| +
|
| +class MojoSharedBuffer {
|
| + static final int CREATE_FLAG_NONE = 0;
|
| + static final int DUPLICATE_FLAG_NONE = 0;
|
| + static final int MAP_FLAG_NONE = 0;
|
| +
|
| + RawMojoHandle handle;
|
| + int status;
|
| + ByteData mapping;
|
| +
|
| + MojoSharedBuffer._internal() {
|
| + handle = null;
|
| + status = MojoResult.OK;
|
| + mapping = null;
|
| + }
|
| +
|
| + factory MojoSharedBuffer.create(int num_bytes, [int flags = 0]) {
|
| + List result = _MojoSharedBufferNatives.Create(num_bytes, flags);
|
| + if (result == null) {
|
| + return null;
|
| + }
|
| + assert((result is List) && (result.length == 2));
|
| + if (!MojoResult.isOk(result[0])) {
|
| + return null;
|
| + }
|
| +
|
| + MojoSharedBuffer buf = new MojoSharedBuffer._internal();
|
| + buf.status = result[0];
|
| + buf.handle = new RawMojoHandle(result[1]);
|
| + buf.mapping = null;
|
| + return buf;
|
| + }
|
| +
|
| + factory MojoSharedBuffer.duplicate(
|
| + MojoSharedBuffer msb, [int flags = 0]) {
|
| + List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
|
| + if (result == null) {
|
| + return null;
|
| + }
|
| + assert((result is List) && (result.length == 2));
|
| + if (!MojoResult.isOk(result[0])) {
|
| + return null;
|
| + }
|
| +
|
| + MojoSharedBuffer dupe = new MojoSharedBuffer._internal();
|
| + dupe.status = result[0];
|
| + dupe.handle = new RawMojoHandle(result[1]);
|
| + dupe.mapping = msb.mapping;
|
| + return dupe;
|
| + }
|
| +
|
| + int close() {
|
| + int r = handle.close();
|
| + status = r;
|
| + mapping = null;
|
| + return r;
|
| + }
|
| +
|
| + int map(int offset, int num_bytes, [int flags = 0]) {
|
| + List result = _MojoSharedBufferNatives.Map(
|
| + handle.h, offset, num_bytes, flags);
|
| + if (result == null) {
|
| + status = MojoResult.INVALID_ARGUMENT;
|
| + return status;
|
| + }
|
| + assert((result is List) && (result.length == 2));
|
| + status = result[0];
|
| + mapping = result[1];
|
| + return status;
|
| + }
|
| +
|
| + int unmap() {
|
| + int r = _MojoSharedBufferNatives.Unmap(mapping);
|
| + status = r;
|
| + mapping = null;
|
| + return r;
|
| + }
|
| +}
|
|
|