Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 1 | /* |
| 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 | Sample Demo module. This contains the "business logic" for the topology |
| 19 | overlay that we are implementing. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
| 26 | var $log, fs, flash, wss; |
| 27 | |
| 28 | // constants |
| 29 | var srcMessage = 'ppTopovSetSrc', |
| 30 | dstMessage = 'ppTopovSetDst', |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 31 | swapMessage = 'ppTopovSwapSrcDst', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 32 | modeMessage = 'ppTopovSetMode', |
| 33 | nextPathMessage = 'ppTopovNextPath', |
| 34 | prevPathMessage = 'ppTopovPrevPath'; |
| 35 | |
| 36 | // internal state |
| 37 | var currentMode = null; |
| 38 | |
| 39 | |
| 40 | // === --------------------------- |
| 41 | // === Helper functions |
| 42 | |
| 43 | |
| 44 | // === --------------------------- |
| 45 | // === Main API functions |
| 46 | |
| 47 | |
| 48 | function setSrc(node) { |
| 49 | wss.sendEvent(srcMessage, { |
| 50 | id: node.id |
| 51 | }); |
| 52 | flash.flash('Source node: ' + node.id); |
| 53 | } |
| 54 | |
| 55 | function setDst(node) { |
| 56 | wss.sendEvent(dstMessage, { |
| 57 | id: node.id |
| 58 | }); |
| 59 | flash.flash('Destination node: ' + node.id); |
| 60 | } |
| 61 | |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 62 | function swapSrcDst() { |
| 63 | wss.sendEvent(swapMessage) |
| 64 | flash.flash('Source and destination swap'); |
| 65 | } |
| 66 | |
| 67 | function nextPath() { |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 68 | wss.sendEvent(nextPathMessage); |
| 69 | } |
| 70 | |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 71 | function prevPath() { |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 72 | wss.sendEvent(prevPathMessage); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | function setMode(mode) { |
| 77 | if (currentMode === mode) { |
| 78 | $log.debug('(in mode', mode, 'already)'); |
| 79 | } else { |
| 80 | currentMode = mode; |
| 81 | wss.sendEvent(modeMessage, { |
| 82 | mode: mode |
| 83 | }); |
| 84 | flash.flash('Path mode: ' + mode); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // === --------------------------- |
| 89 | // === Module Factory Definition |
| 90 | |
| 91 | angular.module('ovPpTopov', []) |
| 92 | .factory('PathPainterTopovService', |
| 93 | ['$log', 'FnService', 'FlashService', 'WebSocketService', |
| 94 | |
| 95 | function (_$log_, _fs_, _flash_, _wss_) { |
| 96 | $log = _$log_; |
| 97 | fs = _fs_; |
| 98 | flash = _flash_; |
| 99 | wss = _wss_; |
| 100 | |
| 101 | return { |
| 102 | setSrc: setSrc, |
| 103 | setDst: setDst, |
| 104 | setMode: setMode, |
| 105 | nextPath: nextPath, |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 106 | prevPath: prevPath, |
| 107 | swapSrcDst: swapSrcDst |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 108 | }; |
| 109 | }]); |
| 110 | }()); |