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

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

Last change on this file since 2488 was 2488, checked in by stud-tollenaere, 16 years ago

Added a test for openssl library

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