blob: 31fc57aba2db11014836a493ae6f97db284ec3a3 [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
19import org.onosproject.ui.UiExtension;
20import org.onosproject.ui.UiExtensionService;
21import org.onosproject.ui.UiMessageHandlerFactory;
22import org.onosproject.ui.UiView;
23
24import com.google.common.collect.ImmutableList;
25import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Deactivate;
28import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
30import org.apache.felix.scr.annotations.Service;
31
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import java.util.List;
36
37import static org.onosproject.ui.UiView.Category.NETWORK;
38import static org.onosproject.ui.GlyphConstants.ENDSTATION;
39
40/**
41 * Mechanism to stream CPU data to the GUI.
42 */
43@Component(immediate = true, enabled = true)
44@Service(value = CpuUI.class)
45public class CpuUI {
46
47 private final Logger log = LoggerFactory.getLogger(getClass());
48
49 /**
50 * GUI Information.
51 */
52 private static final String CPU_ID = "cpu";
53 private static final String CPU_TEXT = "Servers-CPU";
54 private static final String RES_PATH = "gui";
55 private static final ClassLoader CL = CpuUI.class.getClassLoader();
56
57 // Factory for UI message handlers
58 private final UiMessageHandlerFactory messageHandlerFactory =
59 () -> ImmutableList.of(new CpuViewMessageHandler());
60
61 // List of application views
62 private final List<UiView> views = ImmutableList.of(
63 new UiView(NETWORK, CPU_ID, CPU_TEXT, ENDSTATION)
64 );
65
66 // Application UI extension
67 private final UiExtension uiExtension =
68 new UiExtension.Builder(CL, views)
69 .messageHandlerFactory(messageHandlerFactory)
70 .resourcePath(RES_PATH)
71 .build();
72
73 /**
74 * Interact with ONOS.
75 */
76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 protected UiExtensionService uiExtensionService;
78
79 @Activate
80 protected void activate() {
81 uiExtensionService.register(uiExtension);
82 log.info("Started");
83 }
84
85 @Deactivate
86 protected void deactivate() {
87 uiExtensionService.unregister(uiExtension);
88 log.info("Stopped");
89 }
90
91}