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