blob: 2f09b316a1917cbea707711ec864c17f6ba5bae1 [file] [log] [blame]
Simon Huntbb282f52014-11-10 11:08:19 -08001/*
2 * Copyright 2014 Open Networking Laboratory
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/*
18 View that traces messages across the websocket.
19
20 @author Simon Hunt
21 */
22
23(function (onos) {
24 'use strict';
25
26 var v,
27 $d,
28 tb,
29 out,
30 which = 'tx',
31 keyDispatch = {
32 space: function () {
33 output(which, "Simon woz 'ere... " + which);
34 which = (which === 'tx') ? 'rx' : 'tx';
35 }
36 };
37
38
39 function addHeader() {
40 tb = $d.append('div')
41 .attr('class', 'toolbar');
42 tb.append('span').text('Web Socket Trace');
43 }
44
45 function addOutput() {
46 out = $d.append('div')
47 .attr('class', 'output');
48 }
49
50 function subtitle(msg) {
51 out.append('p').attr('class', 'subtitle').text(msg);
52 }
53
54 function output(rxtx, msg) {
55 out.append('p').attr('class', rxtx).text(msg);
56 }
57
58 // invoked only the first time the view is loaded
59 function preload(view, ctx, flags) {
60 // NOTE: view.$div is a D3 selection of the view's div
61 v = view;
62 $d = v.$div;
63 addHeader();
64 addOutput();
65
66
67 // hack for now, to allow topo access to our API
68 // TODO: add 'exportApi' and 'importApi' to views.
69 onos.exported.webSockTrace = {
70 subtitle: subtitle,
71 output: output
72 };
73 }
74
75 // invoked just prior to loading the view
76 function reset(view, ctx, flags) {
77
78 }
79
80 // invoked when the view is loaded
81 function load(view, ctx, flags) {
82 resize(view, ctx, flags);
83 view.setKeys(keyDispatch);
84 subtitle('Waiting for messages...');
85 }
86
87 // invoked when the view is resized
88 function resize(view, ctx, flags) {
89 var h = view.height();
90 out.style('height', h + 'px');
91
92 }
93
94 // == register the view here, with links to lifecycle callbacks
95
96 onos.ui.addView('webSockTrace', {
97 preload: preload,
98 load: load,
99 resize: resize
100 });
101
102}(ONOS));