Add beginnings of EventPort wrapping
This commit is contained in:
29
capnp/helpers/asyncHelper.h
Normal file
29
capnp/helpers/asyncHelper.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "kj/async.h"
|
||||
#include "Python.h"
|
||||
|
||||
class PyEventPort: public kj::EventPort {
|
||||
public:
|
||||
PyEventPort(PyObject * _py_event_port): py_event_port(_py_event_port) {
|
||||
// We don't need to incref/decref, since this C++ class will be owned by the Python wrapper class, and we'll make sure the python class doesn't refcount to 0 elsewhere.
|
||||
// Py_INCREF(py_event_port);
|
||||
}
|
||||
virtual void wait() {
|
||||
PyObject_CallMethod(py_event_port, const_cast<char *>("wait"), NULL);
|
||||
}
|
||||
|
||||
virtual void poll() {
|
||||
PyObject_CallMethod(py_event_port, const_cast<char *>("poll"), NULL);
|
||||
}
|
||||
|
||||
virtual void setRunnable(bool runnable) {
|
||||
PyObject * arg = Py_False;
|
||||
if (runnable)
|
||||
arg = Py_True;
|
||||
PyObject_CallMethod(py_event_port, const_cast<char *>("set_runnable"), const_cast<char *>("o"), arg);
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject * py_event_port;
|
||||
};
|
||||
@@ -7,4 +7,12 @@ cdef extern from "../helpers/capabilityHelper.h":
|
||||
cdef extern from "../helpers/capabilityHelper.h":
|
||||
void reraise_kj_exception()
|
||||
cdef cppclass PyRefCounter:
|
||||
PyRefCounter(PyObject *)
|
||||
PyRefCounter(PyObject *)
|
||||
|
||||
cdef extern from "../helpers/rpcHelper.h":
|
||||
cdef cppclass PyRestorer:
|
||||
PyRestorer(PyObject *)
|
||||
|
||||
cdef extern from "../helpers/asyncHelper.h":
|
||||
cdef cppclass PyEventPort:
|
||||
PyEventPort(PyObject *)
|
||||
Reference in New Issue
Block a user