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

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

-visualisierungsänderungen

File size: 7.7 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 );
161}
162
163void DddVis::visConnect(
164 NETWORK_ID network,
165 NodeID& srcnode,
166 NodeID& destnode,
167 string info
168){
169 // if we already have a link between the two nodes
170 // we just ignore the call and leave the old link
171
172 if( networkLinks.exists( network, NodePair(srcnode,destnode) )) return;
173
174 ostringstream out;
175 unsigned long edgekey = networkLinks.insert( network, NodePair(srcnode,destnode) );
176
177 out << CREATE_EDGE_TYPE << del
178 << getCommandID() << del
179 << getTimestamp() << del
180 << getNetworkName(network) << del
181 << 0 << del
182 << getNodeNumber(srcnode) << del
183 << getNodeNumber(destnode) << del
184 << edgekey << del
185 << 0x00000000 << del
186 << "null" << del;
187
188 sendMessage( out.str(), network );
189}
190
191void DddVis::visDisconnect(
192 NETWORK_ID network,
193 NodeID& srcnode,
194 NodeID& destnode,
195 string info
196){
197 if( !networkLinks.exists(network, NodePair(srcnode, destnode)) ) return;
198
199 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
200 networkLinks.remove( network, NodePair(srcnode, destnode) );
201
202 ostringstream out;
203 out << REMOVE_EDGE_TYPE << del
204 << getCommandID() << del
205 << getTimestamp() << del
206 << getNetworkName(network) << del
207 << edgekey << del;
208
209 sendMessage( out.str(), network );
210}
211
212void DddVis::visShutdown(
213 NETWORK_ID network,
214 NodeID& node,
215 string info
216){
217 ostringstream out;
218
219 out << REMOVE_NODE_TYPE << del
220 << getCommandID() << del
221 << getTimestamp() << del
222 << getNetworkName(network) << del
223 << getNodeNumber(node) << del;
224
225 sendMessage( out.str(), network );
226}
227
228void DddVis::visChangeNodeColor (
229 NETWORK_ID network,
230 NodeID& node,
231 unsigned char r,
232 unsigned char g,
233 unsigned char b
234){
[6900]235 NodeSet::iterator i = colorSet.find(node);
236 unsigned int color = makeColor(r,g,b);
237
238 if( i == colorSet.end() ){
239 colorSet.insert(make_pair( node, color )); // color not set for node, set
240 }else{
241 if( i->second == color ) return; // color already set, ignore
242 else i->second = color; // new color, set
243 }
244
[6822]245 ostringstream out;
246 out << SET_NODE_COLOR_TYPE << del
247 << getCommandID() << del
248 << getTimestamp() << del
249 << getNetworkName(network) << del
250 << getNodeNumber(node) << del
251 << makeColor(r, g, b) << del;
252
253 sendMessage( out.str(), network );
254}
255
256int DddVis::makeColor(unsigned char r, unsigned char g, unsigned char b){
257 return ((r<<16)+(g<<8)+b);
258}
259
260void DddVis::visChangeNodeColor (
261 NETWORK_ID network,
262 NodeID& node,
263 NODE_COLORS color
264){
265 unsigned char r = 0;
266 unsigned char g = 0;
267 unsigned char b = 0;
268
269 switch( color ) {
270 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
271 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
272 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
273 }
274
275 visChangeNodeColor( network, node, r, g, b );
276}
277
278void DddVis::visChangeLinkColor (
279 NETWORK_ID network,
280 NodeID& srcnode,
281 NodeID& destnode,
282 unsigned char r,
283 unsigned char g,
284 unsigned char b
285){
286 ostringstream out;
287 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
288
289 out << SET_EDGE_COLOR_TYPE << del
290 << getCommandID() << del
291 << getTimestamp() << del
292 << getNetworkName(network) << del
293 << edgekey << del
294 << makeColor(r, g, b) << del;
295
296 sendMessage( out.str(), network );
297}
298
299void DddVis::visChangeLinkColor (
300 NETWORK_ID network,
301 NodeID& srcnode,
302 NodeID& destnode,
303 NODE_COLORS color
304){
305 unsigned char r = 0;
306 unsigned char g = 0;
307 unsigned char b = 0;
308
309 switch( color ) {
310 case NODE_COLORS_GREY: r = 128; g = 128; b = 128; break;
311 case NODE_COLORS_GREEN: r = 0; g = 200; b = 0; break;
312 case NODE_COLORS_RED: r = 255; g = 0; b = 0; break;
313 }
314
315 visChangeLinkColor( network, srcnode, destnode, r, g, b );
316}
317
318}} // namespace ariba, common
Note: See TracBrowser for help on using the repository browser.