Remove some more c++ helper functions
This commit is contained in:
@@ -89,17 +89,6 @@ public:
|
|||||||
capnp::CallContext< capnp::DynamicStruct, capnp::DynamicStruct> context);
|
capnp::CallContext< capnp::DynamicStruct, capnp::DynamicStruct> context);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline capnp::DynamicCapability::Client new_client(capnp::InterfaceSchema & schema, PyObject * server) {
|
|
||||||
return capnp::DynamicCapability::Client(kj::heap<PythonInterfaceDynamicImpl>(schema, server));
|
|
||||||
}
|
|
||||||
inline capnp::DynamicValue::Reader new_server(capnp::InterfaceSchema & schema, PyObject * server) {
|
|
||||||
return capnp::DynamicValue::Reader(kj::heap<PythonInterfaceDynamicImpl>(schema, server));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline capnp::Capability::Client server_to_client(capnp::InterfaceSchema & schema, PyObject * server) {
|
|
||||||
return kj::heap<PythonInterfaceDynamicImpl>(schema, server);
|
|
||||||
}
|
|
||||||
|
|
||||||
class PyAsyncIoStream: public kj::AsyncIoStream {
|
class PyAsyncIoStream: public kj::AsyncIoStream {
|
||||||
public:
|
public:
|
||||||
kj::Own<PyRefCounter> protocol;
|
kj::Own<PyRefCounter> protocol;
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ from cpython.ref cimport PyObject
|
|||||||
from libcpp cimport bool
|
from libcpp cimport bool
|
||||||
|
|
||||||
cdef extern from "capnp/helpers/capabilityHelper.h":
|
cdef extern from "capnp/helpers/capabilityHelper.h":
|
||||||
cppclass PythonInterfaceDynamicImpl:
|
|
||||||
PythonInterfaceDynamicImpl(PyObject *)
|
|
||||||
void reraise_kj_exception()
|
void reraise_kj_exception()
|
||||||
cdef cppclass PyRefCounter:
|
cdef cppclass PyRefCounter:
|
||||||
PyRefCounter(PyObject *)
|
PyRefCounter(PyObject *)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ cdef extern from "capnp/helpers/checkCompiler.h":
|
|||||||
|
|
||||||
from libcpp cimport bool
|
from libcpp cimport bool
|
||||||
from capnp.helpers.non_circular cimport (
|
from capnp.helpers.non_circular cimport (
|
||||||
PythonInterfaceDynamicImpl, reraise_kj_exception, PyRefCounter,
|
reraise_kj_exception, PyRefCounter,
|
||||||
)
|
)
|
||||||
from capnp.includes.schema_cpp cimport (
|
from capnp.includes.schema_cpp cimport (
|
||||||
Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader, ReaderOptions,
|
Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader, ReaderOptions,
|
||||||
@@ -296,6 +296,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||||||
cppclass Client nogil:
|
cppclass Client nogil:
|
||||||
Client()
|
Client()
|
||||||
Client(Client&)
|
Client(Client&)
|
||||||
|
Client(Own[PythonInterfaceDynamicImpl])
|
||||||
Client upcast(InterfaceSchema requestedSchema)
|
Client upcast(InterfaceSchema requestedSchema)
|
||||||
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
|
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
|
||||||
InterfaceSchema getSchema()
|
InterfaceSchema getSchema()
|
||||||
@@ -326,7 +327,7 @@ cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp":
|
|||||||
TwoPartyVatNetwork(EventLoop &, AsyncIoStream& stream, Side, ReaderOptions)
|
TwoPartyVatNetwork(EventLoop &, AsyncIoStream& stream, Side, ReaderOptions)
|
||||||
VoidPromise onDisconnect()
|
VoidPromise onDisconnect()
|
||||||
VoidPromise onDrained()
|
VoidPromise onDrained()
|
||||||
RpcSystem makeRpcServerBootstrap"makeRpcServer"(TwoPartyVatNetwork&, Capability.Client) nogil
|
RpcSystem makeRpcServer(TwoPartyVatNetwork&, Capability.Client) nogil
|
||||||
RpcSystem makeRpcClient(TwoPartyVatNetwork&) nogil
|
RpcSystem makeRpcClient(TwoPartyVatNetwork&) nogil
|
||||||
|
|
||||||
cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||||
@@ -410,7 +411,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||||||
Reader(DynamicEnum value)
|
Reader(DynamicEnum value)
|
||||||
Reader(DynamicStruct.Reader& value)
|
Reader(DynamicStruct.Reader& value)
|
||||||
Reader(DynamicCapability.Client& value)
|
Reader(DynamicCapability.Client& value)
|
||||||
Reader(PythonInterfaceDynamicImpl& value)
|
Reader(Own[PythonInterfaceDynamicImpl] value)
|
||||||
Reader(AnyPointer.Reader& value)
|
Reader(AnyPointer.Reader& value)
|
||||||
Type getType()
|
Type getType()
|
||||||
int64_t asInt"as<int64_t>"()
|
int64_t asInt"as<int64_t>"()
|
||||||
@@ -497,6 +498,8 @@ cdef extern from "capnp/helpers/capabilityHelper.h":
|
|||||||
void rejectVoidDisconnected(VoidPromiseFulfiller& fulfiller, StringPtr message)
|
void rejectVoidDisconnected(VoidPromiseFulfiller& fulfiller, StringPtr message)
|
||||||
Exception makeException(StringPtr message)
|
Exception makeException(StringPtr message)
|
||||||
PyPromise tryReadMessage(AsyncIoStream& stream, ReaderOptions opts)
|
PyPromise tryReadMessage(AsyncIoStream& stream, ReaderOptions opts)
|
||||||
|
cppclass PythonInterfaceDynamicImpl:
|
||||||
|
PythonInterfaceDynamicImpl(InterfaceSchema&, PyObject *)
|
||||||
|
|
||||||
cdef extern from "capnp/serialize-async.h" namespace " ::capnp":
|
cdef extern from "capnp/serialize-async.h" namespace " ::capnp":
|
||||||
VoidPromise writeMessage(AsyncIoStream& output, MessageBuilder& builder)
|
VoidPromise writeMessage(AsyncIoStream& output, MessageBuilder& builder)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from capnp.includes.capnp_cpp cimport (
|
|||||||
SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr,
|
SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr,
|
||||||
String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject,
|
String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject,
|
||||||
DynamicCapability as C_DynamicCapability, Request, Response, RemotePromise, Promise,
|
DynamicCapability as C_DynamicCapability, Request, Response, RemotePromise, Promise,
|
||||||
CallContext, RpcSystem, makeRpcServerBootstrap, makeRpcClient, Capability as C_Capability,
|
CallContext, RpcSystem, makeRpcServer, makeRpcClient, Capability as C_Capability,
|
||||||
TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own,
|
TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own,
|
||||||
DynamicStruct_Builder, PyRefCounter, PyAsyncIoStream
|
DynamicStruct_Builder, PyRefCounter, PyAsyncIoStream
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
cimport cython # noqa: E402
|
cimport cython # noqa: E402
|
||||||
|
|
||||||
from capnp.helpers.helpers cimport init_capnp_api
|
from capnp.helpers.helpers cimport init_capnp_api
|
||||||
from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope, PyPromise, VoidPromise, EventPort, EventLoop, Canceler, PyAsyncIoStream, PromiseFulfiller, VoidPromiseFulfiller, tryReadMessage, writeMessage, makeException
|
from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope, PyPromise, VoidPromise, EventPort, EventLoop, Canceler, PyAsyncIoStream, PromiseFulfiller, VoidPromiseFulfiller, tryReadMessage, writeMessage, makeException, PythonInterfaceDynamicImpl
|
||||||
from capnp.includes.schema_cpp cimport (MessageReader,)
|
from capnp.includes.schema_cpp cimport (MessageReader,)
|
||||||
|
|
||||||
from cpython cimport array, Py_buffer, PyObject_CheckBuffer, memoryview, buffer
|
from cpython cimport array, Py_buffer, PyObject_CheckBuffer, memoryview, buffer
|
||||||
@@ -702,7 +702,7 @@ cdef C_DynamicValue.Reader _extract_dynamic_client(_DynamicCapabilityClient valu
|
|||||||
|
|
||||||
cdef C_DynamicValue.Reader _extract_dynamic_server(object value):
|
cdef C_DynamicValue.Reader _extract_dynamic_server(object value):
|
||||||
cdef _InterfaceSchema schema = value.schema
|
cdef _InterfaceSchema schema = value.schema
|
||||||
return helpers.new_server(schema.thisptr, <PyObject *>value)
|
return C_DynamicValue.Reader(capnp.heap[PythonInterfaceDynamicImpl](schema.thisptr, <PyObject*> value))
|
||||||
|
|
||||||
|
|
||||||
cdef C_DynamicValue.Reader _extract_dynamic_enum(_DynamicEnum value):
|
cdef C_DynamicValue.Reader _extract_dynamic_enum(_DynamicEnum value):
|
||||||
@@ -2056,7 +2056,8 @@ cdef class _DynamicCapabilityClient:
|
|||||||
else:
|
else:
|
||||||
s = schema
|
s = schema
|
||||||
|
|
||||||
self.thisptr = helpers.new_client(s.thisptr, <PyObject *>server)
|
self.thisptr = C_DynamicCapability.Client(
|
||||||
|
capnp.heap[PythonInterfaceDynamicImpl](s.thisptr, <PyObject *>server))
|
||||||
self._parent = server
|
self._parent = server
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@@ -2250,8 +2251,10 @@ cdef class TwoPartyServer:
|
|||||||
raise ValueError(f"Argument socket should be a AsyncIoStream, was {type(socket)}")
|
raise ValueError(f"Argument socket should be a AsyncIoStream, was {type(socket)}")
|
||||||
|
|
||||||
cdef _InterfaceSchema schema = bootstrap.schema
|
cdef _InterfaceSchema schema = bootstrap.schema
|
||||||
self.thisptr = capnp.heap[RpcSystem](makeRpcServerBootstrap(
|
self.thisptr = capnp.heap[RpcSystem](makeRpcServer(
|
||||||
deref(self._network.thisptr), helpers.server_to_client(schema.thisptr, <PyObject *>bootstrap)))
|
deref(self._network.thisptr),
|
||||||
|
C_DynamicCapability.Client(capnp.heap[PythonInterfaceDynamicImpl](
|
||||||
|
schema.thisptr, <PyObject *>bootstrap))))
|
||||||
|
|
||||||
cpdef bootstrap(self) except +reraise_kj_exception:
|
cpdef bootstrap(self) except +reraise_kj_exception:
|
||||||
return _CapabilityClient()._init(helpers.bootstrapHelperServer(deref(self.thisptr)), self)
|
return _CapabilityClient()._init(helpers.bootstrapHelperServer(deref(self.thisptr)), self)
|
||||||
|
|||||||
Reference in New Issue
Block a user