Thomas Vachuska
Committed by Gerrit Code Review

Adding ability for driver handler behaviours to obtain services via the parent handler context.

Change-Id: Icc71a0c5f1fd50a4accd35777aeca7d0d5811bbf
......@@ -15,6 +15,9 @@
*/
package org.onosproject.net.driver;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceDirectory;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
......@@ -24,6 +27,9 @@ public class DefaultDriverHandler implements DriverHandler {
private final DefaultDriverData data;
// Reference to service directory to provide run-time context.
protected static ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
/**
* Creates new driver handler with the attached driver data.
*
......@@ -49,10 +55,13 @@ public class DefaultDriverHandler implements DriverHandler {
}
@Override
public <T> T get(Class<T> serviceClass) {
return serviceDirectory.get(serviceClass);
}
@Override
public String toString() {
return toStringHelper(this)
.add("data", data)
.toString();
return toStringHelper(this).add("data", data).toString();
}
}
......
......@@ -43,4 +43,15 @@ public interface DriverHandler {
*/
<T extends Behaviour> T behaviour(Class<T> behaviourClass);
/**
* Returns the reference to the implementation of the specified service.
* Provides access to run-time context.
*
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
* @throws org.onlab.osgi.ServiceNotFoundException if service is unavailable
*/
<T> T get(Class<T> serviceClass);
}
......