blob: 10b69093db415a9a4afaa62691645bccf342b7b8 [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
Thomas Vachuska329af532015-03-10 02:08:33 -070030 var $log, vs, wss, tps, tis, tfs, tss, tts;
Simon Huntfd1231a2015-01-26 22:14:51 -080031
32 // internal state
Thomas Vachuska329af532015-03-10 02:08:33 -070033 var handlers;
Simon Hunt1894d792015-02-04 17:09:20 -080034
Simon Huntfd1231a2015-01-26 22:14:51 -080035 // ==========================
36
Thomas Vachuska329af532015-03-10 02:08:33 -070037 function createHandlers() {
38 handlers = {
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
Thomas Vachuska329af532015-03-10 02:08:33 -070061 var nilApi = {};
Simon Huntfd1231a2015-01-26 22:14:51 -080062
Simon Huntbb596362015-01-26 21:27:42 -080063 angular.module('ovTopo')
Simon Huntfd1231a2015-01-26 22:14:51 -080064 .factory('TopoEventService',
Thomas Vachuska329af532015-03-10 02:08:33 -070065 ['$log', '$location', 'VeilService', 'WebSocketService',
Simon Huntac4c6f72015-02-03 19:50:53 -080066 'TopoPanelService', 'TopoInstService', 'TopoForceService',
Simon Huntf542d842015-02-11 16:20:33 -080067 'TopoSelectService', 'TopoTrafficService',
Simon Huntfd1231a2015-01-26 22:14:51 -080068
Thomas Vachuska329af532015-03-10 02:08:33 -070069 function (_$log_, $loc, _vs_, _wss_, _tps_, _tis_, _tfs_, _tss_, _tts_) {
Simon Huntbb596362015-01-26 21:27:42 -080070 $log = _$log_;
Simon Hunt36fc15c2015-02-12 17:02:58 -080071 vs = _vs_;
Thomas Vachuska329af532015-03-10 02:08:33 -070072 wss = _wss_;
Simon Huntb0ec1e52015-01-28 18:13:49 -080073 tps = _tps_;
Simon Hunt4b668592015-01-29 17:33:53 -080074 tis = _tis_;
Simon Huntac4c6f72015-02-03 19:50:53 -080075 tfs = _tfs_;
Simon Hunt08f841d02015-02-10 14:39:20 -080076 tss = _tss_;
Simon Huntf542d842015-02-11 16:20:33 -080077 tts = _tts_;
Simon Huntbb596362015-01-26 21:27:42 -080078
Thomas Vachuska329af532015-03-10 02:08:33 -070079 createHandlers();
Simon Hunt24077f12015-02-04 17:58:21 -080080
Thomas Vachuska329af532015-03-10 02:08:33 -070081 // FIXME: need to handle async socket open to avoid race
82 function start() {
83 wss.bindHandlers(handlers);
84 wss.sendEvent('topoStart');
85 $log.debug('topo comms started');
Simon Huntfd1231a2015-01-26 22:14:51 -080086 }
87
Thomas Vachuska329af532015-03-10 02:08:33 -070088 function stop() {
89 wss.unbindHandlers();
90 wss.sendEvent('topoStop');
91 $log.debug('topo comms stopped');
Simon Huntfd1231a2015-01-26 22:14:51 -080092 }
Simon Huntbb596362015-01-26 21:27:42 -080093
94 return {
Thomas Vachuska329af532015-03-10 02:08:33 -070095 start: start,
96 stop: stop,
97 sendEvent: wss.sendEvent
Simon Hunt737c89f2015-01-28 12:23:19 -080098 };
Simon Huntbb596362015-01-26 21:27:42 -080099 }]);
100}());