changeset 248:640178656bfc

Added a dump function for peers (TBC)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 04 Dec 2008 12:11:56 +0900
parents adbc3782ba69
children d3e799cbb0e4
files waaad/peer-struct.c waaad/peer.h waaad/queues.c waaad/queues.h
diffstat 4 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/peer-struct.c	Thu Dec 04 11:37:16 2008 +0900
+++ b/waaad/peer-struct.c	Thu Dec 04 12:11:56 2008 +0900
@@ -569,3 +569,53 @@
 	
 	return 0;
 }
+
+
+/*************************************************************/
+/* A dump function for the peer */
+void peer_dump(peer_t * peer, int debug_level, int what /* 0: 1-line dump; 1: compact; 2: detailed; 3: develop everything */)
+{
+	_peer_t * p = _P(peer);
+	
+	if (!VALIDATE_PEER( p )) {
+		TRACE_DEBUG(debug_level, "peer @%p: INVALID! (%s)", p,
+				(p == NULL) ? "null" : 
+					((p->p_eyec != PEER_EYEC) ? "eyec" :
+						"deleted"));
+		return;
+	}
+	
+	switch (what) {
+		case 0:
+			TRACE_DEBUG(debug_level, "peer @%p: %s (%s)", p, p->p_diamid ?  p->p_diamid : "(nil)", STATESTR( p->p_state ));
+			break;
+		
+		case 1:
+		default: /* to be completed */
+			TRACE_DEBUG(debug_level, "peer @%p: id:%s st:%s h:%u rlm:%s hbh:%u", 
+					p, 
+					p->p_diamid ?  p->p_diamid : "(nil)",
+					STATESTR( p->p_state ), 
+					p->p_hash,
+					p->p_realm ?  p->p_realm : "(nil)",
+					p->p_hbh);
+			TRACE_DEBUG(debug_level, "  fl:%08x gl:%p ac:%s psm:%p ts:%u ev:%s",
+					p->p_flags,
+					IS_LIST_EMPTY(&p->p_global) ? NULL : p->p_global.head,
+					IS_LIST_EMPTY(&p->p_active) ? "n" : ((p->p_active.head == &_peers_actives) ? "y" : "E"),
+					p->p_psm,
+					p->p_ts,
+					IS_LIST_EMPTY(&p->p_events) ? "n" : "y");
+			TRACE_DEBUG(debug_level, "  inq:%p(%d) th:%p outq:%p(%d) th:%p snt:%s",
+					p->p_in_q, meq_length_noerr(p->p_in_q),
+					p->p_in_th,
+					p->p_out_q, meq_length_noerr(p->p_out_q),
+					p->p_out_th,
+					IS_LIST_EMPTY(&p->p_sent) ? "n" : "y");
+			/* To be completed ... */
+	}
+}
+					
+					
+					
+					
--- a/waaad/peer.h	Thu Dec 04 11:37:16 2008 +0900
+++ b/waaad/peer.h	Thu Dec 04 12:11:56 2008 +0900
@@ -168,5 +168,8 @@
 int peer_struct_list_open( application_id_t app, rt_dpl_t ** list, uti_list_t * rejects );
 
 
+/* Helper function for debug */
+void peer_dump(peer_t * peer, int debug_level, int what);
+
 #endif /* ! _PEER_H */
 
--- a/waaad/queues.c	Thu Dec 04 11:37:16 2008 +0900
+++ b/waaad/queues.c	Thu Dec 04 12:11:56 2008 +0900
@@ -187,6 +187,12 @@
 	/* Done */
 	return 0;
 }
+int meq_length_noerr ( meq_t * queue )
+{
+	if ( !CHECK_QUEUE( queue ) )
+		return 0;
+	return _Q(queue)->count;
+}
 
 /* Enqueue a message */
 int meq_post ( meq_t * queue, msg_t * msg )
--- a/waaad/queues.h	Thu Dec 04 11:37:16 2008 +0900
+++ b/waaad/queues.h	Thu Dec 04 12:11:56 2008 +0900
@@ -131,6 +131,7 @@
  *  EINVAL 	: A parameter is invalid.
  */
 int meq_length ( meq_t * queue, int * length );
+int meq_length_noerr ( meq_t * queue );
 
 /*
  * FUNCTION:	meq_post
"Welcome to our mercurial repository"