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

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

Issue 674383002: Initial work on Dart bindings for Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Merge. Work on templates. 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/system/lib/embedder.dart ('k') | mojo/public/dart/system/lib/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/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;
+ }
+}
« no previous file with comments | « mojo/public/dart/system/lib/embedder.dart ('k') | mojo/public/dart/system/lib/src/data_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698