Skip to contentSkip to conversation

cld: replace "if (verbose) { act_log }" with CLD_DEBUG

RFC Superseded Colin McCabe 2 participants 2 messages Dec 6, 2009 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 cld: replace "if (verbose) { act_log }" with CLD_DEBUG

Move prototypes for common.c functions out of cld_msg.h and into a new header file, common.h. Create a structure that represents the current log level and the function to use for logging.

Create CLD_DEBUG and CLD_LOG macros to print debugging and informational log messages, respectively. CLD_DEBUG will not evaluate its parameters unless log->verbose is true. This patch converts over the client code to use these macros.

Rationale:
1. Some functions in common.c can be called from the server _and_ the client code. If these functions want to print a debug message, they would currently need two extra parameters-- the logging function, and the verbose flag. It's cleaner to condense this into one parameter.

2. The if (verbose) sess->act_log pattern leads to an excessive level of indentation, which tends to make things more unclear.

What do you think?

---
 include/cld_msg.h |   10 -----
 include/cldc.h    |    5 +--
 lib/cldc.c        |   98 +++++++++++++++++++++-------------------------------
 tools/cldcli.c    |    2 +-
 4 files changed, 43 insertions(+), 72 deletions(-)
include/cld_msg.h +0 -10
index 641b857..01837b7 100644
@@ -250,14 +250,4 @@ struct cld_msg_event {
 	uint8_t			res[4];
 };
 
-/*
- * function prototypes for lib/common.c;
- * ideally these should not be in cld_msg.h
- */
-
-extern unsigned long long cld_sid2llu(const uint8_t *sid);
-extern void __cld_rand64(void *p);
-extern const char *cld_errstr(enum cle_err_codes ecode);
-extern int cld_readport(const char *fname);
-
 #endif /* __CLD_MSG_H__ */
include/cldc.h +2 -3
index 9ae6dfe..70062cf 100644
@@ -5,6 +5,7 @@
 #include <stdbool.h>
 #include <glib.h>
 #include <cld_msg.h>
+#include <common.h>
 
 struct cldc_session;
 
@@ -84,10 +85,8 @@ struct cldc_ops {
 struct cldc_session {
 	uint8_t		sid[CLD_SID_SZ];	/* client id */
 
-	bool		verbose;
-
 	const struct cldc_ops *ops;
-	void		(*act_log)(int prio, const char *fmt, ...);
+	struct		cld_log log;
 	void		*private;
 
 	uint8_t		addr[64];		/* server address */
lib/cldc.c +40 -58

237 lines not on this page · raw message

tools/cldcli.c +1 -1
index 60ab301..23cba99 100644
@@ -823,7 +823,7 @@ static gpointer cld_thread(gpointer dummy)
 		return NULL;
 	}
 
-	thr_udp->sess->verbose = cldcli_verbose;
+	thr_udp->sess->log.verbose = cldcli_verbose;
 
 	pfd[0].fd = thr_udp->fd;
 	pfd[0].events = POLLIN;
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 3 lines · Colin McCabe

Move prototypes for common.c functions out of cld_msg.h and into a new header file, common.h. Create a structure that represents the current log level and the function to use for logging.

Patch lacks common.h...