| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # distutils language = c++ | 5 # distutils language = c++ |
| 6 | 6 |
| 7 cimport c_core | 7 cimport c_core |
| 8 cimport c_environment | 8 cimport c_environment |
| 9 cimport c_async_waiter |
| 9 | 10 |
| 10 | 11 |
| 11 from libc.stdint cimport uintptr_t | 12 from libc.stdint cimport uintptr_t |
| 12 | 13 |
| 14 |
| 13 def SetSystemThunks(system_thunks_as_object): | 15 def SetSystemThunks(system_thunks_as_object): |
| 14 """Bind the basic Mojo Core functions. | 16 """Bind the basic Mojo Core functions. |
| 15 """ | 17 """ |
| 16 cdef const c_core.MojoSystemThunks* system_thunks = ( | 18 cdef const c_core.MojoSystemThunks* system_thunks = ( |
| 17 <const c_core.MojoSystemThunks*><uintptr_t>system_thunks_as_object) | 19 <const c_core.MojoSystemThunks*><uintptr_t>system_thunks_as_object) |
| 18 c_core.MojoSetSystemThunks(system_thunks) | 20 c_core.MojoSetSystemThunks(system_thunks) |
| 19 | 21 |
| 20 | 22 |
| 21 cdef class RunLoop(object): | 23 cdef class RunLoop(object): |
| 22 """RunLoop to use when using asynchronous operations on handles.""" | 24 """RunLoop to use when using asynchronous operations on handles.""" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 """ | 48 """ |
| 47 Post a task on the runloop. This must be called from the thread owning the | 49 Post a task on the runloop. This must be called from the thread owning the |
| 48 runloop. | 50 runloop. |
| 49 """ | 51 """ |
| 50 cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable) | 52 cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable) |
| 51 self.c_run_loop.PostDelayedTask(closure, delay) | 53 self.c_run_loop.PostDelayedTask(closure, delay) |
| 52 | 54 |
| 53 | 55 |
| 54 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter | 56 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter |
| 55 # across module boundaries. | 57 # across module boundaries. |
| 56 cdef class _AsyncWaiter(object): | 58 cdef class AsyncWaiter(object): |
| 57 cdef c_environment.CEnvironment* _cenvironment | 59 cdef c_environment.CEnvironment* _cenvironment |
| 58 cdef c_environment.PythonAsyncWaiter* _c_async_waiter | 60 cdef c_async_waiter.PythonAsyncWaiter* _c_async_waiter |
| 59 | 61 |
| 60 def __init__(self): | 62 def __init__(self): |
| 61 self._cenvironment = new c_environment.CEnvironment() | 63 self._cenvironment = new c_environment.CEnvironment() |
| 62 self._c_async_waiter = new c_environment.PythonAsyncWaiter() | 64 self._c_async_waiter = c_environment.NewAsyncWaiter() |
| 63 | 65 |
| 64 def __dealloc__(self): | 66 def __dealloc__(self): |
| 65 del self._c_async_waiter | 67 del self._c_async_waiter |
| 66 del self._cenvironment | 68 del self._cenvironment |
| 67 | 69 |
| 68 def AsyncWait(self, handle, signals, deadline, callback): | 70 def AsyncWait(self, handle, signals, deadline, callback): |
| 69 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback) | 71 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback) |
| 70 | 72 |
| 71 def CancelWait(self, wait_id): | 73 def CancelWait(self, wait_id): |
| 72 self._c_async_waiter.CancelWait(wait_id) | 74 self._c_async_waiter.CancelWait(wait_id) |
| 73 | |
| 74 | |
| 75 ASYNC_WAITER = _AsyncWaiter() | |
| OLD | NEW |