blob: 097c24552a324ce31597504c570fbbda9f22ac35 [file] [log] [blame]
Jian Li10a20702016-02-01 16:39:51 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jian Li10a20702016-02-01 16:39:51 -08003 *
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 */
16package org.onosproject.cpman.gui;
17
18import com.google.common.collect.ImmutableList;
Jian Li10a20702016-02-01 16:39:51 -080019import org.onosproject.ui.UiExtension;
20import org.onosproject.ui.UiExtensionService;
21import org.onosproject.ui.UiMessageHandlerFactory;
22import org.onosproject.ui.UiView;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.osgi.service.component.annotations.Activate;
24import org.osgi.service.component.annotations.Component;
25import org.osgi.service.component.annotations.Deactivate;
26import org.osgi.service.component.annotations.Reference;
27import org.osgi.service.component.annotations.ReferenceCardinality;
Jian Li10a20702016-02-01 16:39:51 -080028import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import java.util.List;
32
33import static org.onosproject.ui.UiView.Category.NETWORK;
34
35/**
36 * Mechanism to stream data to the GUI.
37 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038@Component(immediate = true, service = CpmanUI.class)
Jian Li10a20702016-02-01 16:39:51 -080039public class CpmanUI {
40 private static final String CPMAN_ID = "cpman";
41 private static final String CPMAN_TEXT = "Control Plane Manager";
42 private static final String RES_PATH = "gui";
43 private static final ClassLoader CL = CpmanUI.class.getClassLoader();
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jian Li10a20702016-02-01 16:39:51 -080048 protected UiExtensionService uiExtensionService;
49
50 // Factory for UI message handlers
51 private final UiMessageHandlerFactory messageHandlerFactory =
52 () -> ImmutableList.of(new CpmanViewMessageHandler());
53
54 // List of application views
55 private final List<UiView> views = ImmutableList.of(
56 new UiView(NETWORK, CPMAN_ID, CPMAN_TEXT)
57 );
58
59 // Application UI extension
60 private final UiExtension uiExtension =
61 new UiExtension.Builder(CL, views)
62 .messageHandlerFactory(messageHandlerFactory)
63 .resourcePath(RES_PATH)
64 .build();
65
66 @Activate
67 protected void activate() {
68 uiExtensionService.register(uiExtension);
69 log.info("Started");
70 }
71
72 @Deactivate
73 protected void deactivate() {
74 uiExtensionService.unregister(uiExtension);
75 log.info("Stopped");
76 }
77}