blob: 44bdeff3eb56828fbe43548c02d59728eebb8754 [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08003 *
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 */
16package org.onosproject.net.driver;
17
Thomas Vachuskad5d113b2015-07-10 12:12:01 -070018import org.onlab.osgi.DefaultServiceDirectory;
19import org.onlab.osgi.ServiceDirectory;
20
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080021import static com.google.common.base.MoreObjects.toStringHelper;
22
23/**
24 * Default implementation of driver handler.
25 */
26public class DefaultDriverHandler implements DriverHandler {
27
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080028 private final DriverData data;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080029
Thomas Vachuskad5d113b2015-07-10 12:12:01 -070030 // Reference to service directory to provide run-time context.
31 protected static ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
32
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080033 /**
34 * Creates new driver handler with the attached driver data.
35 *
36 * @param data driver data to attach
37 */
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080038 public DefaultDriverHandler(DriverData data) {
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080039 this.data = data;
40 }
41
42 @Override
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070043 public Driver driver() {
44 return data.driver();
45 }
46
47 @Override
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080048 public DriverData data() {
49 return data;
50 }
51
52 @Override
53 public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
Thomas Vachuskafacc3f52015-04-10 08:58:36 -070054 return data.driver().createBehaviour(this, behaviourClass);
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080055 }
56
57 @Override
Thomas Vachuskad5d113b2015-07-10 12:12:01 -070058 public <T> T get(Class<T> serviceClass) {
59 return serviceDirectory.get(serviceClass);
60 }
61
62 @Override
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080063 public String toString() {
Thomas Vachuskad5d113b2015-07-10 12:12:01 -070064 return toStringHelper(this).add("data", data).toString();
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080065 }
66
67}