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

Last change on this file since 6921 was 6919, checked in by mies, 15 years ago

Fixed tons of warnings when using CXXFLAGS="-Wall"!

File size: 7.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#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
100 << 0 << del;
101
102 sendMessage( out.str(), network );
103 layerSet.insert(network);
104 }
105
106 //
107 // set layer layout
108 //
109
110 {
111 LayoutType layout = FORCE_LAYOUT;
112 LayoutOrderStrategie order = ORDER_RANDOMLY;
113
114 switch(network){
115 case NETWORK_ID_BASE_COMMUNICATION:
116 layout = FORCE_LAYOUT;
117 order = ORDER_RANDOMLY;
118 break;
119 case NETWORK_ID_BASE_OVERLAY:
120 layout = CIRCULAR_LAYOUT;
121 order = ORDER_BY_ID;
122 break;
123 case NETWORK_ID_MCPO:
124 layout = FORCE_LAYOUT;
125 order = ORDER_RANDOMLY;
126 break;
127 default:
128 break;
129 }
130
131 ostringstream out;
132 out << SET_CLUSTER_LAYOUT_TYPE << del
133 << getCommandID() << del
134 << getTimestamp() << del
135 << getNetworkName(network) << del
136 << 0 << del
137 << layout << del
138 << order << del;
139
140 sendMessage( out.str(), network );
141 }
142
143 } // if(layerSet.find(network) == layerSet.end())
144
145 //
146 // create node
147 //
148
149 ostringstream out;
150 out << CREATE_NODE_TYPE << del
151 << getCommandID() << del
152 << getTimestamp() << del
153 << getNetworkName(network) << del
154 << 0 << del
155 << getNodeNumber(node) << del
156 << 0x00000000 << del
157 << "null" << del;
158
159 sendMessage( out.str(), network );
160}
161
162void DddVis::visConnect(
163 NETWORK_ID network,
164 NodeID& srcnode,
165 NodeID& destnode,
166 string info
167){
168 // if we already have a link between the two nodes
169 // we just ignore the call and leave the old link
170
171 if( networkLinks.exists( network, NodePair(srcnode,destnode) )) return;
172
173 ostringstream out;
174 unsigned long edgekey = networkLinks.insert( network, NodePair(srcnode,destnode) );
175
176 out << CREATE_EDGE_TYPE << del
177 << getCommandID() << del
178 << getTimestamp() << del
179 << getNetworkName(network) << del
180 << 0 << del
181 << getNodeNumber(srcnode) << del
182 << getNodeNumber(destnode) << del
183 << edgekey << del
184 << 0x00000000 << del
185 << "null" << del;
186
187 sendMessage( out.str(), network );
188}
189
190void DddVis::visDisconnect(
191 NETWORK_ID network,
192 NodeID& srcnode,
193 NodeID& destnode,
194 string info
195){
196 if( !networkLinks.exists(network, NodePair(srcnode, destnode)) ) return;
197
198 unsigned long edgekey = networkLinks.get( network, NodePair(srcnode, destnode) );
199 networkLinks.remove( network, NodePair(srcnode, destnode) );
200
201 ostringstream out;
202 out << REMOVE_EDGE_TYPE << del
203 << getCommandID() << del
204 << getTimestamp() << del
205 << getNetworkName(network) << del
206 << edgekey << del;
207
208 sendMessage( out.str(), network );
209}
210
211void DddVis::visShutdown(
212 NETWORK_ID network,
213 NodeID& node,
214 string info
215){
216 ostringstream out;
217
218 out << REMOVE_NODE_TYPE << del
219 << getCommandID() << del
220 << getTimestamp() << del
221 << getNetworkName(network) << del
222 << getNodeNumber(node) << del;
223
224 sendMessage( out.str(), network );
225}
226
227void DddVis::visChangeNodeColor (
228 NETWORK_ID network,
229 NodeID& node,
230 unsigned char r,
231 unsigned char g,
232 unsigned char b
233){
234 NodeSet::iterator i = colorSet.find(node);
235 unsigned int color = makeColor(r,g,b);
236
237 if( i == colorSet.end() ){
238 colorSet.insert(make_pair( node, color )); // color not set for node, set
239 }else{
240 if( i->second == color ) return; // color already set, ignore
241 else i->second = color; // new color, set
242 }
243
244 ostringstream out;
245 out << SET_NODE_COLOR_TYPE << del
246 << getCommandID() << del
247 << getTimestamp() << del
248 << getNetworkName(network) << del
249 << getNodeNumber(node) << del
250 << makeColor(r, g, b) << del;
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
317}} // namespace ariba, common
Note: See TracBrowser for help on using the repository browser.