blob: e42e3466bb931f23ca02c22c8994adcb30c16a49 [file] [log] [blame]
alshabib77b88482015-04-07 15:47:50 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.driver.pipeline;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Deactivate;
20import org.apache.felix.scr.annotations.Reference;
21import org.apache.felix.scr.annotations.ReferenceCardinality;
22import org.onosproject.net.driver.DriverAdminService;
23import org.onosproject.net.driver.DriverProvider;
24import org.onosproject.net.driver.XmlDriverLoader;
25import org.apache.felix.scr.annotations.Component;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.io.IOException;
30
31/**
32 * Bootstrap for built in drivers.
33 */
34@Component(immediate = true)
35public class DefaultDrivers {
36
37 private final Logger log = LoggerFactory.getLogger(getClass());
38
39 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
40 protected DriverAdminService driverService;
41
42 private DriverProvider provider;
43
44 @Activate
45 protected void activate() {
46 XmlDriverLoader xmlDriverLoader =
47 new XmlDriverLoader(getClass().getClassLoader());
48 try {
49 provider = xmlDriverLoader.loadDrivers(
50 getClass().getResourceAsStream("/default.xml"));
51 driverService.registerProvider(
52 provider);
53 } catch (IOException e) {
54 log.warn("Unable to load drivers");
55 }
56
57 log.info("Started");
58 }
59
60 @Deactivate
61 protected void deactivate() {
62 driverService.unregisterProvider(provider);
63 log.info("Stopped");
64 }
65
66
67}