diff --git a/capnp/helpers/helpers.pxd b/capnp/helpers/helpers.pxd index 7654cc8..86d7679 100644 --- a/capnp/helpers/helpers.pxd +++ b/capnp/helpers/helpers.pxd @@ -1,4 +1,4 @@ -from .capnp.includes.capnp_cpp cimport Maybe, DynamicStruct, Request, PyPromise, VoidPromise, RemotePromise, DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability, RpcSystem, MessageBuilder, MessageReader, TwoPartyVatNetwork +from .capnp.includes.capnp_cpp cimport Maybe, DynamicStruct, Request, PyPromise, VoidPromise, RemotePromise, DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability, RpcSystem, MessageBuilder, MessageReader, TwoPartyVatNetwork, PyRestorer from non_circular cimport reraise_kj_exception @@ -22,8 +22,6 @@ cdef extern from "../helpers/capabilityHelper.h": PyPromise convert_to_pypromise(RemotePromise&) cdef extern from "../helpers/rpcHelper.h": - cdef cppclass PyRestorer: - PyRestorer(PyObject *, StructSchema&) Capability.Client restoreHelper(RpcSystem&, MessageBuilder&) Capability.Client restoreHelper(RpcSystem&, MessageReader&) RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&) diff --git a/capnp/includes/capnp_cpp.pxd b/capnp/includes/capnp_cpp.pxd index bf5426b..737050c 100644 --- a/capnp/includes/capnp_cpp.pxd +++ b/capnp/includes/capnp_cpp.pxd @@ -215,6 +215,10 @@ cdef extern from "capnp/capability.h" namespace " ::capnp": Client(Client&) DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema) +cdef extern from "../helpers/rpcHelper.h": + cdef cppclass PyRestorer: + PyRestorer(PyObject *, StructSchema&) + cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp": cdef cppclass RpcSystem" ::capnp::RpcSystem": RpcSystem(RpcSystem&&) @@ -249,30 +253,6 @@ cdef extern from "capnp/any.h" namespace " ::capnp": Builder(Builder) DynamicStruct.Builder getAs"getAs< ::capnp::DynamicStruct>"(StructSchema) -cdef extern from "../helpers/fixMaybe.h": - EnumSchema.Enumerant fixMaybe(Maybe[EnumSchema.Enumerant]) except +reraise_kj_exception - char * getEnumString(DynamicStruct.Reader val) - char * getEnumString(DynamicStruct.Builder val) - char * getEnumString(Request val) - -cdef extern from "../helpers/capabilityHelper.h": - # PyPromise evalLater(EventLoop &, PyObject * func) - # PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func) - PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func) - VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func) - PyPromise then(VoidPromise & promise, PyObject * func, PyObject * error_func) - DynamicCapability.Client new_client(InterfaceSchema&, PyObject *) - DynamicValueForward.Reader new_server(InterfaceSchema&, PyObject *) - Capability.Client server_to_client(InterfaceSchema&, PyObject *) - PyPromise convert_to_pypromise(RemotePromise&) - -cdef extern from "../helpers/rpcHelper.h": - cdef cppclass PyRestorer: - PyRestorer(PyObject *, StructSchema&) - Capability.Client restoreHelper(RpcSystem&, MessageBuilder&) - Capability.Client restoreHelper(RpcSystem&, MessageReader&) - RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&) - cdef extern from "capnp/dynamic.h" namespace " ::capnp": cdef cppclass DynamicEnum: uint16_t getRaw() diff --git a/capnp/lib/capnp.pxd b/capnp/lib/capnp.pxd index 1259ebc..9868714 100644 --- a/capnp/lib/capnp.pxd +++ b/capnp/lib/capnp.pxd @@ -1,8 +1,10 @@ from .capnp.includes cimport capnp_cpp as capnp from .capnp.includes cimport schema_cpp -from .capnp.includes.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, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception +from .capnp.includes.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, 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, Request, Response, RemotePromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller from .capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode from .capnp.includes.types cimport * +from .capnp.helpers.non_circular cimport reraise_kj_exception +from .capnp.helpers cimport helpers cdef class _DynamicStructReader: cdef C_DynamicStruct.Reader thisptr diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 52fb6e0..562bbff 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -92,7 +92,7 @@ cdef public C_Capability.Client * call_py_restorer(PyObject * _restorer, C_Dynam ret = restorer.restore(reader) cdef _DynamicCapabilityServer server = ret - return new C_Capability.Client(server_to_client(server.schema.thisptr, server.server)) + return new C_Capability.Client(helpers.server_to_client(server.schema.thisptr, server.server)) cdef extern from "" namespace " ::kj": String strStructReader" ::kj::str"(C_DynamicStruct.Reader) @@ -544,7 +544,7 @@ cdef to_python_reader(C_DynamicValue.Reader self, object parent): elif type == capnp.TYPE_STRUCT: return _DynamicStructReader()._init(self.asStruct(), parent) elif type == capnp.TYPE_ENUM: - return fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr() + return helpers.fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr() elif type == capnp.TYPE_VOID: return None elif type == capnp.TYPE_ANY_POINTER: @@ -576,7 +576,7 @@ cdef to_python_builder(C_DynamicValue.Builder self, object parent): elif type == capnp.TYPE_STRUCT: return _DynamicStructBuilder()._init(self.asStruct(), parent) elif type == capnp.TYPE_ENUM: - return fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr() + return helpers.fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr() elif type == capnp.TYPE_VOID: return None elif type == capnp.TYPE_ANY_POINTER: @@ -598,7 +598,7 @@ cdef C_DynamicValue.Reader _extract_dynamic_client(_DynamicCapabilityClient valu return C_DynamicValue.Reader(value.thisptr) cdef C_DynamicValue.Reader _extract_dynamic_server(_DynamicCapabilityServer value): - return new_server(value.schema.thisptr, value.server) + return helpers.new_server(value.schema.thisptr, value.server) cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent): cdef C_DynamicValue.Reader temp @@ -765,7 +765,7 @@ cdef class _DynamicStructReader: :Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union """ - cdef object which = getEnumString(self.thisptr) + cdef object which = helpers.getEnumString(self.thisptr) if len(which) == 0: raise ValueError("Attempted to call which on a non-union type") @@ -953,7 +953,7 @@ cdef class _DynamicStructBuilder: :Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union """ - cdef object which = getEnumString(self.thisptr) + cdef object which = helpers.getEnumString(self.thisptr) if len(which) == 0: raise ValueError("Attempted to call which on a non-union type") @@ -1220,7 +1220,7 @@ cdef class _Promise: Py_INCREF(func) Py_INCREF(error_func) - return _Promise()._init(capnp.then(deref(self.thisptr), func, error_func)) + return _Promise()._init(helpers.then(deref(self.thisptr), func, error_func)) cdef class _VoidPromise: cdef VoidPromise * thisptr @@ -1252,7 +1252,7 @@ cdef class _VoidPromise: Py_INCREF(func) Py_INCREF(error_func) - return _Promise()._init(capnp.then(deref(self.thisptr), func, error_func)) + return _Promise()._init(helpers.then(deref(self.thisptr), func, error_func)) cdef class _RemotePromise: cdef RemotePromise * thisptr @@ -1281,7 +1281,7 @@ cdef class _RemotePromise: return ret cpdef as_pypromise(self) except +reraise_kj_exception: - _Promise()._init(convert_to_pypromise(deref(self.thisptr))) + _Promise()._init(helpers.convert_to_pypromise(deref(self.thisptr))) cpdef then(self, func, error_func=None) except +reraise_kj_exception: if self.is_consumed: @@ -1290,7 +1290,7 @@ cdef class _RemotePromise: Py_INCREF(func) Py_INCREF(error_func) - return _VoidPromise()._init(capnp.then(deref(self.thisptr), func, error_func)) + return _VoidPromise()._init(helpers.then(deref(self.thisptr), func, error_func)) cpdef _get(self, field) except +reraise_kj_exception: cdef int type = (self.thisptr.get(field)).getType() @@ -1371,7 +1371,7 @@ cdef class _DynamicCapabilityClient: else: s = schema - self.thisptr = new_client(s.thisptr, server) + self.thisptr = helpers.new_client(s.thisptr, server) self._server = server return self @@ -1536,9 +1536,9 @@ cdef class RpcClient: reader = objectId._parent if builder is not None: - return _CapabilityClient()._init(restoreHelper(deref(self.thisptr), deref(builder.thisptr)), self) + return _CapabilityClient()._init(helpers.restoreHelper(deref(self.thisptr), deref(builder.thisptr)), self) elif reader is not None: - return _CapabilityClient()._init(restoreHelper(deref(self.thisptr), deref(reader.thisptr)), self) + return _CapabilityClient()._init(helpers.restoreHelper(deref(self.thisptr), deref(reader.thisptr)), self) else: raise ValueError("objectId unexpectedly was not convertible to the proper type")