blob: bfa9c32e2d173b6d214e53168e53b30667e3808f [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;
Jonathan Hart17d00452015-04-21 17:10:00 -070019import org.apache.felix.scr.annotations.Component;
alshabib77b88482015-04-07 15:47:50 -070020import org.apache.felix.scr.annotations.Deactivate;
Jonathan Hart17d00452015-04-21 17:10:00 -070021import org.apache.felix.scr.annotations.Service;
22import org.onosproject.net.driver.DefaultDriverProviderService;
23import org.onosproject.net.driver.Driver;
alshabib77b88482015-04-07 15:47:50 -070024import org.onosproject.net.driver.DriverProvider;
25import org.onosproject.net.driver.XmlDriverLoader;
alshabib77b88482015-04-07 15:47:50 -070026import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.io.IOException;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070030import java.io.InputStream;
Jonathan Hart17d00452015-04-21 17:10:00 -070031import java.util.Set;
alshabib77b88482015-04-07 15:47:50 -070032
33/**
34 * Bootstrap for built in drivers.
35 */
Jonathan Hart17d00452015-04-21 17:10:00 -070036@Service
37@Component(immediate = false)
38public class DefaultDrivers implements DefaultDriverProviderService {
alshabib77b88482015-04-07 15:47:50 -070039
40 private final Logger log = LoggerFactory.getLogger(getClass());
41
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070042 private static final String DRIVERS_XML = "/onos-drivers.xml";
43
alshabib77b88482015-04-07 15:47:50 -070044 private DriverProvider provider;
45
46 @Activate
47 protected void activate() {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070048 ClassLoader classLoader = getClass().getClassLoader();
alshabib77b88482015-04-07 15:47:50 -070049 try {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070050 InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML);
51 provider = new XmlDriverLoader(classLoader).loadDrivers(stream);
alshabib77b88482015-04-07 15:47:50 -070052 } catch (IOException e) {
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070053 log.error("Unable to load default drivers", e);
alshabib77b88482015-04-07 15:47:50 -070054 }
alshabib77b88482015-04-07 15:47:50 -070055 log.info("Started");
56 }
57
58 @Deactivate
59 protected void deactivate() {
alshabib77b88482015-04-07 15:47:50 -070060 log.info("Stopped");
61 }
62
Jonathan Hart17d00452015-04-21 17:10:00 -070063 @Override
64 public Set<Driver> getDrivers() {
65 return provider.getDrivers();
66 }
alshabib77b88482015-04-07 15:47:50 -070067}