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# distutils: language = c++
6
7from cpython.buffer cimport PyBUF_CONTIG
8from cpython.buffer cimport PyBUF_CONTIG_RO
9from cpython.buffer cimport Py_buffer
10from cpython.buffer cimport PyBuffer_FillInfo
11from cpython.buffer cimport PyBuffer_Release
12from cpython.buffer cimport PyObject_GetBuffer
13from cpython.mem cimport PyMem_Malloc, PyMem_Free
14from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t
15
16cdef extern from "third_party/cython/python_export.h":
17  pass
18
19cdef extern from "mojo/public/platform/native/system_thunks.h" nogil:
20  cdef struct MojoSystemThunks:
21    pass
22
23cdef extern size_t MojoSetSystemThunks(const MojoSystemThunks* system_thunks)
24
25cdef extern from "mojo/public/c/system/core.h" nogil:
26  # types.h
27  ctypedef int64_t MojoTimeTicks
28
29  ctypedef uint32_t MojoHandle
30  const MojoHandle MOJO_HANDLE_INVALID
31
32  ctypedef int32_t MojoResult
33  const MojoResult MOJO_RESULT_OK
34  const MojoResult MOJO_RESULT_CANCELLED
35  const MojoResult MOJO_RESULT_UNKNOWN
36  const MojoResult MOJO_RESULT_INVALID_ARGUMENT
37  const MojoResult MOJO_RESULT_DEADLINE_EXCEEDED
38  const MojoResult MOJO_RESULT_NOT_FOUND
39  const MojoResult MOJO_RESULT_ALREADY_EXISTS
40  const MojoResult MOJO_RESULT_PERMISSION_DENIED
41  const MojoResult MOJO_RESULT_RESOURCE_EXHAUSTED
42  const MojoResult MOJO_RESULT_FAILED_PRECONDITION
43  const MojoResult MOJO_RESULT_ABORTED
44  const MojoResult MOJO_RESULT_OUT_OF_RANGE
45  const MojoResult MOJO_RESULT_UNIMPLEMENTED
46  const MojoResult MOJO_RESULT_INTERNAL
47  const MojoResult MOJO_RESULT_UNAVAILABLE
48  const MojoResult MOJO_RESULT_DATA_LOSS
49  const MojoResult MOJO_RESULT_BUSY
50  const MojoResult MOJO_RESULT_SHOULD_WAIT
51
52  ctypedef uint64_t MojoDeadline
53  const MojoDeadline MOJO_DEADLINE_INDEFINITE
54
55  ctypedef uint32_t MojoHandleSignals
56  const MojoHandleSignals MOJO_HANDLE_SIGNAL_NONE
57  const MojoHandleSignals MOJO_HANDLE_SIGNAL_READABLE
58  const MojoHandleSignals MOJO_HANDLE_SIGNAL_WRITABLE
59
60  # functions.h
61  MojoTimeTicks MojoGetTimeTicksNow()
62  MojoResult MojoClose(MojoHandle handle)
63  MojoResult MojoWait(MojoHandle handle,
64                      MojoHandleSignals signals,
65                      MojoDeadline deadline)
66  MojoResult MojoWaitMany(const MojoHandle* handles,
67                          const MojoHandleSignals* signals,
68                          uint32_t num_handles,
69                          MojoDeadline deadline)
70
71  # message_pipe.h
72  ctypedef uint32_t MojoCreateMessagePipeOptionsFlags
73  const MojoCreateMessagePipeOptionsFlags MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE
74
75  ctypedef uint32_t MojoWriteMessageFlags
76  const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE
77
78  ctypedef uint32_t MojoReadMessageFlags
79  const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE
80  const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD
81
82  cdef struct MojoCreateMessagePipeOptions:
83    uint32_t struct_size
84    MojoCreateMessagePipeOptionsFlags flags
85
86  MojoResult MojoCreateMessagePipe(
87      const MojoCreateMessagePipeOptions* options,
88      MojoHandle* message_pipe_handle0,
89      MojoHandle* message_pipe_handle1)
90
91  MojoResult MojoWriteMessage(
92      MojoHandle message_pipe_handle,
93      const void* bytes,
94      uint32_t num_bytes,
95      const MojoHandle* handles,
96      uint32_t num_handles,
97      MojoWriteMessageFlags flags)
98
99  MojoResult MojoReadMessage(
100      MojoHandle message_pipe_handle,
101      void* bytes,
102      uint32_t* num_bytes,
103      MojoHandle* handles,
104      uint32_t* num_handles,
105      MojoReadMessageFlags flags)
106
107  # data_pipe.h
108  ctypedef uint32_t MojoCreateDataPipeOptionsFlags
109  const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE
110  const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD
111
112  cdef struct MojoCreateDataPipeOptions:
113    uint32_t struct_size
114    MojoCreateDataPipeOptionsFlags flags
115    uint32_t element_num_bytes
116    uint32_t capacity_num_bytes
117
118  ctypedef uint32_t MojoWriteDataFlags
119
120  const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE
121  const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE
122
123  ctypedef uint32_t MojoReadDataFlags
124
125  const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE
126  const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE
127  const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD
128  const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY
129
130  MojoResult MojoCreateDataPipe(
131      const MojoCreateDataPipeOptions* options,
132      MojoHandle* data_pipe_producer_handle,
133      MojoHandle* data_pipe_consumer_handle)
134
135  MojoResult MojoWriteData(
136      MojoHandle data_pipe_producer_handle,
137      const void* elements,
138      uint32_t* num_bytes,
139      MojoWriteDataFlags flags)
140
141  MojoResult MojoBeginWriteData(
142      MojoHandle data_pipe_producer_handle,
143      void** buffer,
144      uint32_t* buffer_num_bytes,
145      MojoWriteDataFlags flags)
146
147  MojoResult MojoEndWriteData(
148      MojoHandle data_pipe_producer_handle,
149      uint32_t num_bytes_written)
150
151  MojoResult MojoReadData(
152      MojoHandle data_pipe_consumer_handle,
153      void* elements,
154      uint32_t* num_bytes,
155      MojoReadDataFlags flags)
156
157  MojoResult MojoBeginReadData(
158      MojoHandle data_pipe_consumer_handle,
159      const void** buffer,
160      uint32_t* buffer_num_bytes,
161      MojoReadDataFlags flags)
162
163  MojoResult MojoEndReadData(
164      MojoHandle data_pipe_consumer_handle,
165      uint32_t num_bytes_read)
166
167  # buffer.h
168  ctypedef uint32_t MojoCreateSharedBufferOptionsFlags
169  const MojoCreateSharedBufferOptionsFlags MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE
170
171  cdef struct MojoCreateSharedBufferOptions:
172    uint32_t struct_size
173    MojoCreateSharedBufferOptionsFlags flags
174
175  ctypedef uint32_t MojoDuplicateBufferHandleOptionsFlags
176  const MojoDuplicateBufferHandleOptionsFlags MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE
177
178  cdef struct MojoDuplicateBufferHandleOptions:
179    uint32_t struct_size
180    MojoDuplicateBufferHandleOptionsFlags flags
181
182  ctypedef uint32_t MojoMapBufferFlags
183  const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE
184
185  MojoResult MojoCreateSharedBuffer(
186      const MojoCreateSharedBufferOptions* options,
187      uint64_t num_bytes,
188      MojoHandle* shared_buffer_handle)
189
190  MojoResult MojoDuplicateBufferHandle(
191      MojoHandle buffer_handle,
192      const MojoDuplicateBufferHandleOptions* options,
193      MojoHandle* new_buffer_handle)
194
195  MojoResult MojoMapBuffer(MojoHandle buffer_handle,
196                           uint64_t offset,
197                           uint64_t num_bytes,
198                           void** buffer,
199                           MojoMapBufferFlags flags)
200
201  MojoResult MojoUnmapBuffer(void* buffer)
202