source: source/ariba/utility/misc/OvlVis.h@ 5424

Last change on this file since 5424 was 3690, checked in by mies, 15 years ago

Merged 20090512-mies-connectors changes r3472:r3689 into trunk.

File size: 9.7 KB
Line 
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#ifndef OVLVIS_H__
40#define OVLVIS_H__
41
42#include <sstream>
43#include <iostream>
44#include <string>
45#include <map>
46#include <boost/utility.hpp>
47#include <boost/asio.hpp>
48#include "ariba/utility/types/NodeID.h"
49#include "ariba/utility/logging/Logging.h"
50#include "ariba/utility/system/Timer.h"
51#include "ariba/utility/misc/Helper.h"
52#include "ariba/utility/misc/KeyMapping.hpp"
53#include "ariba/utility/configuration/Configuration.h"
54
55using std::string;
56using std::map;
57using std::pair;
58using std::make_pair;
59using std::cout;
60using std::ostringstream;
61using boost::asio::ip::tcp;
62using ariba::utility::NodeID;
63using ariba::utility::Configuration;
64using ariba::utility::KeyMapping;
65using ariba::utility::Timer;
66
67namespace ariba {
68namespace utility {
69
70class OvlVis : private boost::noncopyable {
71 use_logging_h(OvlVis);
72public:
73 static OvlVis& instance() { static OvlVis the_inst; return the_inst; }
74
75 typedef enum _NETWORK_ID {
76 NETWORK_ID_BASE_COMMUNICATION = 1,
77 NETWORK_ID_BASE_OVERLAY = 2,
78 NETWORK_ID_EONSON = 3,
79 NETWORK_ID_MCPO = 4,
80 NETWORK_ID_CLIO = 5,
81 NETWORK_ID_VIDEOSTREAM = 6,
82 NETWORK_ID_GAME = 7,
83 NETWORK_ID_SECURITY = 8,
84 } NETWORK_ID;
85
86 //****************************************************************
87 // Node creation, node connections, status, node deletion, ...
88 //****************************************************************
89
90 /**
91 * Create a node in the network that is initially unconnected.
92 */
93 void visCreate (
94 NETWORK_ID network,
95 NodeID& node,
96 string nodename,
97 string info
98 );
99
100 /**
101 * Change the status of a node -> enable/disable a node.
102 */
103 void visChangeStatus(
104 NETWORK_ID network,
105 NodeID& node,
106 bool enable,
107 string info
108 );
109
110 /**
111 * Connect two nodes using a link.
112 */
113 void visConnect (
114 NETWORK_ID network,
115 NodeID& srcnode,
116 NodeID& destnode,
117 string info
118 );
119
120 /**
121 * Disconnect the link between two nodes.
122 */
123 void visDisconnect (
124 NETWORK_ID network,
125 NodeID& srcnode,
126 NodeID& destnode,
127 string info
128 );
129
130 /**
131 * Indicate that the connection procedure
132 * between two nodes failed.
133 */
134 void visFailedConnect (
135 NETWORK_ID network,
136 NodeID& srcnode,
137 NodeID& destnode,
138 string info
139 );
140
141 /**
142 * Delete a node from the network.
143 */
144 void visShutdown (
145 NETWORK_ID network,
146 NodeID& node,
147 string info
148 );
149
150 //****************************************************************
151 // Node manipulation: change color, change icon
152 //****************************************************************
153
154 /**
155 * Change the color of the node.
156 */
157 void visChangeNodeColor (
158 NETWORK_ID network,
159 NodeID& node,
160 unsigned char r,
161 unsigned char g,
162 unsigned char b
163 );
164
165 typedef enum _NODE_COLORS {
166 NODE_COLORS_GREY,
167 NODE_COLORS_GREEN,
168 NODE_COLORS_RED,
169 } NODE_COLORS;
170
171 /**
172 * Change the color of the node.
173 */
174 void visChangeNodeColor (
175 NETWORK_ID network,
176 NodeID& node,
177 NODE_COLORS color
178 );
179
180 /**
181 * The available icons for changing the
182 * icon of a node, showing an icon besides
183 * a node and showing an icon at a link.
184 */
185 typedef enum _ICON_ID {
186 ICON_ID_DEFAULT_NODE = 0,
187 ICON_ID_PC = 1,
188 ICON_ID_PC_WORLD = 2,
189 ICON_ID_FAILURE = 3,
190 ICON_ID_RED_CROSS = 4,
191 ICON_ID_CHARACTER_A = 5,
192 ICON_ID_CHARACTER_W = 6,
193 ICON_ID_CAMERA = 7,
194 } ICON_ID;
195
196 /**
197 * Change the icon of a node.
198 */
199 void visChangeNodeIcon (
200 NETWORK_ID network,
201 NodeID& node,
202 ICON_ID icon
203 );
204
205 /**
206 * Show the label of the node.
207 */
208 void visShowNodeLabel (
209 NETWORK_ID network,
210 NodeID& node,
211 string label
212 );
213
214 /**
215 * Delete the label of the node.
216 */
217 void visDeleteNodeLabel (
218 NETWORK_ID network,
219 NodeID& node
220 );
221
222 /**
223 * Show a bubble at the node.
224 */
225 void visShowNodeBubble (
226 NETWORK_ID network,
227 NodeID& node,
228 string label
229 );
230
231 /**
232 * Delete a bubble at the node.
233 */
234 void visDeleteNodeBubble (
235 NETWORK_ID network,
236 NodeID& node
237 );
238
239 /**
240 * Show an icon besides the node.
241 */
242 void visShowShiftedNodeIcon (
243 NETWORK_ID network,
244 NodeID& node,
245 ICON_ID iconID,
246 unsigned int timeout = 0
247 );
248
249 /**
250 * Delete an icon besides the node
251 */
252 void visDeleteShiftedNodeIcon (
253 NETWORK_ID network,
254 NodeID& node
255 );
256
257 //****************************************************************
258 // Link manipulation: change width, color, show bubbles, icons, ...
259 //****************************************************************
260
261 /**
262 * Change the link width
263 */
264 void visChangeLinkWidth (
265 NETWORK_ID network,
266 NodeID& srcnode,
267 NodeID& destnode,
268 unsigned int width
269 );
270
271 /**
272 * Change the link color
273 */
274 void visChangeLinkColor (
275 NETWORK_ID network,
276 NodeID& srcnode,
277 NodeID& destnode,
278 unsigned char r,
279 unsigned char g,
280 unsigned char b
281 );
282
283 /**
284 * Change the link color
285 */
286 void visChangeLinkColor (
287 NETWORK_ID network,
288 NodeID& srcnode,
289 NodeID& destnode,
290 NODE_COLORS color
291 );
292
293 /**
294 * Show a link label
295 */
296 void visShowLinkLabel (
297 NETWORK_ID network,
298 NodeID& srcnode,
299 NodeID& destnode,
300 string label
301 );
302
303 /**
304 * Delete a link label
305 */
306 void visDeleteLinkLabel (
307 NETWORK_ID network,
308 NodeID& srcnode,
309 NodeID& destnode
310 );
311
312 /**
313 * Show an icon at the link
314 */
315 void visShowOnLinkIcon (
316 NETWORK_ID network,
317 NodeID& srcnode,
318 NodeID& destnode,
319 ICON_ID iconID
320 );
321
322 /**
323 * Delete an icon at the link
324 */
325 void visDeleteOnLinkIcon (
326 NETWORK_ID network,
327 NodeID& srcnode,
328 NodeID& destnode
329 );
330
331 /**
332 * Show a bubble besides the link
333 */
334 void visShowLinkBubble (
335 NETWORK_ID network,
336 NodeID& srcnode,
337 NodeID& destnode,
338 string label
339 );
340
341 /**
342 * Delete a bubble besides the link
343 */
344 void visDeleteLinkBubble (
345 NETWORK_ID network,
346 NodeID& srcnode,
347 NodeID& destnode
348 );
349
350 //****************************************************************
351 // Send message between two nodes
352 //****************************************************************
353
354 /**
355 * Animate the message sending between two nodes
356 */
357 void visSendMessage (
358 NETWORK_ID network,
359 NodeID& startnode,
360 NodeID& endnode
361 );
362
363//*******************************************************
364//*
365 void visCLIOInitMeasurement (
366 NETWORK_ID network,
367 unsigned long edgekey,
368 NodeID& srcnode,
369 NodeID& destnode,
370 string info
371 );
372
373 void visCLIOEndMeasurement (
374 NETWORK_ID network,
375 unsigned long edgekey,
376 NodeID& srcnode,
377 NodeID& destnode,
378 string info,
379 string value,
380 string unit
381 );
382//*
383//*******************************************************
384
385protected:
386 OvlVis();
387 ~OvlVis();
388
389private:
390 void sendMessage( const string msg, NETWORK_ID nid );
391 void sendSocket( const string msg );
392
393 /**
394 * boost asio stuff for connecting to ovlvis
395 */
396 boost::asio::io_service io_service;
397 tcp::socket socket;
398 volatile bool socketOpened;
399
400 typedef pair<NodeID, NodeID> NodePair;
401 typedef KeyMapping<NodePair> NetworkLinks;
402 typedef KeyMapping<NodePair> LinkBubbles;
403 typedef KeyMapping<NodeID> NodeBubbles;
404 typedef KeyMapping<NodeID> ShiftedNodeIcons;
405 typedef KeyMapping<NodePair> OnLinkIcons;
406
407 NetworkLinks networkLinks;
408 LinkBubbles linkBubbles;
409 NodeBubbles nodeBubbles;
410 ShiftedNodeIcons shiftedNodeIcons;
411 OnLinkIcons onLinkIcons;
412
413 class TimedoutIcon : public Timer {
414 private:
415 NETWORK_ID network;
416 NodeID node;
417 unsigned int timeout;
418 public:
419 TimedoutIcon(NETWORK_ID _network, NodeID _node, unsigned int _timeout) :
420 network(_network), node(_node), timeout(_timeout) {
421 }
422
423 virtual ~TimedoutIcon(){
424 Timer::stop();
425 }
426
427 void startIcon(){
428 Timer::setInterval( timeout, true );
429 Timer::start();
430 }
431
432 protected:
433 virtual void eventFunction(){
434 OvlVis::instance().visDeleteShiftedNodeIcon( network, node );
435 delete this;
436 }
437 };
438
439};
440
441}} // namespace ariba, common
442
443#endif // OVLVIS_H__
Note: See TracBrowser for help on using the repository browser.