blob: 580691ba2aa2af2b2c62990628d53dd9c3d27cb5 [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;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070030import java.io.InputStream;
alshabib77b88482015-04-07 15:47:50 -070031
32/**
33 * Bootstrap for built in drivers.
34 */
35@Component(immediate = true)
36public class DefaultDrivers {
37
38 private final Logger log = LoggerFactory.getLogger(getClass());
39
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070040 private static final String DRIVERS_XML = "/onos-drivers.xml";
41
alshabib77b88482015-04-07 15:47:50 -070042 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
43 protected DriverAdminService driverService;
44
45 private DriverProvider provider;
46
47 @Activate
48 protected void activate() {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070049 ClassLoader classLoader = getClass().getClassLoader();
alshabib77b88482015-04-07 15:47:50 -070050 try {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070051 InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML);
52 provider = new XmlDriverLoader(classLoader).loadDrivers(stream);
53 driverService.registerProvider(provider);
alshabib77b88482015-04-07 15:47:50 -070054 } catch (IOException e) {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070055 log.error("Unable to load default drivers", e);
alshabib77b88482015-04-07 15:47:50 -070056 }
alshabib77b88482015-04-07 15:47:50 -070057 log.info("Started");
58 }
59
60 @Deactivate
61 protected void deactivate() {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070062 if (provider != null) {
63 driverService.unregisterProvider(provider);
64 }
alshabib77b88482015-04-07 15:47:50 -070065 log.info("Stopped");
66 }
67
alshabib77b88482015-04-07 15:47:50 -070068}