changeset 1128:7c5449ddc434

New macro HOOK_MASK to ease call of the fd_hook_register function
author Sebastien Decugis <sdecugis@freediameter.net>
date Wed, 15 May 2013 11:18:30 +0800
parents 1af09cc156d6
children f916f4fc3d99
files extensions/dbg_msg_dumps/dbg_msg_dumps.c extensions/dbg_msg_timings/dbg_msg_timings.c include/freeDiameter/libfdcore.h libfdcore/hooks.c
diffstat 4 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Wed May 15 10:39:25 2013 +0800
+++ b/extensions/dbg_msg_dumps/dbg_msg_dumps.c	Wed May 15 11:18:30 2013 +0800
@@ -63,7 +63,7 @@
 {
 	TRACE_ENTRY("%p", conffile);
 	
-	CHECK_FCT( fd_hook_register( ((1 << HOOK_MESSAGE_RECEIVED) | (1 << HOOK_MESSAGE_SENT)), 
+	CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ), 
 					md_hook_cb, NULL, NULL, &md_hdl) );
 	
 	return 0;
--- a/extensions/dbg_msg_timings/dbg_msg_timings.c	Wed May 15 10:39:25 2013 +0800
+++ b/extensions/dbg_msg_timings/dbg_msg_timings.c	Wed May 15 11:18:30 2013 +0800
@@ -116,7 +116,7 @@
 	
 	CHECK_FCT( fd_hook_data_register( sizeof(struct fd_hook_permsgdata), NULL, NULL, &mt_data_hdl ) );
 	
-	CHECK_FCT( fd_hook_register( ((1 << HOOK_MESSAGE_RECEIVED) | (1 << HOOK_MESSAGE_SENT) | (1 << HOOK_DATA_RECEIVED)), 
+	CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT, HOOK_DATA_RECEIVED ), 
 					mt_hook_cb, NULL, mt_data_hdl, &mt_hdl) );
 	
 	return 0;
--- a/include/freeDiameter/libfdcore.h	Wed May 15 10:39:25 2013 +0800
+++ b/include/freeDiameter/libfdcore.h	Wed May 15 11:18:30 2013 +0800
@@ -1076,11 +1076,14 @@
 /* A handler associated with a registered hook callback (for cleanup) */
 struct fd_hook_hdl; 
 
+/* Helper for building a mask of hooks for registration */
+#define HOOK_MASK(hooklist...)	fd_hook_mask_helper(0, ## hooklist, -1)
+
 /*
  * FUNCTION:	fd_hook_register
  *
  * PARAMETERS:
- *  type_mask	  : A bitmask of fd_hook_type bits for which this cb is registered, e.g. ((1 << HOOK_MESSAGE_RECEIVED) | (1 << HOOK_MESSAGE_SENT))
+ *  type_mask	  : A bitmask of fd_hook_type bits for which this cb is registered, e.g. HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT )
  *  fd_hook_cb	  : The callback function to register (see prototype above).
  *  regdata	  : Pointer to pass to the callback when it is called. The data is opaque to the daemon.
  *  data_hdl      : If permsgdata is requested for the hooks, a handler registered with fd_hook_data_register. NULL otherwise.
@@ -1109,6 +1112,8 @@
 /* Use the following function to retrieve any pmd structure associated with a request matching the current answer. Returns NULL in case of error / no such structure */
 struct fd_hook_permsgdata * fd_hook_get_request_pmd(struct fd_hook_data_hdl *data_hdl, struct msg * answer);
 
+/* The following is used by HOOK_MASK macro */
+uint32_t fd_hook_mask_helper(int dummy, ...);
 
 /*============================================================*/
 
--- a/libfdcore/hooks.c	Wed May 15 10:39:25 2013 +0800
+++ b/libfdcore/hooks.c	Wed May 15 11:18:30 2013 +0800
@@ -262,6 +262,24 @@
 	return ret;
 }
 
+/* Create a mask */
+uint32_t fd_hook_mask_helper(int dummy, ...)
+{
+	va_list ap;
+	uint32_t ret = 0;
+	int next;
+	
+	va_start(ap, dummy);
+	while ((next = va_arg(ap, int)) >= 0) {
+		if (next > HOOK_PEER_LAST)
+			break; /* invalid parameter */
+		ret |= (1<<next);
+	}
+	va_end(ap);
+
+	return ret;
+}
+
 /* The function that does the work of calling the extension's callbacks and also managing the permessagedata structures */
 void   fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * peer, void * other, struct fd_msg_pmdl * pmdl)
 {
"Welcome to our mercurial repository"