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

Side by Side Diff: mojo/public/dart/src/buffer.dart

Issue 800523004: Dart: Simplifies the handle watcher. Various cleanups and bugfixes. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: cleanup Created 5 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « mojo/dart/test/simple_handle_watcher_test.dart ('k') | mojo/public/dart/src/client.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 part of core; 5 part of core;
6 6
7 class _MojoSharedBufferNatives { 7 class _MojoSharedBufferNatives {
8 static List Create(int num_bytes, int flags) 8 static List Create(int num_bytes, int flags)
9 native "MojoSharedBuffer_Create"; 9 native "MojoSharedBuffer_Create";
10 10
(...skipping 10 matching lines...) Expand all
21 static int Unmap(ByteData buffer) 21 static int Unmap(ByteData buffer)
22 native "MojoSharedBuffer_Unmap"; 22 native "MojoSharedBuffer_Unmap";
23 } 23 }
24 24
25 25
26 class MojoSharedBuffer { 26 class MojoSharedBuffer {
27 static const int CREATE_FLAG_NONE = 0; 27 static const int CREATE_FLAG_NONE = 0;
28 static const int DUPLICATE_FLAG_NONE = 0; 28 static const int DUPLICATE_FLAG_NONE = 0;
29 static const int MAP_FLAG_NONE = 0; 29 static const int MAP_FLAG_NONE = 0;
30 30
31 RawMojoHandle handle; 31 MojoHandle handle;
32 MojoResult status; 32 MojoResult status;
33 ByteData mapping; 33 ByteData mapping;
34 34
35 MojoSharedBuffer._() { 35 MojoSharedBuffer._() {
36 handle = null; 36 handle = null;
37 status = MojoResult.OK; 37 status = MojoResult.OK;
38 mapping = null; 38 mapping = null;
39 } 39 }
40 40
41 factory MojoSharedBuffer(int num_bytes, [int flags = 0]) { 41 factory MojoSharedBuffer(int num_bytes, [int flags = 0]) {
42 List result = _MojoSharedBufferNatives.Create(num_bytes, flags); 42 List result = _MojoSharedBufferNatives.Create(num_bytes, flags);
43 if (result == null) { 43 if (result == null) {
44 return null; 44 return null;
45 } 45 }
46 assert((result is List) && (result.length == 2)); 46 assert((result is List) && (result.length == 2));
47 var r = new MojoResult(result[0]); 47 var r = new MojoResult(result[0]);
48 if (!r.isOk) { 48 if (!r.isOk) {
49 return null; 49 return null;
50 } 50 }
51 51
52 MojoSharedBuffer buf = new MojoSharedBuffer._(); 52 MojoSharedBuffer buf = new MojoSharedBuffer._();
53 buf.status = r; 53 buf.status = r;
54 buf.handle = new RawMojoHandle(result[1]); 54 buf.handle = new MojoHandle(result[1]);
55 buf.mapping = null; 55 buf.mapping = null;
56 return buf; 56 return buf;
57 } 57 }
58 58
59 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) { 59 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) {
60 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags); 60 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
61 if (result == null) { 61 if (result == null) {
62 return null; 62 return null;
63 } 63 }
64 assert((result is List) && (result.length == 2)); 64 assert((result is List) && (result.length == 2));
65 var r = new MojoResult(result[0]); 65 var r = new MojoResult(result[0]);
66 if(!r.isOk) { 66 if(!r.isOk) {
67 return null; 67 return null;
68 } 68 }
69 69
70 MojoSharedBuffer dupe = new MojoSharedBuffer._(); 70 MojoSharedBuffer dupe = new MojoSharedBuffer._();
71 dupe.status = r; 71 dupe.status = r;
72 dupe.handle = new RawMojoHandle(result[1]); 72 dupe.handle = new MojoHandle(result[1]);
73 dupe.mapping = null; // The buffer is not mapped in the duplicate. 73 dupe.mapping = null; // The buffer is not mapped in the duplicate.
74 return dupe; 74 return dupe;
75 } 75 }
76 76
77 MojoResult close() { 77 MojoResult close() {
78 if (handle == null) { 78 if (handle == null) {
79 status = MojoResult.INVALID_ARGUMENT; 79 status = MojoResult.INVALID_ARGUMENT;
80 return status; 80 return status;
81 } 81 }
82 MojoResult r = handle.close(); 82 MojoResult r = handle.close();
(...skipping 19 matching lines...) Expand all
102 return status; 102 return status;
103 } 103 }
104 104
105 MojoResult unmap() { 105 MojoResult unmap() {
106 int r = _MojoSharedBufferNatives.Unmap(mapping); 106 int r = _MojoSharedBufferNatives.Unmap(mapping);
107 status = new MojoResult(r); 107 status = new MojoResult(r);
108 mapping = null; 108 mapping = null;
109 return status; 109 return status;
110 } 110 }
111 } 111 }
OLDNEW
« no previous file with comments | « mojo/dart/test/simple_handle_watcher_test.dart ('k') | mojo/public/dart/src/client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698