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