Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [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 | 54dc352 | 2015-09-09 00:11:45 -0700 | [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.dhcp.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 19 | import org.onosproject.ui.UiExtension; |
| 20 | import org.onosproject.ui.UiExtensionService; |
| 21 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 22 | import org.onosproject.ui.UiView; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 23 | import org.osgi.service.component.annotations.Activate; |
| 24 | import org.osgi.service.component.annotations.Component; |
| 25 | import org.osgi.service.component.annotations.Deactivate; |
| 26 | import org.osgi.service.component.annotations.Reference; |
| 27 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 28 | import org.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; |
| 30 | |
| 31 | import java.util.List; |
| 32 | |
| 33 | import static org.onosproject.ui.UiView.Category.NETWORK; |
| 34 | |
| 35 | /** |
| 36 | * Mechanism to stream data to the GUI. |
| 37 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 38 | @Component(immediate = true, service = DhcpUi.class) |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 39 | public class DhcpUi { |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 40 | |
| 41 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 42 | private static final ClassLoader CL = DhcpUi.class.getClassLoader(); |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 43 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | 54dc352 | 2015-09-09 00:11:45 -0700 | [diff] [blame] | 45 | protected UiExtensionService uiExtensionService; |
| 46 | |
| 47 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 48 | () -> ImmutableList.of(new DhcpViewMessageHandler()); |
| 49 | |
| 50 | private final List<UiView> views = ImmutableList.of( |
| 51 | new UiView(NETWORK, "dhcp", "DHCP Server") |
| 52 | ); |
| 53 | |
| 54 | private final UiExtension uiExtension = |
| 55 | new UiExtension.Builder(CL, views) |
| 56 | .messageHandlerFactory(messageHandlerFactory) |
| 57 | .resourcePath("gui") |
| 58 | .build(); |
| 59 | |
| 60 | @Activate |
| 61 | protected void activate() { |
| 62 | uiExtensionService.register(uiExtension); |
| 63 | log.info("Started"); |
| 64 | } |
| 65 | |
| 66 | @Deactivate |
| 67 | protected void deactivate() { |
| 68 | uiExtensionService.unregister(uiExtension); |
| 69 | log.info("Stopped"); |
| 70 | } |
| 71 | |
| 72 | } |