I have a really simple RPC protocol:
interface AvServer
{
createApp @0 ( name: Text ) -> ( app: AvApp );
}
interface AvApp
{
name @0 () -> ( name: Text );
destroy @1 ();
}
I implement that on the server with two concrete classes:
class AvServerImpl final : public AvServer::Server
class CAardvarkApp final: public AvApp::Server
And then when the client calls createApp I want to create an AvApp, return
a reference to it, and keep ownership of the app itself in some
datastructure on the server:
::kj::Promise<void> AvServerImpl::createApp( CreateAppContext context )
{
// "works"
context.getResults().setApp( kj::heap<CAardvarkApp>( context.getParams().
getName() ) );
// crashes because "thisHook" is null
auto pApp = kj::heap<CAardvarkApp>( context.getParams().getName() );
context.getResults().setApp( pApp->GetClient() ); // GetClient() is just a
call to thisCap()
m_listApps.push_back( std::move( pApp ) );
return kj::READY_NOW;
}
The first approach there works, but the AvServerImpl class doesn't keep any
kind of record of the new CAardvarkApp object, so it won't be able to do
anything with the app outside of a call from this one particular client.
What I'm attempting to do in the second approach is create an object on the
heap and set it in the results, but keep ownership of it in the list. I
don't get that far, though, because thisCap crashes because thisHook
returns nullptr.
I think I must be missing something really fundamental about how all this
is supposed to work. Am I required to create a unique foo::Server object
for each incoming call that refers to a single logical object? If I have to
pass ownership to the results in order to return values, it seems like
something along that line will be called for. That doesn't sound right,
though, since I'd have to manage an unbounded number of those objects as
requests come in from different clients.
Help? :)
Joe
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.