Introduce an Rpc concept similar to Action, except without a path.
Generate its specializations, allowing RPCs to be implemented and/or
invoked without their ModuleService aggregate.
JIRA: MDSAL-773
Change-Id: I5fec1ac5c81b908714965e71c3471b954b58d1f9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
final var ex = assertThrows(IncorrectNestingException.class,
() -> codecContext.fromYangInstanceIdentifier(yiid));
assertThat(ex.getMessage(), startsWith("Argument (urn:opendaylight:params:xml:ns:yang:md:sal:knock-knock"
- + "?revision=2018-07-23)knock-knock is not valid child of "));
+ + "?revision=2018-07-23)knock-knock is not valid data tree child of "));
}
@Test
tmp.add(this instanceof RpcGenerator ? new RpcOutputGenerator(output, this)
: new OutputGenerator(output, this));
} else if (stmt instanceof RpcEffectiveStatement rpc) {
- tmp.add(new RpcGenerator(rpc, this));
+ if (this instanceof ModuleGenerator module) {
+ tmp.add(new RpcGenerator(rpc, module));
+ }
} else if (stmt instanceof TypedefEffectiveStatement typedef) {
tmp.add(new TypedefGenerator(typedef, this));
} else if (stmt instanceof AugmentEffectiveStatement augment) {
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl.reactor;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
+import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
+import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
+import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
+import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
+
+abstract class AbstractInvokableGenerator<S extends SchemaTreeEffectiveStatement<?>, R extends CompositeRuntimeType>
+ extends CompositeSchemaTreeGenerator<S, R> {
+ private static final JavaTypeName FUNCTIONAL_INTERFACE_ANNOTATION = JavaTypeName.create(FunctionalInterface.class);
+
+ AbstractInvokableGenerator(final S statement, final AbstractCompositeGenerator<?, ?> parent) {
+ super(statement, parent);
+ }
+
+ @Override
+ final void pushToInference(final SchemaInferenceStack dataTree) {
+ dataTree.enterSchemaTree(statement().argument());
+ }
+
+ @Override
+ final void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
+ // RPCs/Actions are a separate concept
+ }
+
+ @Override
+ final GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
+ final var builder = builderFactory.newGeneratedTypeBuilder(typeName());
+ builder.addImplementsType(implementedType(builderFactory,
+ getChild(this, InputEffectiveStatement.class).getOriginal().getGeneratedType(builderFactory),
+ getChild(this, OutputEffectiveStatement.class).getOriginal().getGeneratedType(builderFactory)));
+ builder.addAnnotation(FUNCTIONAL_INTERFACE_ANNOTATION);
+ defaultImplementedInterace(builder);
+
+ final var module = currentModule();
+ module.addQNameConstant(builder, statement().argument());
+
+ annotateDeprecatedIfNecessary(builder);
+ builderFactory.addCodegenInformation(module, statement(), builder);
+
+ return builder.build();
+ }
+
+ abstract @NonNull ParameterizedType implementedType(TypeBuilderFactory builderFactory, GeneratedType input,
+ GeneratedType output);
+}
*/
package org.opendaylight.mdsal.binding.generator.impl.reactor;
-import static com.google.common.base.Verify.verify;
-
import java.util.List;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultActionRuntimeType;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
+import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
/**
* Generator corresponding to a {@code action} statement.
*/
-final class ActionGenerator extends CompositeSchemaTreeGenerator<ActionEffectiveStatement, ActionRuntimeType> {
- private static final JavaTypeName FUNCTIONAL_INTERFACE_ANNOTATION = JavaTypeName.create(FunctionalInterface.class);
-
+final class ActionGenerator extends AbstractInvokableGenerator<ActionEffectiveStatement, ActionRuntimeType> {
ActionGenerator(final ActionEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
super(statement, parent);
}
- @Override
- void pushToInference(final SchemaInferenceStack dataTree) {
- dataTree.enterSchemaTree(statement().getIdentifier());
- }
-
@Override
ClassPlacement classPlacement() {
// We do not generate Actions for groupings as they are inexact, and do not capture an actual instantiation --
}
@Override
- GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
- final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
- builder.addImplementsType(implementedType(builderFactory));
- builder.addAnnotation(FUNCTIONAL_INTERFACE_ANNOTATION);
- defaultImplementedInterace(builder);
-
- final ModuleGenerator module = currentModule();
- module.addQNameConstant(builder, statement().argument());
-
-// addGetterMethods(builder, builderFactory);
-
- annotateDeprecatedIfNecessary(builder);
- builderFactory.addCodegenInformation(module, statement(), builder);
-
- return builder.build();
- }
-
- private @NonNull Type implementedType(final TypeBuilderFactory builderFactory) {
- final GeneratedType input = getChild(this, InputEffectiveStatement.class).getOriginal()
- .getGeneratedType(builderFactory);
- final GeneratedType output = getChild(this, OutputEffectiveStatement.class).getOriginal()
- .getGeneratedType(builderFactory);
-
- final AbstractCompositeGenerator<?, ?> parent = getParent();
- if (parent instanceof ListGenerator) {
- final KeyGenerator keyGen = ((ListGenerator) parent).keyGenerator();
+ ParameterizedType implementedType(final TypeBuilderFactory builderFactory, final GeneratedType input,
+ final GeneratedType output) {
+ final var parent = getParent();
+ final var parentType = Type.of(parent.typeName());
+ if (parent instanceof ListGenerator list) {
+ final var keyGen = list.keyGenerator();
if (keyGen != null) {
- return BindingTypes.keyedListAction(Type.of(parent.typeName()), keyGen.getGeneratedType(builderFactory),
- input, output);
+ return BindingTypes.keyedListAction(parentType, keyGen.getGeneratedType(builderFactory), input, output);
}
}
-
- return BindingTypes.action(Type.of(parent.typeName()), input, output);
- }
-
- @Override
- void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
- // actions are a separate concept
+ return BindingTypes.action(parentType, input, output);
}
@Override
CompositeRuntimeTypeBuilder<ActionEffectiveStatement, ActionRuntimeType> createBuilder(
final ActionEffectiveStatement statement) {
- return new CompositeRuntimeTypeBuilder<>(statement) {
+ return new InvokableRuntimeTypeBuilder<>(statement) {
@Override
ActionRuntimeType build(final GeneratedType generatedType, final ActionEffectiveStatement statement,
- final List<RuntimeType> childTypes, final List<AugmentRuntimeType> augmentTypes) {
- verify(augmentTypes.isEmpty(), "Unexpected augments %s", augmentTypes);
+ final List<RuntimeType> childTypes) {
return new DefaultActionRuntimeType(generatedType, statement, childTypes);
}
};
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl.reactor;
+
+import static com.google.common.base.Verify.verify;
+
+import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+abstract class InvokableRuntimeTypeBuilder<S extends EffectiveStatement<?, ?>, R extends CompositeRuntimeType>
+ extends CompositeRuntimeTypeBuilder<S, R> {
+ InvokableRuntimeTypeBuilder(final S statement) {
+ super(statement);
+ }
+
+ @Override
+ final R build(final GeneratedType type, final S statement, final List<RuntimeType> children,
+ final List<AugmentRuntimeType> augments) {
+ verify(augments.isEmpty(), "Unexpected augments %s", augments);
+ return build(type, statement, children);
+ }
+
+ abstract @NonNull R build(GeneratedType type, S statement, List<RuntimeType> children);
+}
*/
package org.opendaylight.mdsal.binding.generator.impl.reactor;
+import java.util.List;
+import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultRpcRuntimeType;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
+import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
+import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
/**
* Generator corresponding to a {@code rpc} statement.
*/
// FIXME: hide this once we have RpcRuntimeType
-public final class RpcGenerator extends CompositeSchemaTreeGenerator<RpcEffectiveStatement, RpcRuntimeType> {
- RpcGenerator(final RpcEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
+public final class RpcGenerator extends AbstractInvokableGenerator<RpcEffectiveStatement, RpcRuntimeType> {
+ RpcGenerator(final RpcEffectiveStatement statement, final ModuleGenerator parent) {
super(statement, parent);
}
@Override
- void pushToInference(final SchemaInferenceStack dataTree) {
- dataTree.enterSchemaTree(statement().argument());
- }
-
- @Override
- // FIXME: switch to the same thing we are using for 'action'
ClassPlacement classPlacement() {
- return ClassPlacement.PHANTOM;
- }
-
- @Override
- GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
- throw new UnsupportedOperationException();
+ return ClassPlacement.TOP_LEVEL;
}
@Override
- void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
- // RPCs are a separate concept
+ ParameterizedType implementedType(final TypeBuilderFactory builderFactory, final GeneratedType input,
+ final GeneratedType output) {
+ return BindingTypes.rpc(input, output);
}
@Override
CompositeRuntimeTypeBuilder<RpcEffectiveStatement, RpcRuntimeType> createBuilder(
final RpcEffectiveStatement statement) {
- // RPCs do not have a dedicated interface
- throw new UnsupportedOperationException("Should never be called");
+ return new InvokableRuntimeTypeBuilder<>(statement) {
+ @Override
+ RpcRuntimeType build(final GeneratedType generatedType, final RpcEffectiveStatement statement,
+ final List<RuntimeType> childTypes) {
+ return new DefaultRpcRuntimeType(generatedType, statement, childTypes);
+ }
+ };
}
}
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl.rt;
+
+import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.InvokableRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+abstract sealed class AbstractInvokableRuntimeType<S extends EffectiveStatement<?, ?>>
+ extends AbstractCompositeRuntimeType<S> implements InvokableRuntimeType
+ permits DefaultActionRuntimeType, DefaultRpcRuntimeType {
+ private final @NonNull InputRuntimeType input;
+ private final @NonNull OutputRuntimeType output;
+
+ AbstractInvokableRuntimeType(final GeneratedType bindingType, final S statement, final List<RuntimeType> children) {
+ super(bindingType, statement, children);
+ input = child(children, InputRuntimeType.class);
+ output = child(children, OutputRuntimeType.class);
+ }
+
+ @Override
+ public final InputRuntimeType input() {
+ return input;
+ }
+
+ @Override
+ public final OutputRuntimeType output() {
+ return output;
+ }
+
+ private static <T extends RuntimeType> @NonNull T child(final List<RuntimeType> list, final Class<T> clazz) {
+ return list.stream().filter(clazz::isInstance).map(clazz::cast).findFirst().orElseThrow();
+ }
+}
import com.google.common.annotations.Beta;
import java.util.List;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
@Beta
-public final class DefaultActionRuntimeType extends AbstractCompositeRuntimeType<ActionEffectiveStatement>
+public final class DefaultActionRuntimeType extends AbstractInvokableRuntimeType<ActionEffectiveStatement>
implements ActionRuntimeType {
- private final @NonNull InputRuntimeType input;
- private final @NonNull OutputRuntimeType output;
-
public DefaultActionRuntimeType(final GeneratedType bindingType, final ActionEffectiveStatement statement,
final List<RuntimeType> children) {
super(bindingType, statement, children);
- input = child(children, InputRuntimeType.class);
- output = child(children, OutputRuntimeType.class);
- }
-
- @Override
- public InputRuntimeType input() {
- return input;
- }
-
- @Override
- public OutputRuntimeType output() {
- return output;
- }
-
- private static <T extends RuntimeType> @NonNull T child(final List<RuntimeType> list, final Class<T> clazz) {
- return list.stream().filter(clazz::isInstance).map(clazz::cast).findFirst().orElseThrow();
}
}
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl.rt;
+
+import com.google.common.annotations.Beta;
+import java.util.List;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
+import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
+
+@Beta
+public final class DefaultRpcRuntimeType extends AbstractInvokableRuntimeType<RpcEffectiveStatement>
+ implements RpcRuntimeType {
+ public DefaultRpcRuntimeType(final GeneratedType bindingType, final RpcEffectiveStatement statement,
+ final List<RuntimeType> children) {
+ super(bindingType, statement, children);
+ }
+}
String getListChildContainerMethodReturnTypeName = "";
for (final GeneratedType genType : genTypes) {
- if (!(genType instanceof GeneratedTransferObject)) {
+ if (!(genType instanceof GeneratedTransferObject genTO)) {
if (genType.getName().equals("ListParentContainer")) {
listParentContainerMethodsCount = genType.getMethodDefinitions().size();
} else if (genType.getName().equals("SimpleList")) {
listChildContainerMethodsCount = genType.getMethodDefinitions().size();
}
} else {
- final GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
final List<GeneratedProperty> properties = genTO.getProperties();
final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
int innerListKeyPropertyCount = 0;
for (final GeneratedType type : genTypes) {
- if (!(type instanceof GeneratedTransferObject)) {
+ if (!(type instanceof GeneratedTransferObject genTO)) {
genTypesCount++;
- } else {
- final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
-
- if (genTO.getName().equals("CompositeKeyListKey")) {
- compositeKeyListKeyCount++;
- final List<GeneratedProperty> properties = genTO.getProperties();
- for (final GeneratedProperty prop : properties) {
- if (prop.getName().equals("key1") || prop.getName().equals("key2")) {
- compositeKeyListKeyPropertyCount++;
- }
+ } else if (genTO.getName().equals("CompositeKeyListKey")) {
+ compositeKeyListKeyCount++;
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ for (final GeneratedProperty prop : properties) {
+ if (prop.getName().equals("key1") || prop.getName().equals("key2")) {
+ compositeKeyListKeyPropertyCount++;
}
- genTOsCount++;
- } else if (genTO.getName().equals("InnerListKey")) {
- final List<GeneratedProperty> properties = genTO.getProperties();
- innerListKeyPropertyCount = properties.size();
- genTOsCount++;
}
+ genTOsCount++;
+ } else if (genTO.getName().equals("InnerListKey")) {
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ innerListKeyPropertyCount = properties.size();
+ genTOsCount++;
}
}
assertEquals(1, compositeKeyListKeyCount);
public void testAugmentRpcInput() {
final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/augment-rpc-input.yang"));
- assertEquals(6, genTypes.size());
+ assertEquals(7, genTypes.size());
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal302Test {
@Test
public void testRpcUsesAugment() {
- List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
- "/mdsal302.yang"));
- assertNotNull(generateTypes);
- assertEquals(15, generateTypes.size());
+ final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal302.yang"));
+ assertNotNull(types);
+ assertEquals(16, types.size());
}
}
final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal500.yang"));
assertNotNull(types);
- assertEquals(4, types.size());
+ assertEquals(5, types.size());
- final GeneratedType rpcService = types.get(3);
+ final GeneratedType rpcService = types.get(4);
assertEquals("Mdsal500Service", rpcService.getName());
final List<MethodSignature> methods = rpcService.getMethodDefinitions();
assertEquals(1, methods.size());
final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal552.yang"));
assertNotNull(types);
- assertEquals(5, types.size());
+ assertEquals(6, types.size());
final GeneratedType baz = types.stream()
.filter(type -> BAZ.equals(type.getIdentifier()))
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.Optional;
import java.util.stream.Collectors;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
final var generatedNames = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal666.yang")).stream().map(GeneratedType::getIdentifier)
.collect(Collectors.toUnmodifiableList());
- assertEquals(10, generatedNames.size());
+ assertEquals(11, generatedNames.size());
- // Reserved for future use
- assertEquals(Optional.empty(), generatedNames.stream().filter(FOO::equals).findAny());
- // Grouping is relocated for 'rpc foo' ...
- assertTrue(generatedNames.stream().filter(FOO_GRP::equals).findAny().isPresent());
+ // 'rpc foo' ...
+ assertTrue(generatedNames.stream().anyMatch(FOO::equals));
+ // ... grouping is relocated for 'rpc foo' ...
+ assertTrue(generatedNames.stream().anyMatch(FOO_GRP::equals));
// .. and 'action baz'
- assertTrue(generatedNames.stream().filter(BAZ_GRP::equals).findAny().isPresent());
+ assertTrue(generatedNames.stream().anyMatch(BAZ_GRP::equals));
}
}
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
private static boolean hasBuilderClass(final SchemaNode schemaNode) {
return schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode
- || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition;
+ || schemaNode instanceof NotificationDefinition;
}
private static boolean isSameProperty(final String getterName1, final String getterName2) {
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.opendaylight.yangtools.yang.binding.OpaqueObject;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.binding.RpcOutput;
import org.opendaylight.yangtools.yang.binding.RpcService;
private static final ConcreteType KEYED_LIST_NOTIFICATION = typeForClass(KeyedListNotification.class);
private static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
+ private static final ConcreteType RPC = typeForClass(Rpc.class);
private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
private static final ConcreteType YANG_FEATURE = typeForClass(YangFeature.class);
return parameterizedTypeFor(OPAQUE_OBJECT, type);
}
+ /**
+ * Type specializing {@link Rpc} for a particular type.
+ *
+ * @param input Type input type
+ * @param output Type output type
+ * @return A parameterized type corresponding to {@code Rpc<Input, Output>}
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static @NonNull ParameterizedType rpc(final Type input, final Type output) {
+ return parameterizedTypeFor(RPC, input, output);
+ }
+
/**
* Type specializing {@link RpcResult} for a particular type.
*
@Beta
// FIXME: evaluate integrating with BindingObject
public sealed interface BindingContract<T extends BindingContract<T>>
- permits Action, BaseIdentity, DataContainer, YangFeature {
+ permits Action, BaseIdentity, DataContainer, Rpc, YangFeature {
/**
* Return the interface implemented by this object. This method differs from {@link Object#getClass()} in that it
* returns the interface contract, not a concrete implementation class.
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.binding;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import edu.umd.cs.findbugs.annotations.CheckReturnValue;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+/**
+ * Interface extended by all interfaces generated for a YANG {@code rpc}.
+ */
+public non-sealed interface Rpc<I extends RpcInput, O extends RpcOutput> extends BindingContract<Rpc<I, O>> {
+ /**
+ * Invoke the RPC.
+ *
+ * @param input Input argument
+ * @return Future result of invocation
+ * @throws NullPointerException if any of the arguments are null
+ */
+ @CheckReturnValue
+ @NonNull ListenableFuture<@NonNull RpcResult<@NonNull O>> invoke(@NonNull I input);
+}