Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
559a592b
Commit
559a592b
authored
Apr 25, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix dynamic pipelining on 'Capability' type.
Fixes #336
parent
a5a0bc6c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
0 deletions
+83
-0
capability-test.c++
c++/src/capnp/capability-test.c++
+43
-0
dynamic.c++
c++/src/capnp/dynamic.c++
+12
-0
test-util.c++
c++/src/capnp/test-util.c++
+23
-0
test-util.h
c++/src/capnp/test-util.h
+1
-0
test.capnp
c++/src/capnp/test.capnp
+4
-0
No files found.
c++/src/capnp/capability-test.c++
View file @
559a592b
...
...
@@ -338,6 +338,49 @@ TEST(Capability, DynamicClientPipelining) {
EXPECT_EQ
(
1
,
chainedCallCount
);
}
TEST
(
Capability
,
DynamicClientPipelineAnyCap
)
{
kj
::
EventLoop
loop
;
kj
::
WaitScope
waitScope
(
loop
);
int
callCount
=
0
;
int
chainedCallCount
=
0
;
DynamicCapability
::
Client
client
=
test
::
TestPipeline
::
Client
(
kj
::
heap
<
TestPipelineImpl
>
(
callCount
));
auto
request
=
client
.
newRequest
(
"getAnyCap"
);
request
.
set
(
"n"
,
234
);
request
.
set
(
"inCap"
,
test
::
TestInterface
::
Client
(
kj
::
heap
<
TestInterfaceImpl
>
(
chainedCallCount
)));
auto
promise
=
request
.
send
();
auto
outAnyCap
=
promise
.
get
(
"outBox"
).
releaseAs
<
DynamicStruct
>
()
.
get
(
"cap"
).
releaseAs
<
DynamicCapability
>
();
EXPECT_EQ
(
Schema
::
from
<
Capability
>
(),
outAnyCap
.
getSchema
());
auto
outCap
=
outAnyCap
.
castAs
<
DynamicCapability
>
(
Schema
::
from
<
test
::
TestInterface
>
());
auto
pipelineRequest
=
outCap
.
newRequest
(
"foo"
);
pipelineRequest
.
set
(
"i"
,
321
);
auto
pipelinePromise
=
pipelineRequest
.
send
();
auto
pipelineRequest2
=
outCap
.
castAs
<
test
::
TestExtends
>
().
graultRequest
();
auto
pipelinePromise2
=
pipelineRequest2
.
send
();
promise
=
nullptr
;
// Just to be annoying, drop the original promise.
EXPECT_EQ
(
0
,
callCount
);
EXPECT_EQ
(
0
,
chainedCallCount
);
auto
response
=
pipelinePromise
.
wait
(
waitScope
);
EXPECT_EQ
(
"bar"
,
response
.
get
(
"x"
).
as
<
Text
>
());
auto
response2
=
pipelinePromise2
.
wait
(
waitScope
);
checkTestMessage
(
response2
);
EXPECT_EQ
(
3
,
callCount
);
EXPECT_EQ
(
1
,
chainedCallCount
);
}
// =======================================================================================
class
TestInterfaceDynamicImpl
final
:
public
DynamicCapability
::
Server
{
...
...
c++/src/capnp/dynamic.c++
View file @
559a592b
...
...
@@ -388,6 +388,18 @@ DynamicValue::Pipeline DynamicStruct::Pipeline::get(StructSchema::Field field) {
return
DynamicCapability
::
Client
(
type
.
asInterface
(),
typeless
.
getPointerField
(
slot
.
getOffset
()).
asCap
());
case
schema
:
:
Type
::
ANY_POINTER
:
switch
(
type
.
whichAnyPointerKind
())
{
case
schema
:
:
Type
::
AnyPointer
::
Unconstrained
::
STRUCT
:
return
DynamicStruct
::
Pipeline
(
StructSchema
(),
typeless
.
getPointerField
(
slot
.
getOffset
()));
case
schema
:
:
Type
::
AnyPointer
::
Unconstrained
::
CAPABILITY
:
return
DynamicCapability
::
Client
(
Capability
::
Client
(
typeless
.
getPointerField
(
slot
.
getOffset
()).
asCap
()));
default
:
KJ_FAIL_REQUIRE
(
"Can only pipeline on struct and interface fields."
);
}
default
:
KJ_FAIL_REQUIRE
(
"Can only pipeline on struct and interface fields."
);
}
...
...
c++/src/capnp/test-util.c++
View file @
559a592b
...
...
@@ -952,6 +952,29 @@ kj::Promise<void> TestPipelineImpl::getCap(GetCapContext context) {
});
}
kj
::
Promise
<
void
>
TestPipelineImpl
::
getAnyCap
(
GetAnyCapContext
context
)
{
++
callCount
;
auto
params
=
context
.
getParams
();
EXPECT_EQ
(
234
,
params
.
getN
());
auto
cap
=
params
.
getInCap
();
context
.
releaseParams
();
auto
request
=
cap
.
castAs
<
test
::
TestInterface
>
().
fooRequest
();
request
.
setI
(
123
);
request
.
setJ
(
true
);
return
request
.
send
().
then
(
[
this
,
KJ_CPCAP
(
context
)](
Response
<
test
::
TestInterface
::
FooResults
>&&
response
)
mutable
{
EXPECT_EQ
(
"foo"
,
response
.
getX
());
auto
result
=
context
.
getResults
();
result
.
setS
(
"bar"
);
result
.
initOutBox
().
setCap
(
kj
::
heap
<
TestExtendsImpl
>
(
callCount
));
});
}
kj
::
Promise
<
void
>
TestCallOrderImpl
::
getCallSequence
(
GetCallSequenceContext
context
)
{
auto
result
=
context
.
getResults
();
result
.
setN
(
count
++
);
...
...
c++/src/capnp/test-util.h
View file @
559a592b
...
...
@@ -213,6 +213,7 @@ public:
TestPipelineImpl
(
int
&
callCount
);
kj
::
Promise
<
void
>
getCap
(
GetCapContext
context
)
override
;
kj
::
Promise
<
void
>
getAnyCap
(
GetAnyCapContext
context
)
override
;
private
:
int
&
callCount
;
...
...
c++/src/capnp/test.capnp
View file @
559a592b
...
...
@@ -782,10 +782,14 @@ interface TestExtends2 extends(TestExtends) {}
interface TestPipeline {
getCap @0 (n: UInt32, inCap :TestInterface) -> (s: Text, outBox :Box);
testPointers @1 (cap :TestInterface, obj :AnyPointer, list :List(TestInterface)) -> ();
getAnyCap @2 (n: UInt32, inCap :Capability) -> (s: Text, outBox :AnyBox);
struct Box {
cap @0 :TestInterface;
}
struct AnyBox {
cap @0 :Capability;
}
}
interface TestCallOrder {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment