Simon Hunt

GUI -- Refactored (condensed) the Topo Event Service.

Change-Id: I58ecac5ed6fe91ae81a44097c3a48d564ccac4bb
...@@ -16,7 +16,11 @@ ...@@ -16,7 +16,11 @@
16 16
17 /* 17 /*
18 ONOS GUI -- Topology Event Module. 18 ONOS GUI -- Topology Event Module.
19 - Defines event handling for events received from the server. 19 +
20 + Defines the conduit between the client and the server:
21 + - provides a clean API for sending events to the server
22 + - dispatches incoming events from the server to the appropriate submodule
23 +
20 */ 24 */
21 25
22 (function () { 26 (function () {
...@@ -26,107 +30,44 @@ ...@@ -26,107 +30,44 @@
26 var $log, wss, wes, tps, tis, tfs; 30 var $log, wss, wes, tps, tis, tfs;
27 31
28 // internal state 32 // internal state
29 - var wsock; 33 + var wsock, evApis;
30 -
31 - var evHandler = {
32 - showSummary: showSummary,
33 - addInstance: addInstance,
34 - updateInstance: updateInstance,
35 - removeInstance: removeInstance,
36 - addDevice: addDevice,
37 - updateDevice: updateDevice,
38 - removeDevice: removeDevice,
39 - addHost: addHost,
40 - updateHost: updateHost,
41 - removeHost: removeHost,
42 - addLink: addLink,
43 - updateLink: updateLink,
44 - removeLink: removeLink
45 -
46 - // TODO: implement remaining handlers..
47 - };
48 -
49 - function unknownEvent(ev) {
50 - $log.warn('Unknown event (ignored):', ev);
51 - }
52 -
53 - // === Event Handlers ===
54 -
55 - // NOTE: --- once these are done, we will collapse them into
56 - // a more compact data structure... but for now, write in full..
57 -
58 - function showSummary(ev) {
59 - $log.debug(' **** Show Summary **** ', ev.payload);
60 - tps.showSummary(ev.payload);
61 - }
62 -
63 - function addInstance(ev) {
64 - $log.debug(' **** Add Instance **** ', ev.payload);
65 - tis.addInstance(ev.payload);
66 - }
67 -
68 - function updateInstance(ev) {
69 - $log.debug(' **** Update Instance **** ', ev.payload);
70 - tis.updateInstance(ev.payload);
71 - }
72 -
73 - function removeInstance(ev) {
74 - $log.debug(' **** Remove Instance **** ', ev.payload);
75 - tis.removeInstance(ev.payload);
76 - }
77 34
78 - function addDevice(ev) { 35 + // ==========================
79 - $log.debug(' **** Add Device **** ', ev.payload);
80 - tfs.addDevice(ev.payload);
81 - }
82 -
83 - function updateDevice(ev) {
84 - $log.debug(' **** Update Device **** ', ev.payload);
85 - tfs.updateDevice(ev.payload);
86 - }
87 -
88 - function removeDevice(ev) {
89 - $log.debug(' **** Remove Device **** ', ev.payload);
90 - tfs.removeDevice(ev.payload);
91 - }
92 -
93 - function addHost(ev) {
94 - $log.debug(' **** Add Host **** ', ev.payload);
95 - tfs.addHost(ev.payload);
96 - }
97 -
98 - function updateHost(ev) {
99 - $log.debug(' **** Update Host **** ', ev.payload);
100 - tfs.updateHost(ev.payload);
101 - }
102 -
103 - function removeHost(ev) {
104 - $log.debug(' **** Remove Host **** ', ev.payload);
105 - tfs.removeHost(ev.payload);
106 - }
107 -
108 - function addLink(ev) {
109 - $log.debug(' **** Add Link **** ', ev.payload);
110 - tfs.addLink(ev.payload);
111 - }
112 -
113 - function updateLink(ev) {
114 - $log.debug(' **** Update Link **** ', ev.payload);
115 - tfs.updateLink(ev.payload);
116 - }
117 36
118 - function removeLink(ev) { 37 + function bindApis() {
119 - $log.debug(' **** Remove Link **** ', ev.payload); 38 + evApis = {
120 - tfs.removeLink(ev.payload); 39 + showSummary: tps,
40 + addInstance: tis,
41 + updateInstance: tis,
42 + removeInstance: tis,
43 + addDevice: tfs,
44 + updateDevice: tfs,
45 + removeDevice: tfs,
46 + addHost: tfs,
47 + updateHost: tfs,
48 + removeHost: tfs,
49 + addLink: tfs,
50 + updateLink: tfs,
51 + removeLink: tfs
52 +
53 + // TODO: add remaining event api vectors
54 + };
121 } 55 }
122 56
123 -
124 - // ==========================
125 -
126 var dispatcher = { 57 var dispatcher = {
127 handleEvent: function (ev) { 58 handleEvent: function (ev) {
128 - (evHandler[ev.event] || unknownEvent)(ev); 59 + var eid = ev.event,
60 + api = evApis[eid] || {},
61 + eh = api[eid];
62 +
63 + if (eh) {
64 + $log.debug(' *EVENT* ', ev.payload);
65 + eh(ev.payload);
66 + } else {
67 + $log.warn('Unknown event (ignored):', ev);
68 + }
129 }, 69 },
70 +
130 sendEvent: function (evType, payload) { 71 sendEvent: function (evType, payload) {
131 if (wsock) { 72 if (wsock) {
132 wes.sendEvent(wsock, evType, payload); 73 wes.sendEvent(wsock, evType, payload);
...@@ -168,6 +109,8 @@ ...@@ -168,6 +109,8 @@
168 tis = _tis_; 109 tis = _tis_;
169 tfs = _tfs_; 110 tfs = _tfs_;
170 111
112 + bindApis();
113 +
171 // TODO: handle "guiSuccessor" functionality (replace host) 114 // TODO: handle "guiSuccessor" functionality (replace host)
172 // TODO: implement retry on close functionality 115 // TODO: implement retry on close functionality
173 116
......