source: source/ariba/utility/visual/DddVis.cpp@ 9737

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

-small visualization enhancements

File size: 7.9 KB
RevLine 
[6822]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 "DddVis.h"
40
41namespace ariba {
42namespace utility {
43
44const string DddVis::del = ":";
45use_logging_cpp(DddVis);
46
47DddVis::DddVis() : commandid(0) {
48 srand(time(NULL));
49}
50
51DddVis::~DddVis(){
52}
53
54void DddVis::sendMessage( const string msg, NETWORK_ID nid ) {
55 sendSocket( msg + "\n" );
56}
57
58long DddVis::getCommandID() {
59 return ++commandid;
60}
61
62long DddVis::getTimestamp() {
63 return 0; //time(NULL);
64}
65
66unsigned int DddVis::getNodeNumber(const NodeID& node){
67 NodeSet::iterator i = nodeSet.find(node);
68
69 if(i == nodeSet.end()){
70 unsigned int number = node.get(MAX_KEYLENGTH-16, 16);
71 nodeSet.insert(make_pair(node, number));
72 return number;
73 } else {
74 return i->second;
75 }
76}
77
78void DddVis::visCreate(
79 NETWORK_ID network,
80 NodeID& node,
81 string nodename,
82 string info
83){
84 //
85 // create layer first if not already done
86 //
87
88 if(layerSet.find(network) == layerSet.end()){
89
90 //
91 // create layer
92 //
93
94 {
95 ostringstream out;
96 out << CREATE_LAYER_TYPE << del
97 << getCommandID() << del
98 << getTimestamp() << del
99 << getNetworkName(network) << del
[6941]100 << "null" << del
[6822]101 << 0 << del;
102
103 sendMessage( out.str(), network );
104 layerSet.insert(network);
105 }
106
107 //
108 // set layer layout
109 //
110
111 {
112 LayoutType layout = FORCE_LAYOUT;
113 LayoutOrderStrategie order = ORDER_RANDOMLY;
114
115 switch(network){
116 case NETWORK_ID_BASE_COMMUNICATION:
117 layout = FORCE_LAYOUT;
118 order = ORDER_RANDOMLY;
119 break;
120 case NETWORK_ID_BASE_OVERLAY:
121 layout = CIRCULAR_LAYOUT;
122 order = ORDER_BY_ID;
123 break;
124 case NETWORK_ID_MCPO:
125 layout = FORCE_LAYOUT;
126 order = ORDER_RANDOMLY;
127 break;
[6919]128 default:
129 break;
[6822]130 }
131
132 ostringstream out;
133 out << SET_CLUSTER_LAYOUT_TYPE << del
134 << getCommandID() << del
135 << getTimestamp() << del
136 << getNetworkName(network) << del
137 << 0 << del
138 << layout << del
139 << order << del;
140
141 sendMessage( out.str(), network );
142 }
143
144 } // if(layerSet.find(network) == layerSet.end())
145
146 //
147 // create node
148 //
149
150 ostringstream out;
151 out << CREATE_NODE_TYPE << del
152 << getCommandID() << del
153 << getTimestamp() << del
154 << getNetworkName(network) << del
155 << 0 << del
156 << getNodeNumber(node) << del
157 << 0x00000000 << del
158 << "null" << del;
159
160 sendMessage( out.str(), network );
[6954]161
162 //
163 // set node color, if any given
164 //
165
166 if(this->nodecolor != 0){
167 this->visChangeNodeColor(network, node,
168 (nodecolor & 0xFF0000) >> 16, (nodecolor & 0x00FF00) >> 8, nodecolor & 0x0000FF );
169 }
[6822]170}
171
172void DddVis::visConnect(
173 NETWORK_ID network,
174 NodeID& srcnode,
175 NodeID& destnode,
176 string info
177){
178 // if we already have a link between the two nodes
179 // we just ignore the call and leave the old link
180
181 if( networkLinks.exists( network, NodePair(srcnode,destnode) )) return;
182
183 ostringstream out;
184 unsigned long edgekey = networkLinks.insert( network, NodePair(srcnode,destnode) );
185
186 out << CREATE_EDGE_TYPE << del
187 << getCommandID() << del
188 << getTimestamp() << del
189 << getNetworkName(network) << del
190 << 0 << del
191 << getNodeNumber(srcnode) << del
192 << getNodeNumber(destnode) << del
193 << edgekey << del
194 << 0x00000000 << del
195 << "null" << del;
196
197 sendMessage( out.str(), network );
198}
199
200void DddVis::visDisconnect(
201 NETWORK_ID network,
202 NodeID& srcnode,
203 NodeID& destnode,
204 string info
205){
206 if( !networkLinks.exists(network, NodePair(srcnode, destnode)) ) return;
207
208 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
209 networkLinks.remove( network, NodePair(srcnode, destnode) );
210
211 ostringstream out;
212 out << REMOVE_EDGE_TYPE << del
213 << getCommandID() << del
214 << getTimestamp() << del
215 << getNetworkName(network) << del
216 << edgekey << del;
217
218 sendMessage( out.str(), network );
219}
220
221void DddVis::visShutdown(
222 NETWORK_ID network,
223 NodeID& node,
224 string info
225){
226 ostringstream out;
227
228 out << REMOVE_NODE_TYPE << del
229 << getCommandID() << del
230 << getTimestamp() << del
231 << getNetworkName(network) << del
232 << getNodeNumber(node) << del;
233
234 sendMessage( out.str(), network );
235}
236
237void DddVis::visChangeNodeColor (
238 NETWORK_ID network,
239 NodeID& node,
240 unsigned char r,
241 unsigned char g,
242 unsigned char b
243){
244 ostringstream out;
245 out << SET_NODE_COLOR_TYPE << del
[6954]246 << getCommandID() << del
247 << getTimestamp() << del
248 << getNetworkName(network) << del
249 << getNodeNumber(node) << del
250 << makeColor(r, g, b) << del;
[6822]251
252 sendMessage( out.str(), network );
253}
254
255int DddVis::makeColor(unsigned char r, unsigned char g, unsigned char b){
256 return ((r<<16)+(g<<8)+b);
257}
258
259void DddVis::visChangeNodeColor (
260 NETWORK_ID network,
261 NodeID& node,
262 NODE_COLORS color
263){
264 unsigned char r = 0;
265 unsigned char g = 0;
266 unsigned char b = 0;
267
268 switch( color ) {
269 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
270 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
271 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
272 }
273
274 visChangeNodeColor( network, node, r, g, b );
275}
276
277void DddVis::visChangeLinkColor (
278 NETWORK_ID network,
279 NodeID& srcnode,
280 NodeID& destnode,
281 unsigned char r,
282 unsigned char g,
283 unsigned char b
284){
285 ostringstream out;
286 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
287
288 out << SET_EDGE_COLOR_TYPE << del
289 << getCommandID() << del
290 << getTimestamp() << del
291 << getNetworkName(network) << del
292 << edgekey << del
293 << makeColor(r, g, b) << del;
294
295 sendMessage( out.str(), network );
296}
297
298void DddVis::visChangeLinkColor (
299 NETWORK_ID network,
300 NodeID& srcnode,
301 NodeID& destnode,
302 NODE_COLORS color
303){
304 unsigned char r = 0;
305 unsigned char g = 0;
306 unsigned char b = 0;
307
308 switch( color ) {
309 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
310 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
311 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
312 }
313
314 visChangeLinkColor( network, srcnode, destnode, r, g, b );
315}
316
[6954]317void DddVis::visShowNodeLabel (
318 NETWORK_ID network,
319 NodeID& node,
320 string label
321){
322 ostringstream out;
323 out << SET_NODE_INFO_TYPE << del
324 << getCommandID() << del
325 << getTimestamp() << del
326 << getNetworkName(network) << del
327 << getNodeNumber(node) << del
328 << label << del;
329
330 sendMessage( out.str(), network );
331}
332
[6822]333}} // namespace ariba, common
Note: See TracBrowser for help on using the repository browser.