[Opensrf-commits] r1618 - trunk/include/opensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Jan 12 15:17:43 EST 2009


Author: scottmk
Date: 2009-01-12 15:17:39 -0500 (Mon, 12 Jan 2009)
New Revision: 1618

Modified:
   trunk/include/opensrf/osrf_application.h
Log:
Reformed the macros OSRF_METHOD_VERIFY_CONTEXT and _OSRF_METHOD_VERIFY_CONTEXT.

1. Renamed _OSRF_METHOD_VERIFY_CONTEXT to OSRF_METHOD_VERIFY_CONTEXT_
and the variable __j to _j, to avoid using reserved identifiers.

2. Applied the do/while(0) trick to accommodate multiple statements.

3. Avoid evaluating the macro arguments more than once.

4. Rearranged the white space for readability.

This update is a Band-aid.  These macros should turn into a proper function.


Modified: trunk/include/opensrf/osrf_application.h
===================================================================
--- trunk/include/opensrf/osrf_application.h	2009-01-12 05:35:10 UTC (rev 1617)
+++ trunk/include/opensrf/osrf_application.h	2009-01-12 20:17:39 UTC (rev 1618)
@@ -29,28 +29,50 @@
 
 /** 
   This macro verifies methods receive the correct parameters */
-#define _OSRF_METHOD_VERIFY_CONTEXT(d) \
-	if(!d) return -1; \
-	if(!d->session) { osrfLogError( OSRF_LOG_MARK,  "Session is NULL in app reqeust" ); return -1; }\
-	if(!d->method) { osrfLogError( OSRF_LOG_MARK,  "Method is NULL in app reqeust" ); return -1; }\
-	if(d->method->argc) {\
-		if(!d->params) { osrfLogError( OSRF_LOG_MARK,  "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
-		if( d->params->type != JSON_ARRAY ) { \
-			osrfLogError( OSRF_LOG_MARK,  "'params' is not a JSON array for method %s", d->method->name);\
-			return -1; }\
-	}\
-	if( !d->method->name ) { osrfLogError( OSRF_LOG_MARK,  "Method name is NULL"); return -1; } 
+#define OSRF_METHOD_VERIFY_CONTEXT_(x) \
+	do { \
+		osrfMethodContext* d = x; \
+		if(!d) return -1; \
+		if(!d->session) { \
+			osrfLogError( OSRF_LOG_MARK, "Session is NULL in app reqeust" ); \
+			return -1; \
+		} \
+		if(!d->method) { \
+			osrfLogError( OSRF_LOG_MARK,  "Method is NULL in app reqeust" ); \
+			return -1; \
+		}\
+		if(d->method->argc) { \
+			if(!d->params) { \
+				osrfLogError( OSRF_LOG_MARK, \
+					"Params is NULL in app reqeust %s", d->method->name ); \
+				return -1; \
+			} \
+			if( d->params->type != JSON_ARRAY ) { \
+				osrfLogError( OSRF_LOG_MARK, \
+					"'params' is not a JSON array for method %s", d->method->name);\
+				return -1; }\
+		}\
+		if( !d->method->name ) { \
+			osrfLogError( OSRF_LOG_MARK, "Method name is NULL"); \
+			return -1; \
+		} \
+	} while(0)
 
-#ifdef OSRF_LOG_PARAMS 
-#define OSRF_METHOD_VERIFY_CONTEXT(d) \
-	_OSRF_METHOD_VERIFY_CONTEXT(d); \
-	char* __j = jsonObjectToJSON(d->params);\
-	if(__j) { \
-		osrfLogInfo( OSRF_LOG_MARK,  "CALL:	%s %s - %s", d->session->remote_service, d->method->name, __j);\
-		free(__j); \
-	} 
+#ifdef OSRF_LOG_PARAMS
+#define OSRF_METHOD_VERIFY_CONTEXT(x) \
+ 	do { \
+ 		osrfMethodContext* d = x; \
+		OSRF_METHOD_VERIFY_CONTEXT_(d); \
+		char* _j = jsonObjectToJSON(d->params); \
+		if(_j) { \
+			osrfLogInfo( OSRF_LOG_MARK, \
+				"CALL:	%s %s - %s", d->session->remote_service, d->method->name, _j); \
+			free(_j); \
+		} \
+	} \
+	while( 0 )
 #else
-#define OSRF_METHOD_VERIFY_CONTEXT(d) _OSRF_METHOD_VERIFY_CONTEXT(d); 
+#define OSRF_METHOD_VERIFY_CONTEXT(d) OSRF_METHOD_VERIFY_CONTEXT_(d);
 #endif
 
 



More information about the opensrf-commits mailing list