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

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

Issue 956653003: Dart: Moves |native| methods to patch files. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Adjust analyzer script Created 5 years, 9 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/embedder/core/message_pipe_patch.dart ('k') | mojo/public/dart/src/data_pipe.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 numBytes, int flags) 8 external static List Create(int numBytes, int flags);
9 native "MojoSharedBuffer_Create";
10 9
11 static List Duplicate(int bufferHandle, int flags) 10 external static List Duplicate(int bufferHandle, int flags);
12 native "MojoSharedBuffer_Duplicate";
13 11
14 static List Map(MojoSharedBuffer buffer, 12 external static List Map(MojoSharedBuffer buffer, int bufferHandle,
15 int bufferHandle, 13 int offset, int numBytes, int flags);
16 int offset,
17 int numBytes,
18 int flags)
19 native "MojoSharedBuffer_Map";
20 14
21 static int Unmap(ByteData buffer) 15 external static int Unmap(ByteData buffer);
22 native "MojoSharedBuffer_Unmap";
23 } 16 }
24 17
25 18
26 class MojoSharedBuffer { 19 class MojoSharedBuffer {
27 static const int CREATE_FLAG_NONE = 0; 20 static const int CREATE_FLAG_NONE = 0;
28 static const int DUPLICATE_FLAG_NONE = 0; 21 static const int DUPLICATE_FLAG_NONE = 0;
29 static const int MAP_FLAG_NONE = 0; 22 static const int MAP_FLAG_NONE = 0;
30 23
31 MojoHandle handle; 24 MojoHandle handle;
32 MojoResult status; 25 MojoResult status;
33 ByteData mapping; 26 ByteData mapping;
34 27
35 MojoSharedBuffer( 28 MojoSharedBuffer(this.handle, [this.status = MojoResult.OK, this.mapping =
36 this.handle, [this.status = MojoResult.OK, this.mapping = null]); 29 null]);
37 30
38 factory MojoSharedBuffer.create(int numBytes, [int flags = 0]) { 31 factory MojoSharedBuffer.create(int numBytes, [int flags = 0]) {
39 List result = _MojoSharedBufferNatives.Create(numBytes, flags); 32 List result = _MojoSharedBufferNatives.Create(numBytes, flags);
40 if (result == null) { 33 if (result == null) {
41 return null; 34 return null;
42 } 35 }
43 assert((result is List) && (result.length == 2)); 36 assert((result is List) && (result.length == 2));
44 var r = new MojoResult(result[0]); 37 var r = new MojoResult(result[0]);
45 if (!r.isOk) { 38 if (!r.isOk) {
46 return null; 39 return null;
47 } 40 }
48 41
49 MojoSharedBuffer buf = 42 MojoSharedBuffer buf =
50 new MojoSharedBuffer(new MojoHandle(result[1]), r, null); 43 new MojoSharedBuffer(new MojoHandle(result[1]), r, null);
51 return buf; 44 return buf;
52 } 45 }
53 46
54 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) { 47 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) {
55 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags); 48 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
56 if (result == null) { 49 if (result == null) {
57 return null; 50 return null;
58 } 51 }
59 assert((result is List) && (result.length == 2)); 52 assert((result is List) && (result.length == 2));
60 var r = new MojoResult(result[0]); 53 var r = new MojoResult(result[0]);
61 if(!r.isOk) { 54 if (!r.isOk) {
62 return null; 55 return null;
63 } 56 }
64 57
65 MojoSharedBuffer dupe = 58 MojoSharedBuffer dupe =
66 new MojoSharedBuffer(new MojoHandle(result[1]), r, null); 59 new MojoSharedBuffer(new MojoHandle(result[1]), r, null);
67 return dupe; 60 return dupe;
68 } 61 }
69 62
70 MojoResult close() { 63 MojoResult close() {
71 if (handle == null) { 64 if (handle == null) {
72 status = MojoResult.INVALID_ARGUMENT; 65 status = MojoResult.INVALID_ARGUMENT;
73 return status; 66 return status;
74 } 67 }
75 MojoResult r = handle.close(); 68 MojoResult r = handle.close();
76 status = r; 69 status = r;
77 mapping = null; 70 mapping = null;
78 return status; 71 return status;
79 } 72 }
80 73
81 MojoResult map(int offset, int numBytes, [int flags = 0]) { 74 MojoResult map(int offset, int numBytes, [int flags = 0]) {
82 if (handle == null) { 75 if (handle == null) {
83 status = MojoResult.INVALID_ARGUMENT; 76 status = MojoResult.INVALID_ARGUMENT;
84 return status; 77 return status;
85 } 78 }
86 List result = _MojoSharedBufferNatives.Map( 79 List result =
87 this, handle.h, offset, numBytes, flags); 80 _MojoSharedBufferNatives.Map(this, handle.h, offset, numBytes, flags);
88 if (result == null) { 81 if (result == null) {
89 status = MojoResult.INVALID_ARGUMENT; 82 status = MojoResult.INVALID_ARGUMENT;
90 return status; 83 return status;
91 } 84 }
92 assert((result is List) && (result.length == 2)); 85 assert((result is List) && (result.length == 2));
93 status = new MojoResult(result[0]); 86 status = new MojoResult(result[0]);
94 mapping = result[1]; 87 mapping = result[1];
95 return status; 88 return status;
96 } 89 }
97 90
98 MojoResult unmap() { 91 MojoResult unmap() {
99 int r = _MojoSharedBufferNatives.Unmap(mapping); 92 int r = _MojoSharedBufferNatives.Unmap(mapping);
100 status = new MojoResult(r); 93 status = new MojoResult(r);
101 mapping = null; 94 mapping = null;
102 return status; 95 return status;
103 } 96 }
104 } 97 }
OLDNEW
« no previous file with comments | « mojo/dart/embedder/core/message_pipe_patch.dart ('k') | mojo/public/dart/src/data_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698