Enhancing driver subsystem to support asynchronous event notifications.

Change-Id: I6850aae4f660b8328378da98460529eb58531732
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java b/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
index 6263940..90b3d28 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
@@ -20,8 +20,7 @@
 /**
  * Service for managing drivers and driver behaviour implementations.
  */
-public interface DriverAdminService
-        extends DriverRegistry, BehaviourClassResolver {
+public interface DriverAdminService extends DriverRegistry, BehaviourClassResolver {
 
     /**
      * Returns the set of driver providers currently registered.
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverEvent.java b/core/api/src/main/java/org/onosproject/net/driver/DriverEvent.java
new file mode 100644
index 0000000..238ede4
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverEvent.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.driver;
+
+import org.joda.time.LocalDateTime;
+import org.onosproject.event.AbstractEvent;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Driver configuration change event.
+ */
+public class DriverEvent extends AbstractEvent<DriverEvent.Type, Driver> {
+
+    /**
+     * Type of driver events.
+     */
+    public enum Type {
+        /**
+         * Signifies that the driver configuration has changed in an additive
+         * manner. Either new behaviours were added, their implementations
+         * changed, or there is a new driver entirely.
+         */
+        DRIVER_ENHANCED,
+
+        /**
+         * Signifies that the driver configuration has been reduced in some way.
+         * Either behaviours or their implementations were withdrawn or the
+         * driver was removed entirely.
+         */
+        DRIVER_REDUCED
+    }
+
+    /**
+     * Creates an event of a given type and for the specified driver and the
+     * current time.
+     *
+     * @param type   device event type
+     * @param driver event driver subject
+     */
+    public DriverEvent(Type type, Driver driver) {
+        super(type, driver);
+    }
+
+    /**
+     * Creates an event of a given type and for the specified driver and time.
+     *
+     * @param type   device event type
+     * @param driver event driver subject
+     * @param time   occurrence time
+     */
+    public DriverEvent(Type type, Driver driver, long time) {
+        super(type, driver, time);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("time", new LocalDateTime(time()))
+                .add("type", type())
+                .add("subject", subject())
+                .toString();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverListener.java b/core/api/src/main/java/org/onosproject/net/driver/DriverListener.java
new file mode 100644
index 0000000..e6a6788
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverListener.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.driver;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving driver related events.
+ */
+public interface DriverListener extends EventListener<DriverEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverRegistry.java b/core/api/src/main/java/org/onosproject/net/driver/DriverRegistry.java
index 36a7642..99152c6 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverRegistry.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverRegistry.java
@@ -15,12 +15,15 @@
  */
 package org.onosproject.net.driver;
 
+import org.onosproject.event.ListenerService;
+
 import java.util.Set;
 
 /**
  * Service for obtaining drivers and driver behaviour implementations.
  */
-public interface DriverRegistry extends DriverPrimordialResolver, DriverResolver {
+public interface DriverRegistry extends DriverPrimordialResolver, DriverResolver,
+        ListenerService<DriverEvent, DriverListener> {
 
     /**
      * Returns the overall set of drivers being provided.
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
index 178a9ac..807dd22 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
@@ -28,14 +28,14 @@
 import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID;
 
 public class DefaultDriverTest {
-    private static final String MFR = "mfr";
-    private static final String HW = "hw";
-    private static final String SW = "sw";
-    private static final String KEY = "key";
-    private static final String VALUE = "value";
-    private static final String ROOT = "rootDriver";
-    private static final String CHILD = "childDriver";
-    private static final String GRAND_CHILD = "grandChilDriver";
+    public static final String MFR = "mfr";
+    public static final String HW = "hw";
+    public static final String SW = "sw";
+    public static final String KEY = "key";
+    public static final String VALUE = "value";
+    public static final String ROOT = "rootDriver";
+    public static final String CHILD = "childDriver";
+    public static final String GRAND_CHILD = "grandChildDriver";
 
     @Test
     public void basics() {
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DriverAdminServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/driver/DriverAdminServiceAdapter.java
index f234779..2cfed4a 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DriverAdminServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DriverAdminServiceAdapter.java
@@ -53,4 +53,12 @@
     public Set<Driver> getDrivers() {
         return null;
     }
+
+    @Override
+    public void addListener(DriverListener listener) {
+    }
+
+    @Override
+    public void removeListener(DriverListener listener) {
+    }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DriverServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/driver/DriverServiceAdapter.java
index 813befc..b2644db 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DriverServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DriverServiceAdapter.java
@@ -53,4 +53,12 @@
     public Driver getDriver(String driverName) {
         return null;
     }
+
+    @Override
+    public void addListener(DriverListener listener) {
+    }
+
+    @Override
+    public void removeListener(DriverListener listener) {
+    }
 }