Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.net.driver; |
| 17 | |
| 18 | import org.onosproject.net.Annotations; |
| 19 | |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 20 | import java.util.List; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 21 | import java.util.Map; |
Yuta HIGUCHI | d6587b9 | 2018-04-06 19:15:10 -0700 | [diff] [blame] | 22 | import java.util.Optional; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 23 | import java.util.Set; |
| 24 | |
| 25 | /** |
| 26 | * Representation of a specific family of device drivers. Behaviour configuration |
| 27 | * data is stored using {@link org.onosproject.net.Annotations}. |
| 28 | */ |
| 29 | public interface Driver extends Annotations { |
| 30 | |
| 31 | /** |
| 32 | * Returns the driver name. This is expected to be a reverse-DNS, |
| 33 | * Java package-like name. |
| 34 | * |
| 35 | * @return driver name |
| 36 | */ |
| 37 | String name(); |
| 38 | |
| 39 | /** |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 40 | * Returns the parent driver from which this driver inherits behaviours |
| 41 | * and properties. |
| 42 | * |
| 43 | * @return parent driver; null if driver has no parent |
Ray Milkey | ea12532 | 2016-02-16 13:35:09 -0800 | [diff] [blame] | 44 | * @deprecated 1.5.0 Falcon Release |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 45 | */ |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 46 | @Deprecated |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 47 | Driver parent(); |
| 48 | |
| 49 | /** |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 50 | * Returns all the parent drivers from which this driver inherits behaviours |
| 51 | * and properties. |
| 52 | * |
sangyun-han | 04c461d | 2017-03-02 20:29:39 +0900 | [diff] [blame] | 53 | * @return list of parent drivers |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 54 | */ |
| 55 | List<Driver> parents(); |
| 56 | |
| 57 | /** |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 58 | * Returns the device manufacturer name. |
| 59 | * |
| 60 | * @return manufacturer name |
| 61 | */ |
| 62 | String manufacturer(); |
| 63 | |
| 64 | /** |
| 65 | * Returns the device hardware version. |
| 66 | * |
| 67 | * @return hardware version |
| 68 | */ |
| 69 | String hwVersion(); |
| 70 | |
| 71 | /** |
| 72 | * Returns the device software version. |
| 73 | * |
| 74 | * @return software version |
| 75 | */ |
| 76 | String swVersion(); |
| 77 | |
| 78 | /** |
| 79 | * Returns the set of behaviours supported by this driver. |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 80 | * It reflects behaviours of only this driver and not its parent. |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 81 | * |
| 82 | * @return set of device driver behaviours |
| 83 | */ |
| 84 | Set<Class<? extends Behaviour>> behaviours(); |
| 85 | |
| 86 | /** |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 87 | * Returns the implementation class for the specified behaviour. |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 88 | * It reflects behaviours of only this driver and not its parent. |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 89 | * |
| 90 | * @param behaviour behaviour interface |
| 91 | * @return implementation class |
| 92 | */ |
| 93 | Class<? extends Behaviour> implementation(Class<? extends Behaviour> behaviour); |
| 94 | |
| 95 | /** |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 96 | * Indicates whether or not the driver, or any of its parents, support |
HIGUCHI Yuta | 82b3c11 | 2016-01-07 22:22:26 -0800 | [diff] [blame] | 97 | * the specified class of behaviour. |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 98 | * |
| 99 | * @param behaviourClass behaviour class |
| 100 | * @return true if behaviour is supported |
| 101 | */ |
| 102 | boolean hasBehaviour(Class<? extends Behaviour> behaviourClass); |
| 103 | |
| 104 | /** |
| 105 | * Creates an instance of behaviour primed with the specified driver data. |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 106 | * If the current driver does not support the specified behaviour and the |
| 107 | * driver has parent, the request is delegated to the parent driver. |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 108 | * |
| 109 | * @param data driver data context |
| 110 | * @param behaviourClass driver behaviour class |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 111 | * @param <T> type of behaviour |
| 112 | * @return behaviour instance |
| 113 | */ |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 114 | <T extends Behaviour> T createBehaviour(DriverData data, Class<T> behaviourClass); |
| 115 | |
| 116 | /** |
Thomas Vachuska | f133bb1 | 2016-03-31 08:54:49 -0700 | [diff] [blame] | 117 | * Creates an instance of behaviour primed with the specified driver handler. |
Thomas Vachuska | 635c2d7 | 2015-05-08 14:32:13 -0700 | [diff] [blame] | 118 | * If the current driver does not support the specified behaviour and the |
| 119 | * driver has parent, the request is delegated to the parent driver. |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 120 | * |
| 121 | * @param handler driver handler context |
| 122 | * @param behaviourClass driver behaviour class |
| 123 | * @param <T> type of behaviour |
| 124 | * @return behaviour instance |
| 125 | */ |
| 126 | <T extends Behaviour> T createBehaviour(DriverHandler handler, Class<T> behaviourClass); |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Returns the set of annotations as map of key/value properties. |
| 130 | * |
| 131 | * @return map of properties |
| 132 | */ |
| 133 | Map<String, String> properties(); |
| 134 | |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 135 | /** |
Charles Chan | a59f9b76 | 2017-07-30 18:09:44 -0700 | [diff] [blame] | 136 | * Gets the value of given property name. |
| 137 | * If the driver does not define the property, a BFS will be performed to search its ancestors. |
| 138 | * |
| 139 | * @param name property name |
| 140 | * @return the value of the property, |
| 141 | * or null if the property is not defined in this driver nor in any of its ancestors |
| 142 | */ |
| 143 | String getProperty(String name); |
| 144 | |
| 145 | /** |
Yuta HIGUCHI | d6587b9 | 2018-04-06 19:15:10 -0700 | [diff] [blame] | 146 | * Gets the value of given property name. |
| 147 | * If the driver does not define the property, a BFS will be performed to search its ancestors. |
| 148 | * |
| 149 | * @param name property name |
| 150 | * @param defaultValue to use if the property is not defined in this driver nor in any of its ancestors |
| 151 | * @return the value of the property, |
| 152 | * or {@code defaultValue} if the property is not defined in this driver nor in any of its ancestors |
Yuta HIGUCHI | d6587b9 | 2018-04-06 19:15:10 -0700 | [diff] [blame] | 153 | */ |
| 154 | default String getProperty(String name, String defaultValue) { |
| 155 | return Optional.ofNullable(getProperty(name)).orElse(defaultValue); |
| 156 | } |
| 157 | |
| 158 | /** |
Thomas Vachuska | 5c2f813 | 2015-04-08 23:09:08 -0700 | [diff] [blame] | 159 | * Merges the specified driver behaviours and properties into this one, |
| 160 | * giving preference to the other driver when dealing with conflicts. |
| 161 | * |
| 162 | * @param other other driver |
| 163 | * @return merged driver |
| 164 | */ |
| 165 | Driver merge(Driver other); |
| 166 | |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 167 | } |