Commit 66e2e032 authored by Kenton Varda's avatar Kenton Varda

Get rid of 'Advanced' server methods, just have one method that takes a…

Get rid of 'Advanced' server methods, just have one method that takes a CallContext.  A typedef reduces boilerplate.
parent 1460bfb3
......@@ -1226,11 +1226,9 @@ private:
" typedef ", paramType, " ", titleCase, "Params;\n"),
resultProto.getScopeId() != 0 ? kj::strTree() : kj::strTree(
" typedef ", resultType, " ", titleCase, "Results;\n"),
" virtual ::kj::Promise<void> ", name, "(\n"
" ", shortParamType, "::Reader params,\n"
" ", shortResultType, "::Builder result);\n"
" virtual ::kj::Promise<void> ", name, "Advanced(\n"
" ::capnp::CallContext<", shortParamType, ", ", shortResultType, "> context);\n"),
" typedef ::capnp::CallContext<", shortParamType, ", ", shortResultType, "> ",
titleCase, "Context;\n"
" virtual ::kj::Promise<void> ", name, "(", titleCase, "Context context);\n"),
kj::strTree(),
......@@ -1240,20 +1238,15 @@ private:
" return newCall<", paramType, ", ", resultType, ">(\n"
" 0x", interfaceIdHex, "ull, ", methodId, ", firstSegmentWordSize);\n"
"}\n"
"::kj::Promise<void> ", interfaceName, "::Server::", name, "(\n"
" ", paramType, "::Reader, ", resultType, "::Builder) {\n"
"::kj::Promise<void> ", interfaceName, "::Server::", name, "(", titleCase, "Context) {\n"
" return ::capnp::Capability::Server::internalUnimplemented(\n"
" \"", interfaceProto.getDisplayName(), "\", \"", name, "\",\n"
" 0x", interfaceIdHex, "ull, ", methodId, ");\n"
"}\n"
"::kj::Promise<void> ", interfaceName, "::Server::", name, "Advanced(\n"
" ::capnp::CallContext<", paramType, ", ", resultType, "> context) {\n"
" return ", name, "(context.getParams(), context.getResults());\n"
"}\n"),
kj::strTree(
" case ", methodId, ":\n"
" return ", name, "Advanced(::capnp::Capability::Server::internalGetTypedContext<\n"
" return ", name, "(::capnp::Capability::Server::internalGetTypedContext<\n"
" ", paramType, ", ", resultType, ">(context));\n")
};
}
......@@ -1338,8 +1331,7 @@ private:
" ::capnp::CallContext< ::capnp::AnyPointer, ::capnp::AnyPointer> context)\n"
" override;\n"
"\n"
"protected:\n"
" // Implementation should implement one of each method (normal or advanced).\n",
"protected:\n",
KJ_MAP(m, methods) { return kj::mv(m.serverDecls); },
"\n"
" ::kj::Promise<void> dispatchCallInternal(uint16_t methodId,\n"
......
......@@ -862,15 +862,17 @@ void checkDynamicTestMessageAllZero(DynamicStruct::Reader reader) {
TestInterfaceImpl::TestInterfaceImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestInterfaceImpl::foo(FooParams::Reader params, FooResults::Builder result) {
kj::Promise<void> TestInterfaceImpl::foo(FooContext context) {
++callCount;
auto params = context.getParams();
auto result = context.getResults();
EXPECT_EQ(123, params.getI());
EXPECT_TRUE(params.getJ());
result.setX("foo");
return kj::READY_NOW;
}
kj::Promise<void> TestInterfaceImpl::bazAdvanced(CallContext<BazParams, BazResults> context) {
kj::Promise<void> TestInterfaceImpl::baz(BazContext context) {
++callCount;
auto params = context.getParams();
checkTestMessage(params.getS());
......@@ -882,16 +884,17 @@ kj::Promise<void> TestInterfaceImpl::bazAdvanced(CallContext<BazParams, BazResul
TestExtendsImpl::TestExtendsImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestExtendsImpl::foo(FooParams::Reader params, FooResults::Builder result) {
kj::Promise<void> TestExtendsImpl::foo(FooContext context) {
++callCount;
auto params = context.getParams();
auto result = context.getResults();
EXPECT_EQ(321, params.getI());
EXPECT_FALSE(params.getJ());
result.setX("bar");
return kj::READY_NOW;
}
kj::Promise<void> TestExtendsImpl::graultAdvanced(
CallContext<GraultParams, test::TestAllTypes> context) {
kj::Promise<void> TestExtendsImpl::grault(GraultContext context) {
++callCount;
context.releaseParams();
......@@ -902,8 +905,7 @@ kj::Promise<void> TestExtendsImpl::graultAdvanced(
TestPipelineImpl::TestPipelineImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestPipelineImpl::getCapAdvanced(
CallContext<GetCapParams, GetCapResults> context) {
kj::Promise<void> TestPipelineImpl::getCap(GetCapContext context) {
++callCount;
auto params = context.getParams();
......@@ -926,16 +928,15 @@ kj::Promise<void> TestPipelineImpl::getCapAdvanced(
});
}
kj::Promise<void> TestCallOrderImpl::getCallSequence(
GetCallSequenceParams::Reader params, GetCallSequenceResults::Builder result) {
kj::Promise<void> TestCallOrderImpl::getCallSequence(GetCallSequenceContext context) {
auto result = context.getResults();
result.setN(count++);
return kj::READY_NOW;
}
TestTailCallerImpl::TestTailCallerImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestTailCallerImpl::fooAdvanced(
CallContext<FooParams, test::TestTailCallee::TailResult> context) {
kj::Promise<void> TestTailCallerImpl::foo(FooContext context) {
++callCount;
auto params = context.getParams();
......@@ -948,8 +949,7 @@ kj::Promise<void> TestTailCallerImpl::fooAdvanced(
TestTailCalleeImpl::TestTailCalleeImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestTailCalleeImpl::fooAdvanced(
CallContext<FooParams, test::TestTailCallee::TailResult> context) {
kj::Promise<void> TestTailCalleeImpl::foo(FooContext context) {
++callCount;
auto params = context.getParams();
......@@ -964,16 +964,16 @@ kj::Promise<void> TestTailCalleeImpl::fooAdvanced(
TestMoreStuffImpl::TestMoreStuffImpl(int& callCount): callCount(callCount) {}
kj::Promise<void> TestMoreStuffImpl::getCallSequence(
GetCallSequenceParams::Reader params, GetCallSequenceResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::getCallSequence(GetCallSequenceContext context) {
auto result = context.getResults();
result.setN(callCount++);
return kj::READY_NOW;
}
kj::Promise<void> TestMoreStuffImpl::callFoo(
CallFooParams::Reader params, CallFooResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::callFoo(CallFooContext context) {
++callCount;
auto params = context.getParams();
auto cap = params.getCap();
auto request = cap.fooRequest();
......@@ -981,34 +981,32 @@ kj::Promise<void> TestMoreStuffImpl::callFoo(
request.setJ(true);
return request.send().then(
[result](Response<test::TestInterface::FooResults>&& response) mutable {
[context](Response<test::TestInterface::FooResults>&& response) mutable {
EXPECT_EQ("foo", response.getX());
result.setS("bar");
context.getResults().setS("bar");
});
}
kj::Promise<void> TestMoreStuffImpl::callFooWhenResolved(
test::TestMoreStuff::CallFooWhenResolvedParams::Reader params,
test::TestMoreStuff::CallFooWhenResolvedResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::callFooWhenResolved(CallFooWhenResolvedContext context) {
++callCount;
auto params = context.getParams();
auto cap = params.getCap();
return cap.whenResolved().then([cap,result]() mutable {
return cap.whenResolved().then([cap,context]() mutable {
auto request = cap.fooRequest();
request.setI(123);
request.setJ(true);
return request.send().then(
[result](Response<test::TestInterface::FooResults>&& response) mutable {
[context](Response<test::TestInterface::FooResults>&& response) mutable {
EXPECT_EQ("foo", response.getX());
result.setS("bar");
context.getResults().setS("bar");
});
});
}
kj::Promise<void> TestMoreStuffImpl::neverReturnAdvanced(
CallContext<NeverReturnParams, NeverReturnResults> context) {
kj::Promise<void> TestMoreStuffImpl::neverReturn(NeverReturnContext context) {
++callCount;
auto paf = kj::newPromiseAndFulfiller<void>();
......@@ -1024,15 +1022,15 @@ kj::Promise<void> TestMoreStuffImpl::neverReturnAdvanced(
return kj::mv(paf.promise);
}
kj::Promise<void> TestMoreStuffImpl::hold(HoldParams::Reader params, HoldResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::hold(HoldContext context) {
++callCount;
auto params = context.getParams();
clientToHold = params.getCap();
return kj::READY_NOW;
}
kj::Promise<void> TestMoreStuffImpl::callHeld(
CallHeldParams::Reader params, CallHeldResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::callHeld(CallHeldContext context) {
++callCount;
auto request = clientToHold.fooRequest();
......@@ -1040,27 +1038,28 @@ kj::Promise<void> TestMoreStuffImpl::callHeld(
request.setJ(true);
return request.send().then(
[result](Response<test::TestInterface::FooResults>&& response) mutable {
[context](Response<test::TestInterface::FooResults>&& response) mutable {
EXPECT_EQ("foo", response.getX());
result.setS("bar");
context.getResults().setS("bar");
});
}
kj::Promise<void> TestMoreStuffImpl::getHeld(
GetHeldParams::Reader params, GetHeldResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::getHeld(GetHeldContext context) {
++callCount;
auto result = context.getResults();
result.setCap(clientToHold);
return kj::READY_NOW;
}
kj::Promise<void> TestMoreStuffImpl::echo(EchoParams::Reader params, EchoResults::Builder result) {
kj::Promise<void> TestMoreStuffImpl::echo(EchoContext context) {
++callCount;
auto params = context.getParams();
auto result = context.getResults();
result.setCap(params.getCap());
return kj::READY_NOW;
}
kj::Promise<void> TestMoreStuffImpl::expectAsyncCancelAdvanced(
CallContext<ExpectAsyncCancelParams, ExpectAsyncCancelResults> context) {
kj::Promise<void> TestMoreStuffImpl::expectAsyncCancel(ExpectAsyncCancelContext context) {
auto cap = context.getParams().getCap();
context.releaseParams();
context.allowAsyncCancellation();
......@@ -1068,7 +1067,7 @@ kj::Promise<void> TestMoreStuffImpl::expectAsyncCancelAdvanced(
}
kj::Promise<void> TestMoreStuffImpl::loop(uint depth, test::TestInterface::Client cap,
CallContext<ExpectAsyncCancelParams, ExpectAsyncCancelResults> context) {
ExpectAsyncCancelContext context) {
if (depth > 100) {
ADD_FAILURE() << "Looped too long, giving up.";
return kj::READY_NOW;
......@@ -1079,15 +1078,14 @@ kj::Promise<void> TestMoreStuffImpl::loop(uint depth, test::TestInterface::Clien
}
}
kj::Promise<void> TestMoreStuffImpl::expectSyncCancelAdvanced(
CallContext<ExpectSyncCancelParams, ExpectSyncCancelResults> context) {
kj::Promise<void> TestMoreStuffImpl::expectSyncCancel(ExpectSyncCancelContext context) {
auto cap = context.getParams().getCap();
context.releaseParams();
return loop(0, cap, context);
}
kj::Promise<void> TestMoreStuffImpl::loop(uint depth, test::TestInterface::Client cap,
CallContext<ExpectSyncCancelParams, ExpectSyncCancelResults> context) {
ExpectSyncCancelContext context) {
if (depth > 100) {
ADD_FAILURE() << "Looped too long, giving up.";
return kj::READY_NOW;
......
......@@ -148,9 +148,9 @@ class TestInterfaceImpl final: public test::TestInterface::Server {
public:
TestInterfaceImpl(int& callCount);
kj::Promise<void> foo(FooParams::Reader params, FooResults::Builder result) override;
kj::Promise<void> foo(FooContext context) override;
kj::Promise<void> bazAdvanced(CallContext<BazParams, BazResults> context) override;
kj::Promise<void> baz(BazContext context) override;
private:
int& callCount;
......@@ -160,9 +160,9 @@ class TestExtendsImpl final: public test::TestExtends::Server {
public:
TestExtendsImpl(int& callCount);
kj::Promise<void> foo(FooParams::Reader params, FooResults::Builder result) override;
kj::Promise<void> foo(FooContext context) override;
kj::Promise<void> graultAdvanced(CallContext<GraultParams, test::TestAllTypes> context) override;
kj::Promise<void> grault(GraultContext context) override;
private:
int& callCount;
......@@ -172,7 +172,7 @@ class TestPipelineImpl final: public test::TestPipeline::Server {
public:
TestPipelineImpl(int& callCount);
kj::Promise<void> getCapAdvanced(CallContext<GetCapParams, GetCapResults> context) override;
kj::Promise<void> getCap(GetCapContext context) override;
private:
int& callCount;
......@@ -180,9 +180,7 @@ private:
class TestCallOrderImpl final: public test::TestCallOrder::Server {
public:
kj::Promise<void> getCallSequence(
GetCallSequenceParams::Reader params,
GetCallSequenceResults::Builder result) override;
kj::Promise<void> getCallSequence(GetCallSequenceContext context) override;
private:
uint count = 0;
......@@ -192,8 +190,7 @@ class TestTailCallerImpl final: public test::TestTailCaller::Server {
public:
TestTailCallerImpl(int& callCount);
kj::Promise<void> fooAdvanced(
CallContext<FooParams, test::TestTailCallee::TailResult> context) override;
kj::Promise<void> foo(FooContext context) override;
private:
int& callCount;
......@@ -203,8 +200,7 @@ class TestTailCalleeImpl final: public test::TestTailCallee::Server {
public:
TestTailCalleeImpl(int& callCount);
kj::Promise<void> fooAdvanced(
CallContext<FooParams, test::TestTailCallee::TailResult> context) override;
kj::Promise<void> foo(FooContext context) override;
private:
int& callCount;
......@@ -214,36 +210,25 @@ class TestMoreStuffImpl final: public test::TestMoreStuff::Server {
public:
TestMoreStuffImpl(int& callCount);
kj::Promise<void> getCallSequence(
GetCallSequenceParams::Reader params,
GetCallSequenceResults::Builder result) override;
kj::Promise<void> getCallSequence(GetCallSequenceContext context) override;
kj::Promise<void> callFoo(
CallFooParams::Reader params,
CallFooResults::Builder result) override;
kj::Promise<void> callFoo(CallFooContext context) override;
kj::Promise<void> callFooWhenResolved(
CallFooWhenResolvedParams::Reader params,
CallFooWhenResolvedResults::Builder result) override;
kj::Promise<void> callFooWhenResolved(CallFooWhenResolvedContext context) override;
kj::Promise<void> neverReturnAdvanced(
CallContext<NeverReturnParams, NeverReturnResults> context) override;
kj::Promise<void> neverReturn(NeverReturnContext context) override;
kj::Promise<void> hold(HoldParams::Reader params, HoldResults::Builder result) override;
kj::Promise<void> hold(HoldContext context) override;
kj::Promise<void> callHeld(CallHeldParams::Reader params,
CallHeldResults::Builder result) override;
kj::Promise<void> callHeld(CallHeldContext context) override;
kj::Promise<void> getHeld(GetHeldParams::Reader params,
GetHeldResults::Builder result) override;
kj::Promise<void> getHeld(GetHeldContext context) override;
kj::Promise<void> echo(EchoParams::Reader params, EchoResults::Builder result) override;
kj::Promise<void> echo(EchoContext context) override;
kj::Promise<void> expectAsyncCancelAdvanced(
CallContext<ExpectAsyncCancelParams, ExpectAsyncCancelResults> context) override;
kj::Promise<void> expectAsyncCancel(ExpectAsyncCancelContext context) override;
kj::Promise<void> expectSyncCancelAdvanced(
CallContext<ExpectSyncCancelParams, ExpectSyncCancelResults> context) override;
kj::Promise<void> expectSyncCancel(ExpectSyncCancelContext context) override;
private:
int& callCount;
......@@ -267,8 +252,8 @@ public:
fulfiller->fulfill();
}
kj::Promise<void> foo(FooParams::Reader params, FooResults::Builder result) {
return impl.foo(params, result);
kj::Promise<void> foo(FooContext context) {
return impl.foo(context);
}
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment