diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index 5508bec..77123ff 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -390,7 +390,7 @@ private: return kj::strTree("org.capnproto.ListList.", suffix, "<", kj::mv(inner), ">"); } case schema::Type::INTERFACE: - return kj::strTree("org.capnproto.AnyPointer.", suffix); + return kj::strTree("org.capnproto.CapabilityList.", suffix); case schema::Type::ANY_POINTER: KJ_FAIL_REQUIRE("unimplemented"); } @@ -1187,7 +1187,19 @@ private: auto typeParamVec = getTypeParameters(field.getContainingStruct()); auto factoryArg = makeFactoryArg(field.getType()); - auto pipelineType = typeName(field.getType(), kj::str("Pipeline")).flatten(); + + kj::String pipelineType; + if (field.getType().asStruct().getProto().getIsGeneric()) { + auto typeArgs = getTypeArguments(structSchema, structSchema, kj::str("Reader")); + pipelineType = kj::strTree( + javaFullName(structSchema), ".Pipeline<", + kj::StringTree(KJ_MAP(arg, typeArgs){ + return kj::strTree(arg); + }, ", "), + ">").flatten(); + } else { + pipelineType = typeName(field.getType(), kj::str("Pipeline")).flatten(); + } return FieldText { kj::strTree( diff --git a/runtime/src/main/java/org/capnproto/Capability.java b/runtime/src/main/java/org/capnproto/Capability.java index 58cdcfd..9a45e7d 100644 --- a/runtime/src/main/java/org/capnproto/Capability.java +++ b/runtime/src/main/java/org/capnproto/Capability.java @@ -2,7 +2,6 @@ package org.capnproto; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -import java.util.concurrent.TimeUnit; public final class Capability { @@ -86,13 +85,6 @@ public final class Capability { } return CompletableFuture.completedFuture(null); } -/* - default - Request newCall(FromPointerBuilder paramsFactory, - FromPointerReader resultsFactory, - long interfaceId, short methodId) { - return Request.fromTypeless(paramsFactory, resultsFactory, this.getHook().newCall(interfaceId, methodId)); - }*/ default Request newCall(long interfaceId, short methodId) { return this.getHook().newCall(interfaceId, methodId); diff --git a/runtime/src/main/java/org/capnproto/CapabilityList.java b/runtime/src/main/java/org/capnproto/CapabilityList.java new file mode 100644 index 0000000..e49066e --- /dev/null +++ b/runtime/src/main/java/org/capnproto/CapabilityList.java @@ -0,0 +1,123 @@ +// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors +// Licensed under the MIT License: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.capnproto; + +public final class CapabilityList { + public static final class Factory extends ListFactory { + Factory() {super (ElementSize.POINTER); } + public final Reader constructReader(SegmentReader segment, + int ptr, + int elementCount, int step, + int structDataSize, short structPointerCount, + int nestingLimit) { + return new Reader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); + } + + public final Builder constructBuilder(SegmentBuilder segment, + int ptr, + int elementCount, int step, + int structDataSize, short structPointerCount) { + return new Builder(segment, ptr, elementCount, step, structDataSize, structPointerCount); + } + } + public static final Factory factory = new Factory(); + + public static final class Reader extends ListReader implements Iterable { + public Reader(SegmentReader segment, + int ptr, + int elementCount, int step, + int structDataSize, short structPointerCount, + int nestingLimit) { + super(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit); + } + + public Capability.Client get(int index) { + return _getPointerElement(Capability.factory, index); + } + + public final class Iterator implements java.util.Iterator { + public Reader list; + public int idx = 0; + public Iterator(Reader list) { + this.list = list; + } + + public Capability.Client next() { + return this.list._getPointerElement(Capability.factory, idx++); + } + public boolean hasNext() { + return idx < list.size(); + } + public void remove() { + throw new UnsupportedOperationException(); + } + } + + public java.util.Iterator iterator() { + return new Iterator(this); + } + } + + public static final class Builder extends ListBuilder implements Iterable { + public Builder(SegmentBuilder segment, int ptr, + int elementCount, int step, + int structDataSize, short structPointerCount){ + super(segment, ptr, elementCount, step, structDataSize, structPointerCount); + } + + public final Capability.Client get(int index) { + return _getPointerElement(Capability.factory, index); + } + + public final void set(int index, Capability.Client value) { + _setPointerElement(Capability.factory, index, value); + } + + public final Reader asReader() { + return new Reader(this.segment, this.ptr, this.elementCount, this.step, + this.structDataSize, this.structPointerCount, + Integer.MAX_VALUE); + } + + public final class Iterator implements java.util.Iterator { + public Builder list; + public int idx = 0; + public Iterator(Builder list) { + this.list = list; + } + + public Capability.Client next() { + return this.list._getPointerElement(Capability.factory, idx++); + } + public boolean hasNext() { + return this.idx < this.list.size(); + } + public void remove() { + throw new UnsupportedOperationException(); + } + } + + public java.util.Iterator iterator() { + return new Iterator(this); + } + } +} diff --git a/runtime/src/test/schema/test.capnp b/runtime/src/test/schema/test.capnp index d6c2f33..cf824c8 100644 --- a/runtime/src/test/schema/test.capnp +++ b/runtime/src/test/schema/test.capnp @@ -50,7 +50,7 @@ interface TestPipeline { struct TestGenerics(Foo, Bar) { foo @0 :Foo; -# rev @1 :TestGenerics(Bar, Foo); + rev @1 :TestGenerics(Bar, Foo); interface Interface(Qux) { }