/* * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.md.sal.binding.impl; import com.google.common.collect.ImmutableSet; import java.util.HashSet; import java.util.Set; import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration; import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService; import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class BindingDOMRpcProviderServiceAdapter { private static final Set GLOBAL = ImmutableSet.of(YangInstanceIdentifier.builder().build()); private final BindingToNormalizedNodeCodec codec; private final DOMRpcProviderService domRpcRegistry; public BindingDOMRpcProviderServiceAdapter(final DOMRpcProviderService domRpcRegistry, final BindingToNormalizedNodeCodec codec) { this.codec = codec; this.domRpcRegistry = domRpcRegistry; } public ObjectRegistration registerRpcImplementation(final Class type, final T implementation) { return register(type,implementation,createDomRpcIdentifiers(type,GLOBAL)); } public ObjectRegistration registerRpcImplementation(final Class type, final T implementation, final Set> paths) { return register(type,implementation,createDomRpcIdentifiers(type,toYangInstanceIdentifiers(paths))); } private ObjectRegistration register(final Class type, final T implementation, final Set domRpcs) { final BindingRpcImplementationAdapter adapter = new BindingRpcImplementationAdapter(codec.getCodecRegistry(), type, implementation); final DOMRpcImplementationRegistration domReg = domRpcRegistry.registerRpcImplementation(adapter, domRpcs); return new BindingRpcAdapterRegistration<>(implementation, domReg); } private Set createDomRpcIdentifiers(final Class type, final Set paths) { final Set rpcs = getRpcSchemaPaths(type); final Set ret = new HashSet<>(); for(final YangInstanceIdentifier path : paths) { for(final SchemaPath rpc : rpcs) { ret.add(DOMRpcIdentifier.create(rpc, path)); } } return ret; } private Set toYangInstanceIdentifiers(final Set> identifiers) { final Set ret = new HashSet<>(); for(final InstanceIdentifier binding: identifiers) { ret.add(codec.toNormalized(binding)); } return ret; } private Set getRpcSchemaPaths(final Class type) { return codec.getRpcMethodToSchemaPath(type).values(); } }