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 @@ ...@@ -15,6 +15,9 @@
15 */ 15 */
16 package org.onosproject.net.driver; 16 package org.onosproject.net.driver;
17 17
18 +import org.onlab.osgi.DefaultServiceDirectory;
19 +import org.onlab.osgi.ServiceDirectory;
20 +
18 import static com.google.common.base.MoreObjects.toStringHelper; 21 import static com.google.common.base.MoreObjects.toStringHelper;
19 22
20 /** 23 /**
...@@ -24,6 +27,9 @@ public class DefaultDriverHandler implements DriverHandler { ...@@ -24,6 +27,9 @@ public class DefaultDriverHandler implements DriverHandler {
24 27
25 private final DefaultDriverData data; 28 private final DefaultDriverData data;
26 29
30 + // Reference to service directory to provide run-time context.
31 + protected static ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
32 +
27 /** 33 /**
28 * Creates new driver handler with the attached driver data. 34 * Creates new driver handler with the attached driver data.
29 * 35 *
...@@ -49,10 +55,13 @@ public class DefaultDriverHandler implements DriverHandler { ...@@ -49,10 +55,13 @@ public class DefaultDriverHandler implements DriverHandler {
49 } 55 }
50 56
51 @Override 57 @Override
58 + public <T> T get(Class<T> serviceClass) {
59 + return serviceDirectory.get(serviceClass);
60 + }
61 +
62 + @Override
52 public String toString() { 63 public String toString() {
53 - return toStringHelper(this) 64 + return toStringHelper(this).add("data", data).toString();
54 - .add("data", data)
55 - .toString();
56 } 65 }
57 66
58 } 67 }
......
...@@ -43,4 +43,15 @@ public interface DriverHandler { ...@@ -43,4 +43,15 @@ public interface DriverHandler {
43 */ 43 */
44 <T extends Behaviour> T behaviour(Class<T> behaviourClass); 44 <T extends Behaviour> T behaviour(Class<T> behaviourClass);
45 45
46 + /**
47 + * Returns the reference to the implementation of the specified service.
48 + * Provides access to run-time context.
49 + *
50 + * @param serviceClass service class
51 + * @param <T> type of service
52 + * @return service implementation
53 + * @throws org.onlab.osgi.ServiceNotFoundException if service is unavailable
54 + */
55 + <T> T get(Class<T> serviceClass);
56 +
46 } 57 }
......