close Warning: Can't use blame annotator:
No changeset 2259 in the repository

source: source/ariba/utility/misc/OvlVis.cpp@ 6211

Last change on this file since 6211 was 5316, checked in by Christoph Mayer, 15 years ago

merge from bootstrap branch

File size: 17.1 KB
RevLine 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#include "OvlVis.h"
40
41namespace ariba {
42namespace utility {
43
44//*****************************************************
45//*****************************************************
46//*****************************************************
47
48use_logging_cpp(OvlVis);
49
50OvlVis::OvlVis() : socket(io_service), socketOpened(false) {
51
52 if( ! Configuration::haveConfig() ) return;
53 if( ! Configuration::instance().exists("DEMO_OvlVisIP") ) return;
54 if( ! Configuration::instance().exists("DEMO_OvlVisPort") ) return;
55
56 string serverIP = Configuration::instance().read<string>("DEMO_OvlVisIP");
57 string serverPort = Configuration::instance().read<string>("DEMO_OvlVisPort");
58 if( serverIP.length() == 0 || serverPort.length() == 0) return;
59
60 logging_debug( "connecting to ovlvis " + serverIP + " on " + serverPort );
61
62 tcp::resolver resolver(io_service);
63 tcp::resolver::query query(
64 serverIP,
65 serverPort,
66 tcp::resolver::query::passive |
67 tcp::resolver::query::address_configured |
68 tcp::resolver::query::numeric_service);
69
70 tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
71 tcp::resolver::iterator end;
72
73 boost::system::error_code error = boost::asio::error::host_not_found;
74 while (error && endpoint_iterator != end){
75 socket.close();
76 socket.connect(*endpoint_iterator++, error);
77 }
78
79 if (error){
80 logging_warn( "OvlVis could not connect to GUI" );
81 } else {
82 socketOpened = true;
83 }
84}
85
86OvlVis::~OvlVis(){
87
88 socket.close();
89
90}
91
92void OvlVis::sendMessage( const string msg, NETWORK_ID nid ) {
93
94 sendSocket( msg );
95
96// {
97// // auto layout
98// ostringstream out;
99//
100// out << "VisMsgOptimizeView" << ";"
101// << Helper::ultos(nid) << ";" // network id is ignored in the message renderer, just renders the current viewed network
102// << "0" << std::endl;
103//
104// sendSocket( out.str() );
105// }
106
107// { // auto zoom
108// ostringstream out;
109//
110// out << "VisMsgOptimizeView" << ";"
111// << Helper::ultos(nid) << ";" // network id is ignored in the message renderer, just renders the current viewed network
112// << "1" << std::endl;
113//
114// sendSocket( out.str() );
115// }
116
117}
118
119void OvlVis::sendSocket(const string msg){
120 if( socket.is_open() && socketOpened )
121 socket.send( boost::asio::buffer(msg) );
122}
123
124//*****************************************************
125//*****************************************************
126//*****************************************************
127
128void OvlVis::visCreate(
129 NETWORK_ID network,
130 NodeID& node,
131 string nodename,
132 string info
133 ){
134
135 ostringstream out;
136
137 out << "VisMsgCreate" << ";"
138 << Helper::ultos(network) << ";"
139 << node.toString() << ";"
140 << nodename << ";"
141 << "" /*netName*/ << ";"
142 << "" /*ip*/ << ";"
143 << "" /*port*/ << ";"
144 << "0" << ";"
145 << info << std::endl;
146
147 sendMessage( out.str(), network );
148}
149
150void OvlVis::visChangeStatus(
151 NETWORK_ID network,
152 NodeID& node,
153 bool enable,
154 string info
155 ){
156
157 ostringstream out;
158
159 out << "VisMsgChangeStatus" << ";"
160 << Helper::ultos(network) << ";"
161 << node.toString() << ";"
162 << (enable ? "1" : "0") << ";"
163 << info << std::endl;
164
165 sendMessage( out.str(), network );
166}
167
168void OvlVis::visConnect(
169 NETWORK_ID network,
170 NodeID& srcnode,
171 NodeID& destnode,
172 string info
173 ){
174
175 // if we already have a link between the two nodes
176 // we just ignore the call and leave the old link
177
178 if( networkLinks.exists( network, NodePair(srcnode,destnode) )) return;
179
180 ostringstream out;
181 unsigned long edgekey = networkLinks.insert( network, NodePair(srcnode,destnode) );
182
183 out << "VisMsgConnect" << ";"
184 << Helper::ultos(network) << ";"
185 << edgekey << ";"
186 << srcnode.toString() << ";"
187 << destnode.toString() << ";"
188 << "0" << ";"
189 << info << std::endl;
190
191 sendMessage( out.str(), network );
192}
193
194void OvlVis::visDisconnect(
195 NETWORK_ID network,
196 NodeID& srcnode,
197 NodeID& destnode,
198 string info
199 ){
200
201 if( !networkLinks.exists(network, NodePair(srcnode, destnode)) ) return;
202
203 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
204 networkLinks.remove( network, NodePair(srcnode, destnode) );
205
206 ostringstream out;
207 out << "VisMsgDisconnect" << ";"
208 << Helper::ultos(network) << ";"
209 << Helper::ultos(edgekey) << ";"
210 << info << std::endl;
211
212 sendMessage( out.str(), network );
213}
214
215void OvlVis::visFailedConnect(
216 NETWORK_ID network,
217 NodeID& srcnode,
218 NodeID& destnode,
219 string info
220 ){
221
222 ostringstream out;
223
224 out << "VisMsgFailedConnect" << ";"
225 << Helper::ultos(network) << ";"
226 << srcnode.toString() << ";"
227 << destnode.toString() << ";"
228 << info << std::endl;
229
230 sendMessage( out.str(), network );
231}
232
233void OvlVis::visShutdown(
234 NETWORK_ID network,
235 NodeID& node,
236 string info
237 ){
238
239 ostringstream out;
240
241 out << "VisMsgShutdown" << ";"
242 << Helper::ultos(network) << ";"
243 << node.toString() << ";"
244 << info << std::endl;
245
246 sendMessage( out.str(), network );
247}
248
249//*****************************************************
250//*****************************************************
251//*****************************************************
252
253void OvlVis::visChangeNodeColor (
254 NETWORK_ID network,
255 NodeID& node,
256 unsigned char r,
257 unsigned char g,
258 unsigned char b
259 ){
260
261 ostringstream out;
262
263 out << "VisMsgChangeNodeColor" << ";"
264 << Helper::ultos(network) << ";"
265 << node.toString() << ";"
266 << ariba::utility::Helper::ultos(r) << ";"
267 << ariba::utility::Helper::ultos(g) << ";"
268 << ariba::utility::Helper::ultos(b) << std::endl;
269
270 sendMessage( out.str(), network );
271}
272
273void OvlVis::visChangeNodeColor (
274 NETWORK_ID network,
275 NodeID& node,
276 NODE_COLORS color
277 ){
278
279 unsigned char r = 0;
280 unsigned char g = 0;
281 unsigned char b = 0;
282
283 switch( color ) {
284 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
285 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
286 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
287 }
288
289 visChangeNodeColor( network, node, r, g, b );
290}
291
292void OvlVis::visChangeNodeIcon (
293 NETWORK_ID network,
294 NodeID& node,
295 ICON_ID icon
296 ){
297
298 ostringstream out;
299
300 out << "VisMsgChangeNodeIcon" << ";"
301 << Helper::ultos(network) << ";"
302 << node.toString() << ";"
303 << Helper::ultos((unsigned int)icon) << std::endl;
304
305 sendMessage( out.str(), network );
306}
307
308void OvlVis::visShowNodeLabel (
309 NETWORK_ID network,
310 NodeID& node,
311 string label
312 ){
313
314 ostringstream out;
315
316 out << "VisMsgShowNodeLabel" << ";"
317 << Helper::ultos(network) << ";"
318 << node.toString() << ";"
319 << label << std::endl;
320
321 sendMessage( out.str(), network );
322}
323
324void OvlVis::visDeleteNodeLabel (
325 NETWORK_ID network,
326 NodeID& node
327 ){
328
329 ostringstream out;
330
331 out << "VisMsgDeleteNodeLable" << ";"
332 << Helper::ultos(network) << ";"
333 << node.toString() << std::endl;
334
335 sendMessage( out.str(), network );
336}
337
338void OvlVis::visShowNodeBubble (
339 NETWORK_ID network,
340 NodeID& node,
341 string label
342 ){
343
344 unsigned long bubbleKey = nodeBubbles.insert( network, node );
345 ostringstream out;
346
347 out << "VisMsgShowNodeBubble" << ";"
348 << Helper::ultos(network) << ";"
349 << Helper::ultos(bubbleKey) << ";"
350 << node.toString() << ";"
351 << label << std::endl;
352
353 sendMessage( out.str(), network );
354}
355
356
357void OvlVis::visDeleteNodeBubble (
358 NETWORK_ID network,
359 NodeID& node
360 ){
361
362 if( !nodeBubbles.exists(network, node)) return;
363
364 unsigned long bubbleID = nodeBubbles.get( network, node );
365 nodeBubbles.remove( network, node );
366
367 ostringstream out;
368
369 out << "VisMsgDeleteBubble" << ";"
370 << Helper::ultos(network) << ";"
371 << Helper::ultos(bubbleID) << std::endl;
372
373 sendMessage( out.str(), network );
374}
375
376void OvlVis::visShowShiftedNodeIcon (
377 NETWORK_ID network,
378 NodeID& node,
379 ICON_ID iconID,
380 unsigned int timeout
381 ){
382
383 unsigned long iconKey = shiftedNodeIcons.insert( network, node );
384
385 ostringstream out;
386
387 out << "VisMsgShowNodeIcon" << ";"
388 << Helper::ultos(network) << ";"
389 << Helper::ultos(iconKey) << ";"
390 << node.toString() << ";"
391 << Helper::ultos(iconID) << std::endl;
392
393 sendMessage( out.str(), network );
394
395 if( timeout > 0 ){
396 TimedoutIcon* obj = new TimedoutIcon( network, node, timeout );
397 obj->startIcon();
398 }
399}
400
401void OvlVis::visDeleteShiftedNodeIcon (
402 NETWORK_ID network,
403 NodeID& node
404 ){
405
406 if( !shiftedNodeIcons.exists(network, node) )return;
407
408 unsigned long iconKey = shiftedNodeIcons.get( network, node );
409 shiftedNodeIcons.remove( network, node );
410
411 ostringstream out;
412
413 out << "VisMsgDeleteIcon" << ";"
414 << Helper::ultos(network) << ";"
415 << Helper::ultos(iconKey) << std::endl;
416
417 sendMessage( out.str(), network );
418}
419
420//*****************************************************
421//*****************************************************
422//*****************************************************
423
424void OvlVis::visChangeLinkWidth (
425 NETWORK_ID network,
426 NodeID& srcnode,
427 NodeID& destnode,
428 unsigned int width
429 ){
430
431 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
432
433 ostringstream out;
434 out << "VisMsgChangeLinkWidth" << ";"
435 << Helper::ultos(network) << ";"
436 << Helper::ultos(edgekey) << ";"
437 << Helper::ultos(width) << std::endl;
438
439 sendMessage( out.str(), network );
440}
441
442void OvlVis::visChangeLinkColor (
443 NETWORK_ID network,
444 NodeID& srcnode,
445 NodeID& destnode,
446 unsigned char r,
447 unsigned char g,
448 unsigned char b
449 ){
450
451 ostringstream out;
452 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
453
454 out << "VisMsgChangeLinkColor" << ";"
455 << Helper::ultos(network) << ";"
456 << Helper::ultos(edgekey) << ";"
457 << Helper::ultos(r) << ";"
458 << Helper::ultos(g) << ";"
459 << Helper::ultos(b) << std::endl;
460
461 sendMessage( out.str(), network );
462}
463
464void OvlVis::visChangeLinkColor (
465 NETWORK_ID network,
466 NodeID& srcnode,
467 NodeID& destnode,
468 NODE_COLORS color
469 ){
470
471 unsigned char r = 0;
472 unsigned char g = 0;
473 unsigned char b = 0;
474
475 switch( color ) {
476 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
477 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
478 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
479 }
480
481 visChangeLinkColor( network, srcnode, destnode, r, g, b );
482}
483
484void OvlVis::visShowLinkLabel (
485 NETWORK_ID network,
486 NodeID& srcnode,
487 NodeID& destnode,
488 string label
489 ){
490
491 ostringstream out;
492 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
493
494 out << "VisMsgShowLinkLabel" << ";"
495 << Helper::ultos(network) << ";"
496 << Helper::ultos(edgekey) << ";"
497 << label << std::endl;
498
499 sendMessage( out.str(), network );
500}
501
502void OvlVis::visDeleteLinkLabel (
503 NETWORK_ID network,
504 NodeID& srcnode,
505 NodeID& destnode
506 ){
507
508 if( !networkLinks.exists(network, NodePair(srcnode, destnode))) return;
509
510 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
511 ostringstream out;
512
513 out << "VisMsgDeleteLinkLabel" << ";"
514 << Helper::ultos(network) << ";"
515 << Helper::ultos(edgekey) << std::endl;
516
517 sendMessage( out.str(), network );
518}
519
520void OvlVis::visShowOnLinkIcon (
521 NETWORK_ID network,
522 NodeID& srcnode,
523 NodeID& destnode,
524 ICON_ID iconID
525 ){
526
527 unsigned long iconKey = onLinkIcons.insert(network, NodePair(srcnode, destnode));
528 ostringstream out;
529
530 out << "VisMsgShowLinkIcon" << ";"
531 << Helper::ultos(network) << ";"
532 << Helper::ultos(iconKey) << ";"
533 << srcnode.toString() << ";"
534 << destnode.toString() << ";"
535 << Helper::ultos(iconID) << std::endl;
536
537 sendMessage( out.str(), network );
538}
539
540void OvlVis::visDeleteOnLinkIcon (
541 NETWORK_ID network,
542 NodeID& srcnode,
543 NodeID& destnode
544 ){
545
546 if( !onLinkIcons.exists(network, NodePair(srcnode, destnode))) return;
547
548 unsigned long iconKey = onLinkIcons.get( network, NodePair(srcnode, destnode) );
549 onLinkIcons.remove( network, NodePair(srcnode, destnode) );
550
551 ostringstream out;
552
553 out << "VisMsgDeleteIcon" << ";"
554 << Helper::ultos(network) << ";"
555 << Helper::ultos(iconKey) << std::endl;
556
557 sendMessage( out.str(), network );
558}
559
560void OvlVis::visShowLinkBubble (
561 NETWORK_ID network,
562 NodeID& srcnode,
563 NodeID& destnode,
564 string label
565 ){
566
567 ostringstream out;
568 unsigned long bubble = linkBubbles.insert( network, NodePair(srcnode, destnode) );
569
570 out << "VisMsgShowLinkBubble" << ";"
571 << Helper::ultos(network) << ";"
572 << Helper::ultos(bubble) << ";"
573 << srcnode.toString() << ";"
574 << destnode.toString() << ";"
575 << label << std::endl;
576
577 sendMessage( out.str(), network );
578}
579
580void OvlVis::visDeleteLinkBubble (
581 NETWORK_ID network,
582 NodeID& srcnode,
583 NodeID& destnode
584 ){
585
586 if( !linkBubbles.exists(network, NodePair(srcnode, destnode))) return;
587
588 ostringstream out;
589 unsigned long bubble = linkBubbles.get( network, NodePair(srcnode, destnode) );
590 linkBubbles.remove( network, NodePair(srcnode, destnode) );
591
592 out << "VisMsgDeleteBubble" << ";"
593 << Helper::ultos(network) << ";"
594 << Helper::ultos(bubble) << std::endl;
595
596 sendMessage( out.str(), network );
597}
598
599//*****************************************************
600//*****************************************************
601//*****************************************************
602
603void OvlVis::visSendMessage (
604 NETWORK_ID network,
605 NodeID& startnode,
606 NodeID& endnode
607 ){
608
609 ostringstream out;
610
611 out << "VisMsgSendMessage" << ";"
612 << Helper::ultos(network) << ";"
613 << startnode.toString() << ";"
614 << endnode.toString() << std::endl;
615
616 sendMessage( out.str(), network );
617}
618
619//*****************************************************
620//*****************************************************
621//*****************************************************
622
623void OvlVis::visCLIOInitMeasurement(
624 NETWORK_ID network,
625 unsigned long edgekey,
626 NodeID& srcnode,
627 NodeID& destnode,
628 string info
629 ){
630
631 ostringstream out;
632
633 out << "VisMsgCLIOInitMeasurement" << ";"
634 << Helper::ultos(network) << ";"
635 << Helper::ultos(edgekey) << ";"
636 << srcnode.toString() << ";"
637 << destnode.toString() << ";"
638 << info << std::endl;
639
640 sendMessage( out.str(), network );
641}
642
643void OvlVis::visCLIOEndMeasurement(
644 NETWORK_ID network,
645 unsigned long edgekey,
646 NodeID& srcnode,
647 NodeID& destnode,
648 string info,
649 string value,
650 string unit
651 ){
652
653 ostringstream out;
654
655 out << "VisMsgCLIOEndMeasurement" << ";"
656 << Helper::ultos(network) << ";"
657 << Helper::ultos(edgekey) << ";"
658 << srcnode.toString() << ";"
659 << destnode.toString() << ";"
660 << info << ";"
661 << value << ";"
662 << unit << std::endl;
663
664 sendMessage( out.str(), network );
665}
666
667//*****************************************************
668//*****************************************************
669//*****************************************************
670
671}} // namespace ariba, common
Note: See TracBrowser for help on using the repository browser.