Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: mojo/python/content_handler/mojo_system_impl.pyx

Issue 796373006: Content handler for python. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
12 10
13 from libc.stdint cimport uintptr_t 11 from libc.stdint cimport uintptr_t
14 12
15 13
16 def SetSystemThunks(system_thunks_as_object):
17 """Bind the basic Mojo Core functions.
18 """
19 cdef const c_thunks.MojoSystemThunks* system_thunks = (
20 <const c_thunks.MojoSystemThunks*><uintptr_t>system_thunks_as_object)
21 c_thunks.MojoSetSystemThunks(system_thunks)
22
23
24 cdef class RunLoop(object): 14 cdef class RunLoop(object):
25 """RunLoop to use when using asynchronous operations on handles.""" 15 """RunLoop to use when using asynchronous operations on handles."""
26 16
27 cdef c_environment.CRunLoop* c_run_loop 17 cdef c_base.PythonRunLoop* c_run_loop
28 18
29 def __init__(self): 19 def __init__(self):
30 assert not <uintptr_t>(c_environment.CRunLoopCurrent()) 20 self.c_run_loop = new c_base.PythonRunLoop()
31 self.c_run_loop = new c_environment.CRunLoop()
32 21
33 def __dealloc__(self): 22 def __dealloc__(self):
34 del self.c_run_loop 23 del self.c_run_loop
35 24
36 def Run(self): 25 def Run(self):
37 """Run the runloop until Quit is called.""" 26 """Run the runloop until Quit is called."""
38 self.c_run_loop.Run() 27 self.c_run_loop.Run()
39 28
40 def RunUntilIdle(self): 29 def RunUntilIdle(self):
41 """Run the runloop until Quit is called or no operation is waiting.""" 30 """Run the runloop until Quit is called or no operation is waiting."""
42 self.c_run_loop.RunUntilIdle() 31 self.c_run_loop.RunUntilIdle()
43 32
44 def Quit(self): 33 def Quit(self):
45 """Quit the runloop.""" 34 """Quit the runloop."""
46 self.c_run_loop.Quit() 35 self.c_run_loop.Quit()
47 36
48 def PostDelayedTask(self, runnable, delay=0): 37 def PostDelayedTask(self, runnable, delay=0):
49 """ 38 """
50 Post a task on the runloop. This must be called from the thread owning the 39 Post a task on the runloop. This must be called from the thread owning the
51 runloop. 40 runloop.
52 """ 41 """
53 cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable) 42 self.c_run_loop.PostDelayedTask(runnable, delay)
54 self.c_run_loop.PostDelayedTask(closure, delay)
55 43
56 44
57 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter 45 # We use a wrapping class to be able to call the C++ class PythonAsyncWaiter
58 # across module boundaries. 46 # across module boundaries.
59 cdef class AsyncWaiter(object): 47 cdef class AsyncWaiter(object):
60 cdef c_environment.CEnvironment* _cenvironment
61 cdef c_async_waiter.PythonAsyncWaiter* _c_async_waiter 48 cdef c_async_waiter.PythonAsyncWaiter* _c_async_waiter
62 49
63 def __init__(self): 50 def __init__(self):
64 self._cenvironment = new c_environment.CEnvironment() 51 self._c_async_waiter = c_base.NewAsyncWaiter()
65 self._c_async_waiter = c_environment.NewAsyncWaiter()
66 52
67 def __dealloc__(self): 53 def __dealloc__(self):
68 del self._c_async_waiter 54 del self._c_async_waiter
69 del self._cenvironment
70 55
71 def AsyncWait(self, handle, signals, deadline, callback): 56 def AsyncWait(self, handle, signals, deadline, callback):
72 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback) 57 return self._c_async_waiter.AsyncWait(handle, signals, deadline, callback)
73 58
74 def CancelWait(self, wait_id): 59 def CancelWait(self, wait_id):
75 self._c_async_waiter.CancelWait(wait_id) 60 self._c_async_waiter.CancelWait(wait_id)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698