Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.drivers.server.gui; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 20 | import org.onosproject.ui.UiExtension; |
| 21 | import org.onosproject.ui.UiExtensionService; |
| 22 | import org.onosproject.ui.UiMessageHandlerFactory; |
| 23 | import org.onosproject.ui.UiView; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 34 | import static org.onosproject.ui.GlyphConstants.ENDSTATION; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 35 | import static org.onosproject.ui.UiView.Category.NETWORK; |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Mechanism to stream CPU data to the GUI. |
| 39 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 40 | @Component(immediate = true, service = CpuUI.class) |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 41 | public class CpuUI { |
| 42 | |
| 43 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 44 | |
| 45 | /** |
| 46 | * GUI Information. |
| 47 | */ |
| 48 | private static final String CPU_ID = "cpu"; |
| 49 | private static final String CPU_TEXT = "Servers-CPU"; |
| 50 | private static final String RES_PATH = "gui"; |
| 51 | private static final ClassLoader CL = CpuUI.class.getClassLoader(); |
| 52 | |
| 53 | // Factory for UI message handlers |
| 54 | private final UiMessageHandlerFactory messageHandlerFactory = |
| 55 | () -> ImmutableList.of(new CpuViewMessageHandler()); |
| 56 | |
| 57 | // List of application views |
| 58 | private final List<UiView> views = ImmutableList.of( |
| 59 | new UiView(NETWORK, CPU_ID, CPU_TEXT, ENDSTATION) |
| 60 | ); |
| 61 | |
| 62 | // Application UI extension |
| 63 | private final UiExtension uiExtension = |
| 64 | new UiExtension.Builder(CL, views) |
| 65 | .messageHandlerFactory(messageHandlerFactory) |
| 66 | .resourcePath(RES_PATH) |
| 67 | .build(); |
| 68 | |
| 69 | /** |
| 70 | * Interact with ONOS. |
| 71 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 73 | protected UiExtensionService uiExtensionService; |
| 74 | |
| 75 | @Activate |
| 76 | protected void activate() { |
| 77 | uiExtensionService.register(uiExtension); |
| 78 | log.info("Started"); |
| 79 | } |
| 80 | |
| 81 | @Deactivate |
| 82 | protected void deactivate() { |
| 83 | uiExtensionService.unregister(uiExtension); |
| 84 | log.info("Stopped"); |
| 85 | } |
| 86 | |
| 87 | } |