Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(992)

Unified Diff: mojo/public/dart/src/buffer.dart

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/dart/mojo_init.dart ('k') | mojo/public/dart/src/data_pipe.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/src/buffer.dart
diff --git a/mojo/public/dart/src/buffer.dart b/mojo/public/dart/src/buffer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a00838e466dc4db5721855dc3785b2a9110cfe8b
--- /dev/null
+++ b/mojo/public/dart/src/buffer.dart
@@ -0,0 +1,107 @@
+// 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 const int CREATE_FLAG_NONE = 0;
+ static const int DUPLICATE_FLAG_NONE = 0;
+ static const int MAP_FLAG_NONE = 0;
+
+ RawMojoHandle handle;
+ MojoResult status;
+ ByteData mapping;
+
+ MojoSharedBuffer._() {
+ handle = null;
+ status = MojoResult.OK;
+ mapping = null;
+ }
+
+ factory MojoSharedBuffer(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));
+ var r = new MojoResult(result[0]);
+ if (!r.isOk) {
+ return null;
+ }
+
+ MojoSharedBuffer buf = new MojoSharedBuffer._();
+ buf.status = r;
+ 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));
+ var r = new MojoResult(result[0]);
+ if(!r.isOk) {
+ return null;
+ }
+
+ MojoSharedBuffer dupe = new MojoSharedBuffer._();
+ dupe.status = r;
+ dupe.handle = new RawMojoHandle(result[1]);
+ dupe.mapping = msb.mapping;
+ return dupe;
+ }
+
+ MojoResult close() {
+ if (handle == null) {
+ status = MojoResult.INVALID_ARGUMENT;
+ return status;
+ }
+ MojoResult r = handle.close();
+ status = r;
+ mapping = null;
+ return status;
+ }
+
+ MojoResult map(int offset, int num_bytes, [int flags = 0]) {
+ if (handle == null) {
+ status = MojoResult.INVALID_ARGUMENT;
+ return status;
+ }
+ 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 = new MojoResult(result[0]);
+ mapping = result[1];
+ return status;
+ }
+
+ MojoResult unmap() {
+ int r = _MojoSharedBufferNatives.Unmap(mapping);
+ status = new MojoResult(r);
+ mapping = null;
+ return status;
+ }
+}
« no previous file with comments | « mojo/public/dart/mojo_init.dart ('k') | mojo/public/dart/src/data_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698