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.
5 # distutils: language = c++
7 from cpython.buffer cimport PyBUF_CONTIG
8 from cpython.buffer cimport PyBUF_CONTIG_RO
9 from cpython.buffer cimport Py_buffer
10 from cpython.buffer cimport PyBuffer_FillInfo
11 from cpython.buffer cimport PyBuffer_Release
12 from cpython.buffer cimport PyObject_GetBuffer
13 from cpython.mem cimport PyMem_Malloc, PyMem_Free
14 from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t
16 cdef extern from "mojo/public/c/system/core.h" nogil:
18 ctypedef int64_t MojoTimeTicks
20 ctypedef uint32_t MojoHandle
21 const MojoHandle MOJO_HANDLE_INVALID
23 ctypedef int32_t MojoResult
24 const MojoResult MOJO_RESULT_OK
25 const MojoResult MOJO_RESULT_CANCELLED
26 const MojoResult MOJO_RESULT_UNKNOWN
27 const MojoResult MOJO_RESULT_INVALID_ARGUMENT
28 const MojoResult MOJO_RESULT_DEADLINE_EXCEEDED
29 const MojoResult MOJO_RESULT_NOT_FOUND
30 const MojoResult MOJO_RESULT_ALREADY_EXISTS
31 const MojoResult MOJO_RESULT_PERMISSION_DENIED
32 const MojoResult MOJO_RESULT_RESOURCE_EXHAUSTED
33 const MojoResult MOJO_RESULT_FAILED_PRECONDITION
34 const MojoResult MOJO_RESULT_ABORTED
35 const MojoResult MOJO_RESULT_OUT_OF_RANGE
36 const MojoResult MOJO_RESULT_UNIMPLEMENTED
37 const MojoResult MOJO_RESULT_INTERNAL
38 const MojoResult MOJO_RESULT_UNAVAILABLE
39 const MojoResult MOJO_RESULT_DATA_LOSS
40 const MojoResult MOJO_RESULT_BUSY
41 const MojoResult MOJO_RESULT_SHOULD_WAIT
43 ctypedef uint64_t MojoDeadline
44 const MojoDeadline MOJO_DEADLINE_INDEFINITE
46 ctypedef uint32_t MojoHandleSignals
47 const MojoHandleSignals MOJO_HANDLE_SIGNAL_NONE
48 const MojoHandleSignals MOJO_HANDLE_SIGNAL_READABLE
49 const MojoHandleSignals MOJO_HANDLE_SIGNAL_WRITABLE
50 const MojoHandleSignals MOJO_HANDLE_SIGNAL_PEER_CLOSED
52 cdef struct MojoHandleSignalsState:
53 MojoHandleSignals satisfied_signals
54 MojoHandleSignals satisfiable_signals
57 MojoTimeTicks MojoGetTimeTicksNow()
58 MojoResult MojoClose(MojoHandle handle)
59 MojoResult MojoWait "MojoWait"(MojoHandle handle,
60 MojoHandleSignals signals,
61 MojoDeadline deadline,
62 MojoHandleSignalsState* signals_state)
63 MojoResult MojoWaitMany "MojoWaitMany"(const MojoHandle* handles,
64 const MojoHandleSignals* signals,
66 MojoDeadline deadline,
67 uint32_t* result_index,
68 MojoHandleSignalsState* signals_states)
71 ctypedef uint32_t MojoCreateMessagePipeOptionsFlags
72 const MojoCreateMessagePipeOptionsFlags MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE
74 ctypedef uint32_t MojoWriteMessageFlags
75 const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE
77 ctypedef uint32_t MojoReadMessageFlags
78 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE
79 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD
81 cdef struct MojoCreateMessagePipeOptions:
83 MojoCreateMessagePipeOptionsFlags flags
85 MojoResult MojoCreateMessagePipe(
86 const MojoCreateMessagePipeOptions* options,
87 MojoHandle* message_pipe_handle0,
88 MojoHandle* message_pipe_handle1)
90 MojoResult MojoWriteMessage(
91 MojoHandle message_pipe_handle,
94 const MojoHandle* handles,
96 MojoWriteMessageFlags flags)
98 MojoResult MojoReadMessage(
99 MojoHandle message_pipe_handle,
103 uint32_t* num_handles,
104 MojoReadMessageFlags flags)
107 ctypedef uint32_t MojoCreateDataPipeOptionsFlags
108 const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE
109 const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD
111 cdef struct MojoCreateDataPipeOptions:
113 MojoCreateDataPipeOptionsFlags flags
114 uint32_t element_num_bytes
115 uint32_t capacity_num_bytes
117 ctypedef uint32_t MojoWriteDataFlags
119 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE
120 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE
122 ctypedef uint32_t MojoReadDataFlags
124 const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE
125 const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE
126 const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD
127 const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY
128 const MojoReadDataFlags MOJO_READ_DATA_FLAG_PEEK
130 MojoResult MojoCreateDataPipe(
131 const MojoCreateDataPipeOptions* options,
132 MojoHandle* data_pipe_producer_handle,
133 MojoHandle* data_pipe_consumer_handle)
135 MojoResult MojoWriteData(
136 MojoHandle data_pipe_producer_handle,
137 const void* elements,
139 MojoWriteDataFlags flags)
141 MojoResult MojoBeginWriteData(
142 MojoHandle data_pipe_producer_handle,
144 uint32_t* buffer_num_bytes,
145 MojoWriteDataFlags flags)
147 MojoResult MojoEndWriteData(
148 MojoHandle data_pipe_producer_handle,
149 uint32_t num_bytes_written)
151 MojoResult MojoReadData(
152 MojoHandle data_pipe_consumer_handle,
155 MojoReadDataFlags flags)
157 MojoResult MojoBeginReadData(
158 MojoHandle data_pipe_consumer_handle,
160 uint32_t* buffer_num_bytes,
161 MojoReadDataFlags flags)
163 MojoResult MojoEndReadData(
164 MojoHandle data_pipe_consumer_handle,
165 uint32_t num_bytes_read)
168 ctypedef uint32_t MojoCreateSharedBufferOptionsFlags
169 const MojoCreateSharedBufferOptionsFlags MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE
171 cdef struct MojoCreateSharedBufferOptions:
173 MojoCreateSharedBufferOptionsFlags flags
175 ctypedef uint32_t MojoDuplicateBufferHandleOptionsFlags
176 const MojoDuplicateBufferHandleOptionsFlags MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE
178 cdef struct MojoDuplicateBufferHandleOptions:
180 MojoDuplicateBufferHandleOptionsFlags flags
182 ctypedef uint32_t MojoMapBufferFlags
183 const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE
185 MojoResult MojoCreateSharedBuffer(
186 const MojoCreateSharedBufferOptions* options,
188 MojoHandle* shared_buffer_handle)
190 MojoResult MojoDuplicateBufferHandle(
191 MojoHandle buffer_handle,
192 const MojoDuplicateBufferHandleOptions* options,
193 MojoHandle* new_buffer_handle)
195 MojoResult MojoMapBuffer(MojoHandle buffer_handle,
199 MojoMapBufferFlags flags)
201 MojoResult MojoUnmapBuffer(void* buffer)