Jian Li | 10a2070 | 2016-02-01 16:39:51 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jian Li | 10a2070 | 2016-02-01 16:39:51 -0800 | [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.cpman.gui; |
| 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 = CpmanUI.class) |
| 41 | public class CpmanUI { |
| 42 | private static final String CPMAN_ID = "cpman"; |
| 43 | private static final String CPMAN_TEXT = "Control Plane Manager"; |
| 44 | private static final String RES_PATH = "gui"; |
| 45 | private static final ClassLoader CL = CpmanUI.class.getClassLoader(); |
| 46 | |
| 47 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 48 | |
| 49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 50 | protected UiExtensionService uiExtensionService; |
| 51 | |
| 52 | // Factory for UI message handlers |
| 53 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 54 | () -> ImmutableList.of(new CpmanViewMessageHandler()); |
| 55 | |
| 56 | // List of application views |
| 57 | private final List<UiView> views = ImmutableList.of( |
| 58 | new UiView(NETWORK, CPMAN_ID, CPMAN_TEXT) |
| 59 | ); |
| 60 | |
| 61 | // Application UI extension |
| 62 | private final UiExtension uiExtension = |
| 63 | new UiExtension.Builder(CL, views) |
| 64 | .messageHandlerFactory(messageHandlerFactory) |
| 65 | .resourcePath(RES_PATH) |
| 66 | .build(); |
| 67 | |
| 68 | @Activate |
| 69 | protected void activate() { |
| 70 | uiExtensionService.register(uiExtension); |
| 71 | log.info("Started"); |
| 72 | } |
| 73 | |
| 74 | @Deactivate |
| 75 | protected void deactivate() { |
| 76 | uiExtensionService.unregister(uiExtension); |
| 77 | log.info("Stopped"); |
| 78 | } |
| 79 | } |