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

Side by Side Diff: mojo/public/dart/src/message_pipe.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/public/dart/src/interface.dart ('k') | mojo/public/dart/src/types.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 7
8 class _MojoMessagePipeNatives { 8 class _MojoMessagePipeNatives {
9 static List MojoCreateMessagePipe(int flags) 9 static List MojoCreateMessagePipe(int flags)
10 native "MojoMessagePipe_Create"; 10 native "MojoMessagePipe_Create";
(...skipping 17 matching lines...) Expand all
28 MojoMessagePipeReadResult.fromList(List<int> resultList) 28 MojoMessagePipeReadResult.fromList(List<int> resultList)
29 : this(new MojoResult(resultList[0]), resultList[1], resultList[2]); 29 : this(new MojoResult(resultList[0]), resultList[1], resultList[2]);
30 } 30 }
31 31
32 32
33 class MojoMessagePipeEndpoint { 33 class MojoMessagePipeEndpoint {
34 static const int WRITE_FLAG_NONE = 0; 34 static const int WRITE_FLAG_NONE = 0;
35 static const int READ_FLAG_NONE = 0; 35 static const int READ_FLAG_NONE = 0;
36 static const int READ_FLAG_MAY_DISCARD = 0; 36 static const int READ_FLAG_MAY_DISCARD = 0;
37 37
38 RawMojoHandle handle; 38 MojoHandle handle;
39 MojoResult status; 39 MojoResult status;
40 40
41 MojoMessagePipeEndpoint(this.handle); 41 MojoMessagePipeEndpoint(this.handle);
42 42
43 MojoResult write(ByteData data, 43 MojoResult write(ByteData data,
44 [int numBytes = -1, 44 [int numBytes = -1,
45 List<RawMojoHandle> handles = null, 45 List<MojoHandle> handles = null,
46 int flags = 0]) { 46 int flags = 0]) {
47 if (handle == null) { 47 if (handle == null) {
48 status = MojoResult.INVALID_ARGUMENT; 48 status = MojoResult.INVALID_ARGUMENT;
49 return status; 49 return status;
50 } 50 }
51 51
52 // If numBytes has the default value, use the full length of the data. 52 // If numBytes has the default value, use the full length of the data.
53 int dataNumBytes = (numBytes == -1) ? data.lengthInBytes : numBytes; 53 int dataNumBytes = (numBytes == -1) ? data.lengthInBytes : numBytes;
54 if (dataNumBytes > data.lengthInBytes) { 54 if (dataNumBytes > data.lengthInBytes) {
55 status = MojoResult.INVALID_ARGUMENT; 55 status = MojoResult.INVALID_ARGUMENT;
56 return status; 56 return status;
57 } 57 }
58 58
59 // handles may be null, otherwise convert to ints. 59 // handles may be null, otherwise convert to ints.
60 List<int> mojoHandles = 60 List<int> mojoHandles =
61 (handles != null) ? handles.map((h) => h.h).toList() : null; 61 (handles != null) ? handles.map((h) => h.h).toList() : null;
62 62
63 // Do the call. 63 // Do the call.
64 int result = _MojoMessagePipeNatives.MojoWriteMessage( 64 int result = _MojoMessagePipeNatives.MojoWriteMessage(
65 handle.h, data, dataNumBytes, mojoHandles, flags); 65 handle.h, data, dataNumBytes, mojoHandles, flags);
66 66
67 status = new MojoResult(result); 67 status = new MojoResult(result);
68 return status; 68 return status;
69 } 69 }
70 70
71 71
72 MojoMessagePipeReadResult read(ByteData data, 72 MojoMessagePipeReadResult read(ByteData data,
73 [int numBytes = -1, 73 [int numBytes = -1,
74 List<RawMojoHandle> handles = null, 74 List<MojoHandle> handles = null,
75 int flags = 0]) { 75 int flags = 0]) {
76 if (handle == null) { 76 if (handle == null) {
77 status = MojoResult.INVALID_ARGUMENT; 77 status = MojoResult.INVALID_ARGUMENT;
78 return null; 78 return null;
79 } 79 }
80 80
81 // If numBytes has the default value, use the full length of the data. 81 // If numBytes has the default value, use the full length of the data.
82 int dataNumBytes; 82 int dataNumBytes;
83 if (data == null) { 83 if (data == null) {
84 dataNumBytes = 0; 84 dataNumBytes = 0;
(...skipping 21 matching lines...) Expand all
106 status = MojoResult.INVALID_ARGUMENT; 106 status = MojoResult.INVALID_ARGUMENT;
107 return null; 107 return null;
108 } 108 }
109 109
110 assert((result is List) && (result.length == 3)); 110 assert((result is List) && (result.length == 3));
111 var readResult = new MojoMessagePipeReadResult.fromList(result); 111 var readResult = new MojoMessagePipeReadResult.fromList(result);
112 112
113 // Copy out the handles that were read. 113 // Copy out the handles that were read.
114 if (handles != null) { 114 if (handles != null) {
115 for (var i = 0; i < readResult.handlesRead; i++) { 115 for (var i = 0; i < readResult.handlesRead; i++) {
116 handles[i].h = mojoHandles[i]; 116 handles[i] = new MojoHandle(mojoHandles[i]);
117 } 117 }
118 } 118 }
119 119
120 status = readResult.status; 120 status = readResult.status;
121 return readResult; 121 return readResult;
122 } 122 }
123 123
124 MojoMessagePipeReadResult query() => read(null); 124 MojoMessagePipeReadResult query() => read(null);
125 } 125 }
126 126
127 127
128 class MojoMessagePipe { 128 class MojoMessagePipe {
129 static const int FLAG_NONE = 0; 129 static const int FLAG_NONE = 0;
130 130
131 List<MojoMessagePipeEndpoint> endpoints; 131 List<MojoMessagePipeEndpoint> endpoints;
132 MojoResult status; 132 MojoResult status;
133 133
134 MojoMessagePipe._() { 134 MojoMessagePipe._() {
135 endpoints = null; 135 endpoints = null;
136 status = MojoResult.OK; 136 status = MojoResult.OK;
137 } 137 }
138 138
139 factory MojoMessagePipe([int flags = FLAG_NONE]) { 139 factory MojoMessagePipe([int flags = FLAG_NONE]) {
140 List result = _MojoMessagePipeNatives.MojoCreateMessagePipe(flags); 140 List result = _MojoMessagePipeNatives.MojoCreateMessagePipe(flags);
141 if (result == null) { 141 if (result == null) {
142 return null; 142 return null;
143 } 143 }
144 assert((result is List) && (result.length == 3)); 144 assert((result is List) && (result.length == 3));
145 145
146 RawMojoHandle end1 = new RawMojoHandle(result[1]); 146 MojoHandle end1 = new MojoHandle(result[1]);
147 RawMojoHandle end2 = new RawMojoHandle(result[2]); 147 MojoHandle end2 = new MojoHandle(result[2]);
148 MojoMessagePipe pipe = new MojoMessagePipe._(); 148 MojoMessagePipe pipe = new MojoMessagePipe._();
149 pipe.endpoints = new List(2); 149 pipe.endpoints = new List(2);
150 pipe.endpoints[0] = new MojoMessagePipeEndpoint(end1); 150 pipe.endpoints[0] = new MojoMessagePipeEndpoint(end1);
151 pipe.endpoints[1] = new MojoMessagePipeEndpoint(end2); 151 pipe.endpoints[1] = new MojoMessagePipeEndpoint(end2);
152 pipe.status = new MojoResult(result[0]); 152 pipe.status = new MojoResult(result[0]);
153 return pipe; 153 return pipe;
154 } 154 }
155 } 155 }
OLDNEW
« no previous file with comments | « mojo/public/dart/src/interface.dart ('k') | mojo/public/dart/src/types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698