2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.generator.impl.reactor;
10 import java.util.List;
11 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultRpcRuntimeType;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
14 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
15 import org.opendaylight.mdsal.binding.model.ri.Types;
16 import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
17 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
18 import org.opendaylight.yangtools.yang.binding.contract.Naming;
19 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
20 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
23 * Generator corresponding to a {@code rpc} statement.
25 final class RpcGenerator extends AbstractInvokableGenerator<RpcEffectiveStatement, RpcRuntimeType> {
26 RpcGenerator(final RpcEffectiveStatement statement, final ModuleGenerator parent) {
27 super(statement, parent);
31 StatementNamespace namespace() {
32 return StatementNamespace.RPC;
36 ClassPlacement classPlacement() {
37 return ClassPlacement.TOP_LEVEL;
41 void addImplementedType(final TypeBuilderFactory builderFactory, final GeneratedTypeBuilder builder,
42 final GeneratedType input, final GeneratedType output) {
43 builder.addImplementsType(BindingTypes.rpc(input, output));
44 builder.addMethod(Naming.RPC_INVOKE_NAME).setAbstract(true)
45 .addParameter(input, "input")
46 .setReturnType(Types.listenableFutureTypeFor(BindingTypes.rpcResult(output)))
47 .addAnnotation(OVERRIDE_ANNOTATION);
51 CompositeRuntimeTypeBuilder<RpcEffectiveStatement, RpcRuntimeType> createBuilder(
52 final RpcEffectiveStatement statement) {
53 return new InvokableRuntimeTypeBuilder<>(statement) {
55 RpcRuntimeType build(final GeneratedType generatedType, final RpcEffectiveStatement statement,
56 final List<RuntimeType> childTypes) {
57 return new DefaultRpcRuntimeType(generatedType, statement, childTypes);