blob: c4d92c2d7977447ffb704a8511c440a2c86465d2 [file] [log] [blame]
Simon Huntbb596362015-01-26 21:27:42 -08001/*
2 * Copyright 2015 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 ONOS GUI -- Topology Event Module.
Simon Hunt24077f12015-02-04 17:58:21 -080019
20 Defines the conduit between the client and the server:
21 - provides a clean API for sending events to the server
Simon Hunt75ec9692015-02-11 16:40:36 -080022 - dispatches incoming events from the server to the appropriate sub-module
Simon Hunt24077f12015-02-04 17:58:21 -080023
Simon Huntbb596362015-01-26 21:27:42 -080024 */
25
26(function () {
27 'use strict';
28
Simon Huntfd1231a2015-01-26 22:14:51 -080029 // injected refs
Simon Hunt20207df2015-03-10 18:30:14 -070030 var $log, wss, tps, tis, tfs, tss, tts;
Simon Huntfd1231a2015-01-26 22:14:51 -080031
32 // internal state
Simon Hunt20207df2015-03-10 18:30:14 -070033 var handlerMap;
Simon Hunt1894d792015-02-04 17:09:20 -080034
Simon Huntfd1231a2015-01-26 22:14:51 -080035 // ==========================
36
Simon Hunt20207df2015-03-10 18:30:14 -070037 function createHandlerMap() {
38 handlerMap = {
Simon Hunt24077f12015-02-04 17:58:21 -080039 showSummary: tps,
Simon Hunt08f841d02015-02-10 14:39:20 -080040
41 showDetails: tss,
42
Simon Huntf542d842015-02-11 16:20:33 -080043 showTraffic: tts,
44
Simon Hunt24077f12015-02-04 17:58:21 -080045 addInstance: tis,
46 updateInstance: tis,
47 removeInstance: tis,
Simon Hunt08f841d02015-02-10 14:39:20 -080048
Simon Hunt24077f12015-02-04 17:58:21 -080049 addDevice: tfs,
50 updateDevice: tfs,
51 removeDevice: tfs,
52 addHost: tfs,
53 updateHost: tfs,
54 removeHost: tfs,
55 addLink: tfs,
56 updateLink: tfs,
57 removeLink: tfs
Simon Hunt24077f12015-02-04 17:58:21 -080058 };
59 }
60
Simon Huntbb596362015-01-26 21:27:42 -080061 angular.module('ovTopo')
Simon Huntfd1231a2015-01-26 22:14:51 -080062 .factory('TopoEventService',
Simon Hunt20207df2015-03-10 18:30:14 -070063 ['$log', '$location', 'WebSocketService',
Simon Huntac4c6f72015-02-03 19:50:53 -080064 'TopoPanelService', 'TopoInstService', 'TopoForceService',
Simon Huntf542d842015-02-11 16:20:33 -080065 'TopoSelectService', 'TopoTrafficService',
Simon Huntfd1231a2015-01-26 22:14:51 -080066
Simon Hunt20207df2015-03-10 18:30:14 -070067 function (_$log_, $loc, _wss_, _tps_, _tis_, _tfs_, _tss_, _tts_) {
Simon Huntbb596362015-01-26 21:27:42 -080068 $log = _$log_;
Thomas Vachuska329af532015-03-10 02:08:33 -070069 wss = _wss_;
Simon Huntb0ec1e52015-01-28 18:13:49 -080070 tps = _tps_;
Simon Hunt4b668592015-01-29 17:33:53 -080071 tis = _tis_;
Simon Huntac4c6f72015-02-03 19:50:53 -080072 tfs = _tfs_;
Simon Hunt08f841d02015-02-10 14:39:20 -080073 tss = _tss_;
Simon Huntf542d842015-02-11 16:20:33 -080074 tts = _tts_;
Simon Huntbb596362015-01-26 21:27:42 -080075
Simon Hunt20207df2015-03-10 18:30:14 -070076 createHandlerMap();
Simon Hunt24077f12015-02-04 17:58:21 -080077
Thomas Vachuska329af532015-03-10 02:08:33 -070078 function start() {
Simon Hunt20207df2015-03-10 18:30:14 -070079 wss.bindHandlers(handlerMap);
Thomas Vachuska329af532015-03-10 02:08:33 -070080 wss.sendEvent('topoStart');
Simon Hunt20207df2015-03-10 18:30:14 -070081 wss.sendEvent('requestSummary');
Thomas Vachuska329af532015-03-10 02:08:33 -070082 $log.debug('topo comms started');
Simon Huntfd1231a2015-01-26 22:14:51 -080083 }
84
Thomas Vachuska329af532015-03-10 02:08:33 -070085 function stop() {
Thomas Vachuska329af532015-03-10 02:08:33 -070086 wss.sendEvent('topoStop');
Simon Hunt20207df2015-03-10 18:30:14 -070087 wss.unbindHandlers(handlerMap);
Thomas Vachuska329af532015-03-10 02:08:33 -070088 $log.debug('topo comms stopped');
Simon Huntfd1231a2015-01-26 22:14:51 -080089 }
Simon Huntbb596362015-01-26 21:27:42 -080090
91 return {
Thomas Vachuska329af532015-03-10 02:08:33 -070092 start: start,
Simon Hunt237676b52015-03-10 19:04:26 -070093 stop: stop
Simon Hunt737c89f2015-01-28 12:23:19 -080094 };
Simon Huntbb596362015-01-26 21:27:42 -080095 }]);
96}());