OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 package system | |
6 | |
7 import "math" | |
8 | |
9 // Go equivalent definitions of the various system types defined in Mojo. | |
10 // | |
11 type MojoTimeTicks int64 | |
12 type MojoHandle uint32 | |
13 type MojoResult uint32 | |
14 type MojoDeadline uint64 | |
15 type MojoHandleSignals uint32 | |
16 type MojoWriteMessageFlags uint32 | |
17 type MojoReadMessageFlags uint32 | |
18 type MojoWriteDataFlags uint32 | |
19 type MojoReadDataFlags uint32 | |
20 type MojoCreateDataPipeOptionsFlags uint32 | |
21 type MojoCreateMessagePipeOptionsFlags uint32 | |
22 type MojoCreateSharedBufferOptionsFlags uint32 | |
23 type MojoDuplicateBufferHandleOptionsFlags uint32 | |
24 type MojoMapBufferFlags uint32 | |
25 type MojoBufferInformationFlags uint32 | |
26 | |
27 const ( | |
28 MOJO_DEADLINE_INDEFINITE MojoDeadline = math.MaxUint64 | |
29 MOJO_HANDLE_INVALID MojoHandle = 0 | |
30 // TODO(vtl): Find a way of supporting the new, more flexible/extensible | |
31 // MojoResult (see mojo/public/c/syste/result.h). | |
32 MOJO_RESULT_OK MojoResult = 0x0 | |
33 MOJO_RESULT_CANCELLED MojoResult = 0x1 | |
34 MOJO_RESULT_UNKNOWN MojoResult = 0x2 | |
35 MOJO_RESULT_INVALID_ARGUMENT MojoResult = 0x3 | |
36 MOJO_RESULT_DEADLINE_EXCEEDED MojoResult = 0x4 | |
37 MOJO_RESULT_NOT_FOUND MojoResult = 0x5 | |
38 MOJO_RESULT_ALREADY_EXISTS MojoResult = 0x6 | |
39 MOJO_RESULT_PERMISSION_DENIED MojoResult = 0x7 | |
40 MOJO_RESULT_RESOURCE_EXHAUSTED MojoResult = 0x8 | |
41 MOJO_RESULT_FAILED_PRECONDITION MojoResult = 0x9 | |
42 MOJO_RESULT_ABORTED MojoResult = 0xa | |
43 MOJO_RESULT_OUT_OF_RANGE MojoResult = 0xb | |
44 MOJO_RESULT_UNIMPLEMENTED MojoResult = 0xc | |
45 MOJO_RESULT_INTERNAL MojoResult = 0xd | |
46 MOJO_RESULT_UNAVAILABLE MojoResult = 0xe | |
47 MOJO_RESULT_DATA_LOSS MojoResult = 0xf | |
48 // MOJO_RESULT_FAILED_PRECONDITION, subcode 0x001: | |
49 MOJO_RESULT_BUSY MojoResult = 0x0019 | |
50 // MOJO_RESULT_UNAVAILABLE, subcode 0x001: | |
51 MOJO_RESULT_SHOULD_WAIT MojoResult = 0x001e | |
52 | |
53 MOJO_HANDLE_SIGNAL_NONE MojoHandleSignals = 0 | |
54 MOJO_HANDLE_SIGNAL_READABLE MojoHandleSignals = 1 << 0 | |
55 MOJO_HANDLE_SIGNAL_WRITABLE MojoHandleSignals = 1 << 1 | |
56 MOJO_HANDLE_SIGNAL_PEER_CLOSED MojoHandleSignals = 1 << 2 | |
57 | |
58 MOJO_WRITE_MESSAGE_FLAG_NONE MojoWriteMessageFlags = 0 | |
59 MOJO_READ_MESSAGE_FLAG_NONE MojoReadMessageFlags = 0 | |
60 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD MojoReadMessageFlags = 1 << 0 | |
61 | |
62 MOJO_READ_DATA_FLAG_NONE MojoReadDataFlags = 0 | |
63 MOJO_READ_DATA_FLAG_ALL_OR_NONE MojoReadDataFlags = 1 << 0 | |
64 MOJO_READ_DATA_FLAG_DISCARD MojoReadDataFlags = 1 << 1 | |
65 MOJO_READ_DATA_FLAG_QUERY MojoReadDataFlags = 1 << 2 | |
66 MOJO_READ_DATA_FLAG_PEEK MojoReadDataFlags = 1 << 3 | |
67 MOJO_WRITE_DATA_FLAG_NONE MojoWriteDataFlags = 0 | |
68 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE MojoWriteDataFlags = 1 << 0 | |
69 | |
70 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE MojoCreateDataPipeOptionsFlag
s = 0 | |
71 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE MojoCreateMessagePipeOptionsF
lags = 0 | |
72 | |
73 MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE MojoCreateSharedBufferOpt
ionsFlags = 0 | |
74 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE MojoDuplicateBufferHandle
OptionsFlags = 0 | |
75 MOJO_MAP_BUFFER_FLAG_NONE MojoMapBufferFlags
= 0 | |
76 MOJO_BUFFER_INFORMATION_FLAG_NONE MojoBufferInformationFlag
s = 0 | |
77 ) | |
78 | |
79 // IsReadable returns true iff the |MOJO_HANDLE_SIGNAL_READABLE| bit is set. | |
80 func (m MojoHandleSignals) IsReadable() bool { | |
81 return (m & MOJO_HANDLE_SIGNAL_READABLE) != 0 | |
82 } | |
83 | |
84 // IsWritable returns true iff the |MOJO_HANDLE_SIGNAL_WRITABLE| bit is set. | |
85 func (m MojoHandleSignals) IsWritable() bool { | |
86 return (m & MOJO_HANDLE_SIGNAL_WRITABLE) != 0 | |
87 } | |
88 | |
89 // IsClosed returns true iff the |MOJO_HANDLE_SIGNAL_PEER_CLOSED| bit is set. | |
90 func (m MojoHandleSignals) IsClosed() bool { | |
91 return (m & MOJO_HANDLE_SIGNAL_PEER_CLOSED) != 0 | |
92 } | |
93 | |
94 // MojoHandleSignalsState is a struct returned by wait functions to indicate | |
95 // the signaling state of handles. | |
96 type MojoHandleSignalsState struct { | |
97 // Signals that were satisfied at some time before the call returned. | |
98 SatisfiedSignals MojoHandleSignals | |
99 // Signals that are possible to satisfy. For example, if the return valu
e | |
100 // was |MOJO_RESULT_FAILED_PRECONDITION|, you can use this field to | |
101 // determine which, if any, of the signals can still be satisfied. | |
102 SatisfiableSignals MojoHandleSignals | |
103 } | |
104 | |
105 // DataPipeOptions is used to specify creation parameters for a data pipe. | |
106 type DataPipeOptions struct { | |
107 Flags MojoCreateDataPipeOptionsFlags | |
108 // The size of an element in bytes. All transactions and buffers will | |
109 // be an integral number of elements. | |
110 ElemSize uint32 | |
111 // The capacity of the data pipe in bytes. Must be a multiple of elemSiz
e. | |
112 Capacity uint32 | |
113 } | |
114 | |
115 // MessagePipeOptions is used to specify creation parameters for a message pipe. | |
116 type MessagePipeOptions struct { | |
117 Flags MojoCreateMessagePipeOptionsFlags | |
118 } | |
119 | |
120 // SharedBufferOptions is used to specify creation parameters for a | |
121 // shared buffer. | |
122 type SharedBufferOptions struct { | |
123 Flags MojoCreateSharedBufferOptionsFlags | |
124 } | |
125 | |
126 // DuplicateBufferHandleOptions is used to specify parameters in | |
127 // duplicating access to a shared buffer. | |
128 type DuplicateBufferHandleOptions struct { | |
129 Flags MojoDuplicateBufferHandleOptionsFlags | |
130 } | |
131 | |
132 // MojoBufferInformation is returned by the GetBufferInformation system | |
133 // call. | |
134 type MojoBufferInformation struct { | |
135 // Possible values: | |
136 // MOJO_BUFFER_INFORMATION_FLAG_NONE | |
137 Flags MojoBufferInformationFlags | |
138 | |
139 // The size of this shared buffer, in bytes. | |
140 NumBytes uint64 | |
141 } | |
OLD | NEW |