blob: 915a9938b3e70ac410f58d28cb672341884836c6 [file] [log] [blame]
Georgios Katsikas973a2652018-06-28 08:45:47 +02001/*
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
17package org.onosproject.drivers.server.gui;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import com.google.common.collect.ImmutableList;
Georgios Katsikas973a2652018-06-28 08:45:47 +020020import org.onosproject.ui.UiExtension;
21import org.onosproject.ui.UiExtensionService;
22import org.onosproject.ui.UiMessageHandlerFactory;
23import org.onosproject.ui.UiView;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070024import org.osgi.service.component.annotations.Activate;
25import org.osgi.service.component.annotations.Component;
26import org.osgi.service.component.annotations.Deactivate;
27import org.osgi.service.component.annotations.Reference;
28import org.osgi.service.component.annotations.ReferenceCardinality;
Georgios Katsikas973a2652018-06-28 08:45:47 +020029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.List;
33
Georgios Katsikas973a2652018-06-28 08:45:47 +020034import static org.onosproject.ui.GlyphConstants.ENDSTATION;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070035import static org.onosproject.ui.UiView.Category.NETWORK;
Georgios Katsikas973a2652018-06-28 08:45:47 +020036
37/**
38 * Mechanism to stream CPU data to the GUI.
39 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070040@Component(immediate = true, service = CpuUI.class)
Georgios Katsikas973a2652018-06-28 08:45:47 +020041public 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 Milkey86ad7bb2018-09-27 12:32:28 -070072 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Georgios Katsikas973a2652018-06-28 08:45:47 +020073 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}