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

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

Issue 851173002: Dart: Encode/Decode handle and interface types. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix Interface encode parameters 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/sample_service_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 numBytes, int flags)
9 native "MojoSharedBuffer_Create"; 9 native "MojoSharedBuffer_Create";
10 10
11 static List Duplicate(int buffer_handle, int flags) 11 static List Duplicate(int bufferHandle, int flags)
12 native "MojoSharedBuffer_Duplicate"; 12 native "MojoSharedBuffer_Duplicate";
13 13
14 static List Map(MojoSharedBuffer buffer, 14 static List Map(MojoSharedBuffer buffer,
15 int buffer_handle, 15 int bufferHandle,
16 int offset, 16 int offset,
17 int num_bytes, 17 int numBytes,
18 int flags) 18 int flags)
19 native "MojoSharedBuffer_Map"; 19 native "MojoSharedBuffer_Map";
20 20
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 MojoHandle 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 this.handle, [this.status = MojoResult.OK, this.mapping = null]);
37 status = MojoResult.OK;
38 mapping = null;
39 }
40 37
41 factory MojoSharedBuffer(int num_bytes, [int flags = 0]) { 38 factory MojoSharedBuffer.create(int numBytes, [int flags = 0]) {
42 List result = _MojoSharedBufferNatives.Create(num_bytes, flags); 39 List result = _MojoSharedBufferNatives.Create(numBytes, flags);
43 if (result == null) { 40 if (result == null) {
44 return null; 41 return null;
45 } 42 }
46 assert((result is List) && (result.length == 2)); 43 assert((result is List) && (result.length == 2));
47 var r = new MojoResult(result[0]); 44 var r = new MojoResult(result[0]);
48 if (!r.isOk) { 45 if (!r.isOk) {
49 return null; 46 return null;
50 } 47 }
51 48
52 MojoSharedBuffer buf = new MojoSharedBuffer._(); 49 MojoSharedBuffer buf =
53 buf.status = r; 50 new MojoSharedBuffer(new MojoHandle(result[1]), r, null);
54 buf.handle = new MojoHandle(result[1]);
55 buf.mapping = null;
56 return buf; 51 return buf;
57 } 52 }
58 53
59 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) { 54 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) {
60 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags); 55 List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
61 if (result == null) { 56 if (result == null) {
62 return null; 57 return null;
63 } 58 }
64 assert((result is List) && (result.length == 2)); 59 assert((result is List) && (result.length == 2));
65 var r = new MojoResult(result[0]); 60 var r = new MojoResult(result[0]);
66 if(!r.isOk) { 61 if(!r.isOk) {
67 return null; 62 return null;
68 } 63 }
69 64
70 MojoSharedBuffer dupe = new MojoSharedBuffer._(); 65 MojoSharedBuffer dupe =
71 dupe.status = r; 66 new MojoSharedBuffer(new MojoHandle(result[1]), r, null);
72 dupe.handle = new MojoHandle(result[1]);
73 dupe.mapping = null; // The buffer is not mapped in the duplicate.
74 return dupe; 67 return dupe;
75 } 68 }
76 69
77 MojoResult close() { 70 MojoResult close() {
78 if (handle == null) { 71 if (handle == null) {
79 status = MojoResult.INVALID_ARGUMENT; 72 status = MojoResult.INVALID_ARGUMENT;
80 return status; 73 return status;
81 } 74 }
82 MojoResult r = handle.close(); 75 MojoResult r = handle.close();
83 status = r; 76 status = r;
84 mapping = null; 77 mapping = null;
85 return status; 78 return status;
86 } 79 }
87 80
88 MojoResult map(int offset, int num_bytes, [int flags = 0]) { 81 MojoResult map(int offset, int numBytes, [int flags = 0]) {
89 if (handle == null) { 82 if (handle == null) {
90 status = MojoResult.INVALID_ARGUMENT; 83 status = MojoResult.INVALID_ARGUMENT;
91 return status; 84 return status;
92 } 85 }
93 List result = _MojoSharedBufferNatives.Map( 86 List result = _MojoSharedBufferNatives.Map(
94 this, handle.h, offset, num_bytes, flags); 87 this, handle.h, offset, numBytes, flags);
95 if (result == null) { 88 if (result == null) {
96 status = MojoResult.INVALID_ARGUMENT; 89 status = MojoResult.INVALID_ARGUMENT;
97 return status; 90 return status;
98 } 91 }
99 assert((result is List) && (result.length == 2)); 92 assert((result is List) && (result.length == 2));
100 status = new MojoResult(result[0]); 93 status = new MojoResult(result[0]);
101 mapping = result[1]; 94 mapping = result[1];
102 return status; 95 return status;
103 } 96 }
104 97
105 MojoResult unmap() { 98 MojoResult unmap() {
106 int r = _MojoSharedBufferNatives.Unmap(mapping); 99 int r = _MojoSharedBufferNatives.Unmap(mapping);
107 status = new MojoResult(r); 100 status = new MojoResult(r);
108 mapping = null; 101 mapping = null;
109 return status; 102 return status;
110 } 103 }
111 } 104 }
OLDNEW
« no previous file with comments | « mojo/dart/test/sample_service_test.dart ('k') | mojo/public/dart/src/client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698