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

Side by Side Diff: mojo/public/dart/system/lib/src/message_pipe.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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 part of core;
6
7 class _MojoMessagePipeNatives {
8 static List MojoCreateMessagePipe(int flags)
9 native "MojoMessagePipe_Create";
10
11 static int MojoWriteMessage(
12 int handle, ByteData data, int num_bytes, List<int> handles, int flags)
13 native "MojoMessagePipe_Write";
14
15 static List MojoReadMessage(
16 int handle, ByteData data, int num_bytes, List<int> handles, int flags)
17 native "MojoMessagePipe_Read";
18 }
19
20
21 class MojoMessagePipeEndpoint {
22 static final int WRITE_FLAG_NONE = 0;
23 static final int READ_FLAG_NONE = 0;
24 static final int READ_FLAG_MAY_DISCARD = 0;
25
26 RawMojoHandle handle;
27 int status;
28
29 MojoMessagePipeEndpoint(this.handle);
30
31 int write(ByteData data,
32 [int num_bytes = -1,
33 List<RawMojoHandle> handles = null,
34 int flags = 0]) {
35 // If num_bytes has the default value, use the full length of the data.
36 int data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
37
38 // handles may be null, otherwise convert to ints.
39 List<int> mojo_handles =
40 (handles != null) ? handles.map((h) => h.h).toList() : null;
41
42 // Do the call.
43 int result = _MojoMessagePipeNatives.MojoWriteMessage(
44 handle.h, data, data_num_bytes, mojo_handles, flags);
45
46 status = result;
47 return status;
48 }
49
50 // return[0] = MojoResult
51 // return[1] = bytes read
52 // return[2] = handles read
53 List read(ByteData data,
54 [int num_bytes = -1,
55 List<RawMojoHandle> handles = null,
56 int flags = 0]) {
57 // If num_bytes has the default value, use the full length of the data.
58 int data_num_bytes;
59 if (data == null) {
60 data_num_bytes = 0;
61 } else {
62 data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
63 }
64
65 // handles may be null, otherwise make an int list for the handles.
66 List<int> mojo_handles;
67 if (handles == null) {
68 mojo_handles = null;
69 } else {
70 mojo_handles = new List<int>(handles.length);
71 }
72
73 // Do the call.
74 List result = _MojoMessagePipeNatives.MojoReadMessage(
75 handle.h, data, data_num_bytes, mojo_handles, flags);
76
77 if (result == null) {
78 status = MojoResult.INVALID_ARGUMENT;
79 return null;
80 }
81 assert((result is List) && (result.length == 3));
82
83 status = result[0];
84 return result;
85 }
86
87 List query() => read(null);
88 }
89
90
91 class MojoMessagePipe {
92 static final int FLAG_NONE = 0;
93
94 List<MojoMessagePipeEndpoint> endpoints;
95 int status;
96
97 MojoMessagePipe._internal() {
98 endpoints = null;
99 status = MojoResult.OK;
100 }
101
102 factory MojoMessagePipe() {
103 return new MojoMessagePipe.create(FLAG_NONE);
104 }
105
106 factory MojoMessagePipe.create(int flags) {
107 List result = _MojoMessagePipeNatives.MojoCreateMessagePipe(flags);
108 if (result == null) {
109 return null;
110 }
111 assert((result is List) && (result.length == 3));
112
113 RawMojoHandle end1 = new RawMojoHandle(result[1]);
114 RawMojoHandle end2 = new RawMojoHandle(result[2]);
115 MojoMessagePipe pipe = new MojoMessagePipe._internal();
116 pipe.endpoints = new List(2);
117 pipe.endpoints[0] = new MojoMessagePipeEndpoint(end1);
118 pipe.endpoints[1] = new MojoMessagePipeEndpoint(end2);
119 pipe.status = result[0];
120 return pipe;
121 }
122 }
OLDNEW
« no previous file with comments | « mojo/public/dart/system/lib/src/handle_watcher.dart ('k') | mojo/public/dart/system/lib/src/mojo_dart_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698