blob: 0d8f14006c35ebb4f09b83440c8c3e5cb37d079e [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;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.ui.UiExtension;
26import org.onosproject.ui.UiExtensionService;
27import org.onosproject.ui.UiMessageHandlerFactory;
28import org.onosproject.ui.UiView;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.List;
33
34import 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)
41public 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}