Adding ability for driver handler behaviours to obtain services via the parent handler context.
Change-Id: Icc71a0c5f1fd50a4accd35777aeca7d0d5811bbf
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
index 75ae8cd..28fdb2f 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
@@ -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 @@
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 @@
}
@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();
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java b/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
index 6e8a354..202708b 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
@@ -43,4 +43,15 @@
*/
<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);
+
}