OLD | NEW |
| (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 MojoSharedBuffer { | |
8 static const int CREATE_FLAG_NONE = 0; | |
9 static const int DUPLICATE_FLAG_NONE = 0; | |
10 static const int MAP_FLAG_NONE = 0; | |
11 | |
12 MojoHandle handle; | |
13 MojoResult status; | |
14 ByteData mapping; | |
15 | |
16 MojoSharedBuffer(this.handle, | |
17 [this.status = MojoResult.OK, this.mapping = null]); | |
18 | |
19 factory MojoSharedBuffer.create(int numBytes, [int flags = 0]) { | |
20 List result = MojoSharedBufferNatives.Create(numBytes, flags); | |
21 if (result == null) { | |
22 return null; | |
23 } | |
24 assert((result is List) && (result.length == 2)); | |
25 var r = new MojoResult(result[0]); | |
26 if (!r.isOk) { | |
27 return null; | |
28 } | |
29 | |
30 MojoSharedBuffer buf = | |
31 new MojoSharedBuffer(new MojoHandle(result[1]), r, null); | |
32 return buf; | |
33 } | |
34 | |
35 factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) { | |
36 List result = MojoSharedBufferNatives.Duplicate(msb.handle.h, flags); | |
37 if (result == null) { | |
38 return null; | |
39 } | |
40 assert((result is List) && (result.length == 2)); | |
41 var r = new MojoResult(result[0]); | |
42 if (!r.isOk) { | |
43 return null; | |
44 } | |
45 | |
46 MojoSharedBuffer dupe = | |
47 new MojoSharedBuffer(new MojoHandle(result[1]), r, null); | |
48 return dupe; | |
49 } | |
50 | |
51 MojoResult close() { | |
52 if (handle == null) { | |
53 status = MojoResult.INVALID_ARGUMENT; | |
54 return status; | |
55 } | |
56 MojoResult r = handle.close(); | |
57 status = r; | |
58 mapping = null; | |
59 return status; | |
60 } | |
61 | |
62 MojoResult map(int offset, int numBytes, [int flags = 0]) { | |
63 if (handle == null) { | |
64 status = MojoResult.INVALID_ARGUMENT; | |
65 return status; | |
66 } | |
67 List result = | |
68 MojoSharedBufferNatives.Map(this, handle.h, offset, numBytes, flags); | |
69 if (result == null) { | |
70 status = MojoResult.INVALID_ARGUMENT; | |
71 return status; | |
72 } | |
73 assert((result is List) && (result.length == 2)); | |
74 status = new MojoResult(result[0]); | |
75 mapping = result[1]; | |
76 return status; | |
77 } | |
78 | |
79 MojoResult unmap() { | |
80 int r = MojoSharedBufferNatives.Unmap(mapping); | |
81 status = new MojoResult(r); | |
82 mapping = null; | |
83 return status; | |
84 } | |
85 } | |
OLD | NEW |