494118b694a0f9a43c96c5dd747ecf3e3f4ea8f1
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / OsgiProviderContext.xtend
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.impl;
9
10 import java.util.HashMap;
11 import java.util.Hashtable;
12 import java.util.Map;
13
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.osgi.framework.BundleContext;
17
18 import static org.opendaylight.controller.sal.binding.impl.osgi.Constants.*;
19 import static extension org.opendaylight.controller.sal.binding.impl.osgi.PropertiesUtils.*;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
22 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality
23
24 class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext {
25
26     @Property
27     val Map<Class<? extends RpcService>, RpcRegistration<? extends RpcService>> registeredServices
28
29     new(BundleContext ctx, BindingAwareBrokerImpl broker) {
30         super(ctx, broker);
31         _registeredServices = new HashMap();
32     }
33
34     override <T extends RpcService> addRpcImplementation(Class<T> type, T implementation) {
35
36         // TODO Auto-generated method stub
37         val properties = new Hashtable<String, String>();
38         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
39
40         // Fill requirements
41         val salReg = broker.registerRpcImplementation(type, implementation, this, properties)
42         registeredServices.put(type, salReg)
43         return salReg;
44     }
45
46     override <T extends RpcService> addMountRpcImplementation(Class<T> type, InstanceIdentifier mount, T implementation) throws IllegalStateException {
47
48         val properties = new Hashtable<String, String>();
49         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
50
51         // Fill requirements
52         val salReg = broker.registerMountedRpcImplementation(type, implementation, mount, this, properties)
53         registeredServices.put(type, salReg)
54         return salReg;
55     }
56
57     override <T extends RpcService> addRoutedRpcImplementation(Class<T> type, T implementation) throws IllegalStateException {
58         val properties = new Hashtable<String, String>();
59         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
60
61         // Fill requirements
62         val salReg = broker.registerRoutedRpcImplementation(type, implementation, this, properties)
63         registeredServices.put(type, salReg)
64         return salReg;
65     }
66
67     override registerFunctionality(ProviderFunctionality functionality) {
68     
69     }
70
71     override unregisterFunctionality(ProviderFunctionality functionality) {
72     }
73 }