Chromium Code Reviews| 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_async_waiter | 7 cimport c_async_waiter |
| 8 cimport c_environment | 8 cimport c_base |
| 9 cimport c_export # needed so the init function gets exported | 9 cimport c_export |
| 10 cimport c_thunks | |
| 11 | 10 |
| 12 | 11 |
| 13 from libc.stdint cimport uintptr_t | 12 from libc.stdint cimport uintptr_t |
| 14 | 13 |
| 15 | |
| 16 def SetSystemThunks(system_thunks_as_object): | 14 def SetSystemThunks(system_thunks_as_object): |
| 17 """Bind the basic Mojo Core functions. | 15 """Bind the basic Mojo Core functions. |
| 18 """ | 16 """ |
| 19 cdef const c_thunks.MojoSystemThunks* system_thunks = ( | 17 raise NotImplementedError() |
|
qsr
2015/01/07 15:14:46
I think you should not even write the method.
etiennej
2015/01/08 11:23:13
Done.
| |
| 20 <const c_thunks.MojoSystemThunks*><uintptr_t>system_thunks_as_object) | |
| 21 c_thunks.MojoSetSystemThunks(system_thunks) | |
| 22 | 18 |
| 23 | 19 |
| 24 cdef class RunLoop(object): | 20 cdef class RunLoop(object): |
| 25 """RunLoop to use when using asynchronous operations on handles.""" | 21 """RunLoop to use when using asynchronous operations on handles.""" |
| 26 | 22 |
| 27 cdef c_environment.CRunLoop* c_run_loop | 23 cdef c_base.PythonRunLoop* c_run_loop |
| 28 | 24 |
| 29 def __init__(self): | 25 def __init__(self): |
| 30 assert not <uintptr_t>(c_environment.CRunLoopCurrent()) | 26 self.c_run_loop = new c_base.PythonRunLoop() |
| 31 self.c_run_loop = new c_environment.CRunLoop() | |
| 32 | 27 |
| 33 def __dealloc__(self): | 28 def __dealloc__(self): |
| 34 del self.c_run_loop | 29 del self.c_run_loop |
| 35 | 30 |
| 36 def Run(self): | 31 def Run(self): |
| 37 """Run the runloop until Quit is called.""" | 32 """Run the runloop until Quit is called.""" |
| 38 self.c_run_loop.Run() | 33 self.c_run_loop.Run() |
| 39 | 34 |
| 40 def RunUntilIdle(self): | 35 def RunUntilIdle(self): |
| 41 """Run the runloop until Quit is called or no operation is waiting.""" | 36 """Run the runloop until Quit is called or no operation is waiting.""" |
| 42 self.c_run_loop.RunUntilIdle() | 37 self.c_run_loop.RunUntilIdle() |
| 43 | 38 |
| 44 def Quit(self): | 39 def Quit(self): |
| 45 """Quit the runloop.""" | 40 """Quit the runloop.""" |
| 46 self.c_run_loop.Quit() | 41 self.c_run_loop.Quit() |
| 47 | 42 |
| 48 def PostDelayedTask(self, runnable, delay=0): | 43 def PostDelayedTask(self, runnable, delay=0): |
| 49 """ | 44 """ |
| 50 Post a task on the runloop. This must be called from the thread owning the | 45 Post a task on the runloop. This must be called from the thread owning the |
| 51 runloop. | 46 runloop. |
| 52 """ | 47 """ |
| 53 cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable) | 48 self.c_run_loop.PostDelayedTask(runnable, delay) |
| 54 self.c_run_loop.PostDelayedTask(closure, delay) | |
| 55 | 49 |
| 56 | 50 |
| 57 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter | 51 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter |
| 58 # across module boundaries. | 52 # across module boundaries. |
| 59 cdef class AsyncWaiter(object): | 53 cdef class AsyncWaiter(object): |
| 60 cdef c_environment.CEnvironment* _cenvironment | |
| 61 cdef c_async_waiter.PythonAsyncWaiter* _c_async_waiter | 54 cdef c_async_waiter.PythonAsyncWaiter* _c_async_waiter |
| 62 | 55 |
| 63 def __init__(self): | 56 def __init__(self): |
| 64 self._cenvironment = new c_environment.CEnvironment() | 57 self._c_async_waiter = c_base.NewAsyncWaiter() |
| 65 self._c_async_waiter = c_environment.NewAsyncWaiter() | |
| 66 | 58 |
| 67 def __dealloc__(self): | 59 def __dealloc__(self): |
| 68 del self._c_async_waiter | 60 del self._c_async_waiter |
| 69 del self._cenvironment | |
| 70 | 61 |
| 71 def AsyncWait(self, handle, signals, deadline, callback): | 62 def AsyncWait(self, handle, signals, deadline, callback): |
| 72 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback) | 63 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback) |
| 73 | 64 |
| 74 def CancelWait(self, wait_id): | 65 def CancelWait(self, wait_id): |
| 75 self._c_async_waiter.CancelWait(wait_id) | 66 self._c_async_waiter.CancelWait(wait_id) |
| OLD | NEW |