Add beginnings of EventPort wrapping

This commit is contained in:
Jason Paryani
2014-01-28 21:42:57 -08:00
parent f49af992ca
commit 18c6d41f96
3 changed files with 40 additions and 15 deletions

View 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;
};

View File

@@ -7,4 +7,12 @@ cdef extern from "../helpers/capabilityHelper.h":
cdef extern from "../helpers/capabilityHelper.h": cdef extern from "../helpers/capabilityHelper.h":
void reraise_kj_exception() void reraise_kj_exception()
cdef cppclass PyRefCounter: 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 *)

View File

@@ -5,7 +5,7 @@ cdef extern from "../helpers/checkCompiler.h":
pass pass
from schema_cpp cimport Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader from schema_cpp cimport Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader
from .capnp.helpers.non_circular cimport PythonInterfaceDynamicImpl, reraise_kj_exception, PyRefCounter from .capnp.helpers.non_circular cimport PythonInterfaceDynamicImpl, reraise_kj_exception, PyRefCounter, PyRestorer, PyEventPort
from .capnp.includes.types cimport * from .capnp.includes.types cimport *
cdef extern from "capnp/common.h" namespace " ::capnp": cdef extern from "capnp/common.h" namespace " ::capnp":
@@ -245,10 +245,6 @@ cdef extern from "capnp/capability.h" namespace " ::capnp":
Client(Client&) Client(Client&)
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema) DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
cdef extern from "../helpers/rpcHelper.h":
cdef cppclass PyRestorer:
PyRestorer(PyObject *)
cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp": cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp":
cdef cppclass RpcSystem" ::capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>": cdef cppclass RpcSystem" ::capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>":
RpcSystem(RpcSystem&&) RpcSystem(RpcSystem&&)
@@ -400,15 +396,7 @@ cdef extern from "capnp/capability.h" namespace " ::capnp":
cdef extern from "kj/async.h" namespace " ::kj": cdef extern from "kj/async.h" namespace " ::kj":
cdef cppclass EventLoop: cdef cppclass EventLoop:
EventLoop() EventLoop()
# Promise[void] yield_end'yield'() EventLoop(PyEventPort &)
# object wait(PyPromise) except +reraise_kj_exception
# Response wait_remote'wait'(RemotePromise)
# void wait_void'wait'(VoidPromise)
# object there(PyPromise) except +reraise_kj_exception
# PyPromise evalLater(PyObject * func)
# PyPromise there(PyPromise, PyObject * func)
cdef cppclass SimpleEventLoop(EventLoop):
pass
cdef cppclass PromiseFulfiller: cdef cppclass PromiseFulfiller:
void fulfill() void fulfill()
cdef cppclass PromiseFulfillerPair" ::kj::PromiseFulfillerPair<void>": cdef cppclass PromiseFulfillerPair" ::kj::PromiseFulfillerPair<void>":