Skip to content
This repository
  • 2 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
2  wiselib.testing/algorithms/neighbor_discovery/echo.h
@@ -50,7 +50,7 @@
50 50
  *	If enabled, beacons that are below certain LQI thresholds
51 51
  *	will be ignored.
52 52
  */
53  
-#define ENABLE_LQI_THRESHOLDS
  53
+//#define ENABLE_LQI_THRESHOLDS
54 54
 
55 55
 /**
56 56
  *	If enabled, beacons that are below certain Stability thresholds
46  wiselib.testing/algorithms/semantic_entities/nd_construction.h
@@ -21,17 +21,15 @@
21 21
 #ifndef __WISELIB_ALGORITHMS_SE_CONSTRUCTION_H
22 22
 #define __WISELIB_ALGORITHMS_SE_CONSTRUCTION_H
23 23
 
24  
-#pragma warning("SE construction is not usable yet!")
25  
-
26  
-#include "util/pstl/list_dynamic.h"
27 24
 #include "se_construction_message.h"
28 25
 #include "util/serialization/endian.h"
29 26
 #include <algorithms/neighbor_discovery/echo.h>
30  
-#include <util/pstl/vector_dynamic.h>
  27
+//#include <util/pstl/vector_dynamic.h>
31 28
 #include <util/protobuf/buffer_dynamic.h>
32 29
 #include <util/protobuf/message.h>
33 30
 #include <util/pstl/map_static_vector.h>
34  
-#include <util/pstl/vector_dynamic.h>
  31
+//#include <util/pstl/vector_dynamic.h>
  32
+#include <util/pstl/list_dynamic.h>
35 33
 
36 34
 #define SE_CONSTRUCTION_DEBUG 1
37 35
 
@@ -71,7 +69,8 @@ namespace wiselib {
71 69
 			
72 70
 			typedef string_dynamic<OsModel, Allocator> string_t;
73 71
 			typedef delegate3<void, int, string_t, node_id_t> listener_t;
74  
-			typedef vector_dynamic<OsModel, listener_t, Allocator> listeners_t;
  72
+			//typedef vector_dynamic<OsModel, listener_t, Allocator> listeners_t;
  73
+			typedef list_dynamic<OsModel, listener_t, Allocator> listeners_t;
75 74
 			
76 75
 			typedef node_id_t int_t;
77 76
 			typedef protobuf::buffer_dynamic<OsModel, Allocator> buffer_dynamic_t;
@@ -203,14 +202,14 @@ namespace wiselib {
203 202
 					classes.clear();
204 203
 					 while(p < p_end) {
205 204
 						buffer_dynamic_t buf_class(allocator_);
206  
-						switch(msg_t::field_number(p)) {
207  
-							case PROTOBUF_CLASS:
  205
+					//	switch(msg_t::field_number(p)) {
  206
+					//		case PROTOBUF_CLASS:
208 207
 								Class cls;
209 208
 								msg_t::read(p, field, buf_class.vector());
210 209
 								cls.from_protobuf(buf_class, allocator_);
211 210
 								classes.push_back(cls);
212  
-								break;
213  
-						}
  211
+					//			break;
  212
+					//	}
214 213
 					}
215 214
 				}
216 215
 				
@@ -249,7 +248,8 @@ namespace wiselib {
249 248
 			
250 249
 			int init() {
251 250
 				advertise_interval_ = 10000;
252  
-				listeners.set_allocator(allocator_);
  251
+				//listeners.set_allocator(allocator_);
  252
+				listeners.init(allocator_);
253 253
 				return SUCCESS;
254 254
 			}
255 255
 			
@@ -292,7 +292,7 @@ namespace wiselib {
292 292
 			void on_time(void*) {
293 293
 				//if(trigger_) {
294 294
 					inform_all_neighbors();
295  
-					trigger_ = false;
  295
+					//trigger_ = false;
296 296
 				//}
297 297
 				timer_->template set_timer<self_type, &self_type::on_time>(10000, this, 0);
298 298
 			}
@@ -360,17 +360,24 @@ namespace wiselib {
360 360
 				new_neighbor_state(incoming_source_, other_state);
361 361
 			}
362 362
 			
  363
+			void dbg_arrow(const char* name, node_id_t to_leader) {
  364
+				debug_->debug("ARR %s 0x%x 0x%x $$", name, radio_->id(), to_leader);
  365
+			}
  366
+			
363 367
 			void new_neighbor_state(node_id_t source, State& state) {
364 368
 				for(typename class_vector_t::iterator iter = state_.classes.begin(); iter != state_.classes.end(); ++iter) {
365 369
 					for(typename class_vector_t::iterator niter = state.classes.begin(); niter != state.classes.end(); ++niter) {
366 370
 						if(iter->name == niter->name) {
  371
+							
  372
+							
  373
+							
367 374
 							// other SE, we open -> JOIN if lower than leader,
368 375
 							// else create
369 376
 							if(niter->is_se() && !iter->is_se()) {
370 377
 								if(iter->id > niter->leader) {
371 378
 									iter->to_leader = niter->id;
372 379
 									
373  
-									debug_->debug("ARR %s 0x%x 0x%x $$", iter->name.c_str(), radio_->id(), iter->to_leader);
  380
+									dbg_arrow(iter->name.c_str(), iter->to_leader);
374 381
 									
375 382
 									iter->leader = niter->leader;
376 383
 									notify(SE_LEADER, iter->name, iter->leader);
@@ -386,13 +393,13 @@ namespace wiselib {
386 393
 							else if(!niter->is_se() && !iter->is_se()) {
387 394
 								if(iter->id > niter->id) {
388 395
 									iter->to_leader = iter->id;
389  
-									debug_->debug("ARR %s 0x%x 0x%x $$", iter->name.c_str(), radio_->id(), iter->to_leader);
  396
+									dbg_arrow(iter->name.c_str(), iter->to_leader);
390 397
 									iter->leader = iter->id;
391 398
 									notify(SE_LEADER, iter->name, iter->leader);
392 399
 								}
393 400
 								else {
394 401
 									iter->to_leader = niter->id;
395  
-									debug_->debug("ARR %s 0x%x 0x%x ", iter->name.c_str(), radio_->id(), iter->to_leader);
  402
+									dbg_arrow(iter->name.c_str(), iter->to_leader);
396 403
 									iter->leader = niter->id;
397 404
 									notify(SE_JOIN, iter->name, iter->leader);
398 405
 								}
@@ -404,7 +411,7 @@ namespace wiselib {
404 411
 							else if(!niter->is_se() && iter->is_se()) {
405 412
 								if(niter->id == iter->to_leader) {
406 413
 									iter->to_leader = Radio::NULL_NODE_ID;
407  
-									debug_->debug("ARR %s 0x%x 0x%x $$", iter->name.c_str(), radio_->id(), 0);
  414
+									dbg_arrow(iter->name.c_str(), 0);
408 415
 									notify(SE_LEAVE, iter->name, iter->leader);
409 416
 								}
410 417
 							}
@@ -418,9 +425,8 @@ namespace wiselib {
418 425
 									notify(SE_LEAVE, iter->name, iter->leader);
419 426
 									iter->leader = niter->leader;
420 427
 									iter->to_leader = source;
421  
-									debug_->debug("ARR %s 0x%x 0x%x $$", iter->name.c_str(), radio_->id(), iter->to_leader);
  428
+									dbg_arrow(iter->name.c_str(), iter->to_leader);
422 429
 									notify(SE_JOIN, iter->name, iter->leader);
423  
-									trigger_ = true;
424 430
 								}
425 431
 							}
426 432
 							
@@ -441,6 +447,7 @@ namespace wiselib {
441 447
 						TMethod>(obj));
442 448
 			}
443 449
 			
  450
+			#ifdef SHAWN
444 451
 			template<typename DebugPtr>
445 452
 			void label(DebugPtr d) {
446 453
 				char buf[256];
@@ -454,6 +461,7 @@ namespace wiselib {
454 461
 				*b++ = '\0';
455 462
 				d->debug("%3x: %s", radio_->id(), buf);
456 463
 			}
  464
+#endif
457 465
 			
458 466
 		private:
459 467
 			
@@ -474,7 +482,7 @@ namespace wiselib {
474 482
 			typename Allocator::self_pointer_t allocator_;
475 483
 			typename Debug::self_pointer_t debug_;
476 484
 			typename Neighborhood::self_pointer_t neighborhood_;
477  
-			bool trigger_;
  485
+			//bool trigger_;
478 486
 			size_t advertise_interval_;
479 487
 			listeners_t listeners;
480 488
 	};
18  wiselib.testing/util/allocators/malloc_free_allocator.h
@@ -23,9 +23,12 @@
23 23
 
24 24
 #define KEEP_STATS 0
25 25
 
26  
-template<typename pointer_t>
  26
+/*template<typename pointer_t>
27 27
 void* operator new(size_t size, pointer_t ptr) {
28 28
 	return ptr.raw();
  29
+}*/
  30
