Fix after API changes. Should now be ready for 0.4 RC
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
cimport cython
|
||||
cimport capnp_cpp as capnp
|
||||
cimport schema_cpp
|
||||
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, ObjectPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, makeRpcClientWithRestorer, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
|
||||
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, makeRpcClientWithRestorer, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
|
||||
|
||||
from schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
||||
from cython.operator cimport dereference as deref
|
||||
@@ -569,7 +569,7 @@ cdef to_python_reader(C_DynamicValue.Reader self, object parent):
|
||||
return <char*>fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
||||
elif type == capnp.TYPE_VOID:
|
||||
return None
|
||||
elif type == capnp.TYPE_OBJECT:
|
||||
elif type == capnp.TYPE_ANY_POINTER:
|
||||
return _DynamicObjectReader()._init(self.asObject(), parent)
|
||||
elif type == capnp.TYPE_CAPABILITY:
|
||||
return _DynamicCapabilityClient()._init(self.asCapability(), parent)
|
||||
@@ -601,7 +601,7 @@ cdef to_python_builder(C_DynamicValue.Builder self, object parent):
|
||||
return <char*>fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
||||
elif type == capnp.TYPE_VOID:
|
||||
return None
|
||||
elif type == capnp.TYPE_OBJECT:
|
||||
elif type == capnp.TYPE_ANY_POINTER:
|
||||
return _DynamicObjectBuilder()._init(self.asObject(), parent)
|
||||
elif type == capnp.TYPE_CAPABILITY:
|
||||
return _DynamicCapabilityClient()._init(self.asCapability(), parent)
|
||||
@@ -1172,7 +1172,16 @@ cdef class _EventLoop:
|
||||
cdef _init(self) except +reraise_kj_exception:
|
||||
self.thisptr = new capnp.AsyncIoContext(moveAsyncContext(capnp.setupAsyncIo()))
|
||||
|
||||
def __dealloc__(self):
|
||||
self._remove()
|
||||
|
||||
cdef _remove(self) except +reraise_kj_exception:
|
||||
del self.thisptr
|
||||
self.thisptr = NULL
|
||||
|
||||
cdef Own[AsyncIoStream] wrapSocketFd(self, int fd):
|
||||
if self.thisptr == NULL:
|
||||
raise ValueError('Event loop has already been destroyed')
|
||||
return deref(self.thisptr.lowLevelProvider).wrapSocketFd(fd)
|
||||
|
||||
# def __dealloc__(self):
|
||||
@@ -1229,8 +1238,8 @@ cdef class _CallContext:
|
||||
def __get__(self):
|
||||
return _DynamicStructReader()._init(self.thisptr.getParams(), self)
|
||||
|
||||
cpdef _get_results(self, uint firstSegmentWordSize=0):
|
||||
return _DynamicStructBuilder()._init(self.thisptr.getResults(firstSegmentWordSize), self)
|
||||
cpdef _get_results(self, uint word_count=0):
|
||||
return _DynamicStructBuilder()._init(self.thisptr.getResults(), self) # TODO: pass firstSegmentWordSize
|
||||
|
||||
property results:
|
||||
def __get__(self):
|
||||
@@ -1240,10 +1249,7 @@ cdef class _CallContext:
|
||||
self.thisptr.releaseParams()
|
||||
|
||||
cpdef allow_async_cancellation(self):
|
||||
self.thisptr.allowAsyncCancellation()
|
||||
|
||||
cpdef is_canceled(self):
|
||||
return self.thisptr.isCanceled()
|
||||
self.thisptr.allowCancellation()
|
||||
|
||||
cpdef tail_call(self, _Request tailRequest):
|
||||
return _VoidPromise()._init(self.thisptr.tailCall(moveRequest(deref(tailRequest.thisptr_child))))
|
||||
@@ -1459,25 +1465,29 @@ cdef class _DynamicCapabilityClient:
|
||||
for key, val in kwargs.items():
|
||||
_setDynamicFieldPtr(request, key, val, self)
|
||||
|
||||
cpdef _send_helper(self, name, firstSegmentWordSize, args, kwargs) except +reraise_kj_exception:
|
||||
cdef Request * request = new Request(self.thisptr.newRequest(name, firstSegmentWordSize))
|
||||
cpdef _send_helper(self, name, word_count, args, kwargs) except +reraise_kj_exception:
|
||||
# if word_count is None:
|
||||
# word_count = 0
|
||||
cdef Request * request = new Request(self.thisptr.newRequest(name)) # TODO: pass word_count
|
||||
|
||||
self._set_fields(request, name, args, kwargs)
|
||||
|
||||
return _RemotePromise()._init(request.send(), self)
|
||||
|
||||
cpdef _request_helper(self, name, firstSegmentWordSize, args, kwargs) except +reraise_kj_exception:
|
||||
cdef _Request req = _Request()._init_child(self.thisptr.newRequest(name, firstSegmentWordSize), self)
|
||||
# if word_count is None:
|
||||
# word_count = 0
|
||||
cdef _Request req = _Request()._init_child(self.thisptr.newRequest(name), self)
|
||||
|
||||
self._set_fields(req.thisptr_child, name, args, kwargs)
|
||||
|
||||
return req
|
||||
|
||||
def _request(self, name, *args, firstSegmentWordSize=0, **kwargs):
|
||||
return self._request_helper(name, firstSegmentWordSize, args, kwargs)
|
||||
def _request(self, name, *args, word_count=None, **kwargs):
|
||||
return self._request_helper(name, word_count, args, kwargs)
|
||||
|
||||
def _send(self, name, *args, firstSegmentWordSize=0, **kwargs):
|
||||
return self._send_helper(name, firstSegmentWordSize, args, kwargs)
|
||||
def _send(self, name, *args, word_count=None, **kwargs):
|
||||
return self._send_helper(name, word_count, args, kwargs)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.endswith('_request'):
|
||||
@@ -1920,7 +1930,7 @@ cdef class SchemaParser:
|
||||
def __dealloc__(self):
|
||||
del self.thisptr
|
||||
|
||||
def _parse_disk_file(self, displayName, diskPath, imports):
|
||||
cpdef _parse_disk_file(self, displayName, diskPath, imports) except +reraise_kj_exception:
|
||||
cdef StringPtr * importArray = <StringPtr *>malloc(sizeof(StringPtr) * len(imports))
|
||||
|
||||
for i in range(len(imports)):
|
||||
|
||||
@@ -170,7 +170,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||
TYPE_ENUM " ::capnp::DynamicValue::ENUM"
|
||||
TYPE_STRUCT " ::capnp::DynamicValue::STRUCT"
|
||||
TYPE_CAPABILITY " ::capnp::DynamicValue::CAPABILITY"
|
||||
TYPE_OBJECT " ::capnp::DynamicValue::OBJECT"
|
||||
TYPE_ANY_POINTER " ::capnp::DynamicValue::ANY_POINTER"
|
||||
|
||||
cdef cppclass DynamicStruct:
|
||||
cppclass Reader:
|
||||
@@ -205,7 +205,8 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||
Client upcast(InterfaceSchema requestedSchema)
|
||||
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
|
||||
InterfaceSchema getSchema()
|
||||
Request newRequest(char * methodName, uint firstSegmentWordSize)
|
||||
Request newRequest(char * methodName)
|
||||
# Request newRequest(char * methodName, MessageSize)
|
||||
|
||||
cdef extern from "capnp/capability.h" namespace " ::capnp":
|
||||
cdef cppclass Response" ::capnp::Response< ::capnp::DynamicStruct>"(DynamicStruct.Reader):
|
||||
@@ -243,8 +244,8 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||
Maybe[StructSchema.Field] which()
|
||||
RemotePromise send()
|
||||
|
||||
cdef extern from "capnp/object.h" namespace " ::capnp":
|
||||
cdef cppclass ObjectPointer:
|
||||
cdef extern from "capnp/any.h" namespace " ::capnp":
|
||||
cdef cppclass AnyPointer:
|
||||
cppclass Reader:
|
||||
DynamicStruct.Reader getAs"getAs< ::capnp::DynamicStruct>"(StructSchema)
|
||||
cppclass Builder:
|
||||
@@ -335,7 +336,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||
String asText"as< ::capnp::Text>"()
|
||||
DynamicList.Reader asList"as< ::capnp::DynamicList>"()
|
||||
DynamicStruct.Reader asStruct"as< ::capnp::DynamicStruct>"()
|
||||
ObjectPointer.Reader asObject"as< ::capnp::ObjectPointer>"()
|
||||
AnyPointer.Reader asObject"as< ::capnp::AnyPointer>"()
|
||||
DynamicCapability.Client asCapability"as< ::capnp::DynamicCapability>"()
|
||||
DynamicEnum asEnum"as< ::capnp::DynamicEnum>"()
|
||||
Data.Reader asData"as< ::capnp::Data>"()
|
||||
@@ -349,7 +350,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||
String asText"as< ::capnp::Text>"()
|
||||
DynamicList.Builder asList"as< ::capnp::DynamicList>"()
|
||||
DynamicStruct.Builder asStruct"as< ::capnp::DynamicStruct>"()
|
||||
ObjectPointer.Builder asObject"as< ::capnp::ObjectPointer>"()
|
||||
AnyPointer.Builder asObject"as< ::capnp::AnyPointer>"()
|
||||
DynamicCapability.Client asCapability"as< ::capnp::DynamicCapability>"()
|
||||
DynamicEnum asEnum"as< ::capnp::DynamicEnum>"()
|
||||
Data.Builder asData"as< ::capnp::Data>"()
|
||||
@@ -378,14 +379,13 @@ cdef extern from "capnp/capability.h" namespace " ::capnp":
|
||||
DynamicStruct.Reader getParams() except +reraise_kj_exception
|
||||
void releaseParams() except +reraise_kj_exception
|
||||
|
||||
DynamicStruct.Builder getResults(uint firstSegmentWordSize)
|
||||
DynamicStruct.Builder initResults(uint firstSegmentWordSize)
|
||||
DynamicStruct.Builder getResults()
|
||||
DynamicStruct.Builder initResults()
|
||||
void setResults(DynamicStruct.Reader value)
|
||||
# void adoptResults(Orphan<Results>&& value);
|
||||
# Orphanage getResultsOrphanage(uint firstSegmentWordSize = 0);
|
||||
VoidPromise tailCall(Request & tailRequest)
|
||||
void allowAsyncCancellation() except +reraise_kj_exception
|
||||
bint isCanceled() except +reraise_kj_exception
|
||||
void allowCancellation() except +reraise_kj_exception
|
||||
|
||||
cdef extern from "kj/async.h" namespace " ::kj":
|
||||
cdef cppclass EventLoop:
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C" {
|
||||
capnp::Capability::Client * call_py_restorer(PyObject *, capnp::DynamicStruct::Reader &);
|
||||
}
|
||||
|
||||
class PyRestorer final: public capnp::SturdyRefRestorer<capnp::ObjectPointer> {
|
||||
class PyRestorer final: public capnp::SturdyRefRestorer<capnp::AnyPointer> {
|
||||
public:
|
||||
PyRestorer(PyObject * _py_restorer, capnp::StructSchema& _schema): py_restorer(_py_restorer), schema(_schema) {
|
||||
// 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.
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
// Py_DECREF(py_restorer);
|
||||
// }
|
||||
|
||||
capnp::Capability::Client restore(capnp::ObjectPointer::Reader objectId) override {
|
||||
capnp::Capability::Client restore(capnp::AnyPointer::Reader objectId) override {
|
||||
auto reader = objectId.getAs<capnp::DynamicStruct>(schema);
|
||||
capnp::Capability::Client * ret = call_py_restorer(py_restorer, reader);
|
||||
check_py_error();
|
||||
@@ -38,14 +38,14 @@ private:
|
||||
capnp::Capability::Client restoreHelper(capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>& client, capnp::MessageBuilder & objectId) { capnp::MallocMessageBuilder hostIdMessage(8);
|
||||
auto hostId = hostIdMessage.initRoot<capnp::rpc::twoparty::SturdyRefHostId>();
|
||||
hostId.setSide(capnp::rpc::twoparty::Side::SERVER);
|
||||
return client.restore(hostId, objectId.getRoot<capnp::ObjectPointer>());
|
||||
return client.restore(hostId, objectId.getRoot<capnp::AnyPointer>());
|
||||
}
|
||||
|
||||
|
||||
capnp::Capability::Client restoreHelper(capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>& client, capnp::MessageReader & objectId) { capnp::MallocMessageBuilder hostIdMessage(8);
|
||||
auto hostId = hostIdMessage.initRoot<capnp::rpc::twoparty::SturdyRefHostId>();
|
||||
hostId.setSide(capnp::rpc::twoparty::Side::SERVER);
|
||||
return client.restore(hostId, objectId.getRoot<capnp::ObjectPointer>());
|
||||
return client.restore(hostId, objectId.getRoot<capnp::AnyPointer>());
|
||||
}
|
||||
|
||||
template <typename SturdyRefHostId, typename ProvisionId,
|
||||
@@ -55,5 +55,5 @@ capnp::RpcSystem<SturdyRefHostId> makeRpcClientWithRestorer(
|
||||
PyRestorer& restorer) {
|
||||
using namespace capnp;
|
||||
return RpcSystem<SturdyRefHostId>(network,
|
||||
kj::Maybe<SturdyRefRestorer<ObjectPointer>&>(restorer));
|
||||
kj::Maybe<SturdyRefRestorer<AnyPointer>&>(restorer));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user