+void* operator new(size_t size, void* ptr) {
  31
+	return ptr;
29 32
 }
30 33
 
31 34
 namespace wiselib {
@@ -116,8 +119,9 @@ class MallocFreeAllocator {
116 119
 			#else
117 120
 				void *p = malloc(sizeof(T));
118 121
 			#endif
119  
-			pointer_t<T> r((T*)p);
120  
-			new(r) T;
  122
+			//new(r) T;
  123
+			new(p) T;
  124
+			pointer_t<T> r(reinterpret_cast<T*>(p));
121 125
 			return r;
122 126
 		}
123 127
 		
@@ -127,12 +131,14 @@ class MallocFreeAllocator {
127 131
 				news_++;
128 132
 			#endif
129 133
 			#ifdef ISENSE
130  
-				array_pointer_t<T> r(reinterpret_cast<T*>(isense::malloc(sizeof(T) * n)), n);
  134
+				void *p = isense::malloc(sizeof(T) * n);
131 135
 			#else
132  
-				array_pointer_t<T> r(reinterpret_cast<T*>(malloc(sizeof(T) * n)), n);
  136
+				void *p = malloc(sizeof(T) * n);
133 137
 			#endif
  138
+			array_pointer_t<T> r(reinterpret_cast<T*>(p), n);
134 139
 			for(typename OsModel::size_t i = 0; i < n; i++) {
135  
-				new(pointer_t<T>(&(r.raw()[i]))) T;
  140
+				//new(pointer_t<T>(&(r.raw()[i]))) T;
  141
+				new(&(reinterpret_cast<T*>(p)[i])) T;
136 142
 			}
137 143
 			return r;
138 144
 		}
78  wiselib.testing/util/pstl/list_dynamic.h
@@ -28,15 +28,14 @@ namespace wiselib {
28 28
 			typename Value_P,
29 29
 			typename Allocator_P
30 30
 		>
31  
-		struct DoublyConnectedListNode {
32  
-			typedef DoublyConnectedListNode<Value_P, Allocator_P> self_type;
  31
+		struct SingleConnectedListNode {
  32
+			typedef SingleConnectedListNode<Value_P, Allocator_P> self_type;
33 33
 			typename Allocator_P::template pointer_t<self_type> next;
34  
-			typename Allocator_P::template pointer_t<self_type> prev;
35 34
 			Value_P value;
36 35
 			Value_P& data() { return value; }
37 36
 			const Value_P& data() const { return value; }
38 37
 			
39  
-			DoublyConnectedListNode() { }
  38
+			SingleConnectedListNode() { }
40 39
 		};
41 40
 	
42 41
 	
@@ -72,11 +71,6 @@ namespace wiselib {
72 71
 				
73 72
 				iterator_type& operator++() { node_ = node_->next; return *this; }
74 73
 				
75  
-				iterator_type& operator--() {
76  
-					if(!node_) { node_ = list_->last(); }
77  
-					else { node_ = node_->prev; }
78  
-					return *this;
79  
-				}
80 74
 				bool operator==(const iterator_type& other) const {
81 75
 					return node_ == other.node_;
82 76
 				}
@@ -103,7 +97,7 @@ namespace wiselib {
103 97
 	>
104 98
 	class list_dynamic {
105 99
 		public:
106  
-			typedef list_dynamic_impl::DoublyConnectedListNode<Value_P, Allocator_P> Node_P;
  100
+			typedef list_dynamic_impl::SingleConnectedListNode<Value_P, Allocator_P> Node_P;
107 101
 			
108 102
 			typedef OsModel_P OsModel;
109 103
 			typedef typename OsModel::size_t size_t;
@@ -131,6 +125,10 @@ namespace wiselib {
131 125
 			return to_t_ptr<T>(a)->cmp(*to_t_ptr<T>(b));
132 126
 			//return reinterpret_cast<T*>(a)->cmp(*reinterpret_cast<T*>(b));
133 127
 		}
  128
+		
  129
+			static int obvious_comparator(value_type a, value_type b, void*) {
  130
+				return (a < b) ? -1 : (b > a);
  131
+			}
134 132
 			
135 133
 			list_dynamic() : allocator_(0), first_node_(0), last_node_(0), weak_(false) { };
136 134
 			list_dynamic(Allocator& alloc) : allocator_(&alloc), first_node_(0), last_node_(0), weak_(false) { };
@@ -139,6 +137,14 @@ namespace wiselib {
139 137
 			
140 138
 			
141 139
 			int init(
  140
+					typename Allocator::self_pointer_t alloc
  141
+			) {
  142
+				allocator_ = alloc;
  143
+				compare_ = comparator_t::template from_function<&self_type::obvious_comparator>();
  144
+				return 0;
  145
+			}
  146
+			
  147
+			int init(
142 148
 					typename Allocator::self_pointer_t alloc,
143 149
 					comparator_t compare
144 150
 			) {
@@ -147,6 +153,10 @@ namespace wiselib {
147 153
 				return 0;
148 154
 			}
149 155
 			
  156
+			void set_allocator(typename Allocator::self_pointer_t alloc) {
  157
+				allocator_ = alloc;
  158
+			}
  159
+			
150 160
 			~list_dynamic() {
151 161
 				if(!weak_) {
152 162
 					clear();
@@ -207,41 +217,23 @@ namespace wiselib {
207 217
 			value_type& back() { return last_node_->value; }
208 218
 			iterator back_iterator() { return iterator(*this, last_node_); }
209 219
 			
  220
+			/**
  221
+			 * Insert item v *after* iter.
  222
+			 */
210 223
 			iterator insert(iterator iter, const_reference v) {
211  
-				node_pointer_t n = allocator_-> template allocate<node_type>();
212  
-				n->value = v;
213  
-				
214  
-				iterator before(iter), after(iter);
215  
-				--before;
216  
-				if(before.node()) { before.node()->next = n; }
217  
-				else { first_node_ = n; }
218  
-				
219  
-				if(after.node()) { after.node()->prev = n; }
220  
-				else { last_node_ = n; }
221  
-				
222  
-				n->prev = before.node();
223  
-				n->next = after.node();
224  
-				
225  
-				iterator new_iter(*this, n);
226  
-				return new_iter;
  224
+				node_pointer_t n = insert_n(v, iter.node());
  225
+				return iterator(*this, n);
227 226
 			}
228 227
 			
229  
-			node_pointer_t insert_n(const_reference v) {
230  
-				iterator iter = end();
  228
+			node_pointer_t insert_n(const_reference v, node_ptr_t after = 0) {
  229
+				if(!after) { after = last_node_; }
231 230
 				
232 231
 				node_pointer_t n = allocator_-> template allocate<node_type>();
233 232
 				n->value = v;
234 233
 				
235  
-				iterator before(iter), after(iter);
236  
-				--before;
237  
-				if(before.node()) { before.node()->next = n; }
238  
-				else { first_node_ = n; }
239  
-				
240  
-				if(after.node()) { after.node()->prev = n; }
241  
-				else { last_node_ = n; }
242  
-				
243  
-				n->prev = before.node();
244  
-				n->next = after.node();
  234
+				node_pointer_t prev = after;
  235
+				n->next = prev->next;
  236
+				prev->next = n;
245 237
 				
246 238
 				return n;
247 239
 			}
@@ -267,11 +259,15 @@ namespace wiselib {
267 259
 			void pop_back() { erase(iterator(*this, last_node_)); }
268 260
 			
269 261
 			iterator erase(iterator iter) {
  262
+				node_ptr_t prev = first_node_;
  263
+				while(prev && prev->next != iter.node()) {
  264
+					prev = prev->next;
  265
+				}
  266
+				
270 267
 				if(!iter.node()) { return iter; }
271 268
 				if(iter.node() == first_node_) { first_node_ = iter.node()->next; }
272  
-				if(iter.node() == last_node_) { last_node_ = iter.node()->prev; }
273  
-				if(iter.node()->next) { iter.node()->next->prev = iter.node()->prev; }
274  
-				if(iter.node()->prev) { iter.node()->prev->next = iter.node()->next; }
  269
+				if(iter.node() == last_node_) { last_node_ = prev; }
  270
+				if(prev) { prev->next = iter.node()->next; }
275 271
 				
276 272
 				iterator n(*this, iter.node()->next);
277 273
 				allocator_-> template free<node_type>(iter.node());

No commit comments for this range

Something went wrong with that request. Please try again.