[Opensrf-commits] r1310 - in trunk: include/opensrf src/libopensrf src/router

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Apr 11 23:27:50 EDT 2008


Author: miker
Date: 2008-04-11 22:50:12 -0400 (Fri, 11 Apr 2008)
New Revision: 1310

Modified:
   trunk/include/opensrf/osrf_hash.h
   trunk/src/libopensrf/osrf_hash.c
   trunk/src/libopensrf/osrf_json_object.c
   trunk/src/router/osrf_router.c
Log:
Patch from Scott McKellar:

These patches add two new functions to the osrfHash routines, and
apply them in several modules.  THe purpose is to eliminate the
access of an osrfHash's internals by the client code, so that the
internals can be replaced more readily.

Those internals haven't changed yet, but they will.



Modified: trunk/include/opensrf/osrf_hash.h
===================================================================
--- trunk/include/opensrf/osrf_hash.h	2008-04-11 16:28:20 UTC (rev 1309)
+++ trunk/include/opensrf/osrf_hash.h	2008-04-12 02:50:12 UTC (rev 1310)
@@ -27,6 +27,10 @@
   */
 osrfHash* osrfNewHash();
 
+/** Installs a callback function for freeing stored items
+    */
+void osrfHashSetCallback( osrfHash* hash, void (*callback) (char* key, void* item) );
+
 /**
   Sets the given key with the given item
   if "freeItem" is defined and an item already exists at the given location, 

Modified: trunk/src/libopensrf/osrf_hash.c
===================================================================
--- trunk/src/libopensrf/osrf_hash.c	2008-04-11 16:28:20 UTC (rev 1309)
+++ trunk/src/libopensrf/osrf_hash.c	2008-04-12 02:50:12 UTC (rev 1310)
@@ -57,8 +57,13 @@
       num = (__h & (OSRF_HASH_LIST_SIZE-1));\
    } while(0)
 
+/** Installs a callback function for freeing stored items
+    */
+void osrfHashSetCallback( osrfHash* hash, void (*callback) (char* key, void* item) )
+{
+	if( hash ) hash->freeItem = callback;
+}
 
-
 /* returns the index of the item and points l to the sublist the item
  * lives in if the item and points n to the hashnode the item 
  * lives in if the item is found.  Otherwise -1 is returned */

Modified: trunk/src/libopensrf/osrf_json_object.c
===================================================================
--- trunk/src/libopensrf/osrf_json_object.c	2008-04-11 16:28:20 UTC (rev 1309)
+++ trunk/src/libopensrf/osrf_json_object.c	2008-04-12 02:50:12 UTC (rev 1310)
@@ -37,7 +37,7 @@
 	_obj_->type = newtype;\
 	if( newtype == JSON_HASH && _obj_->value.h == NULL ) {	\
 		_obj_->value.h = osrfNewHash();		\
-		_obj_->value.h->freeItem = _jsonFreeHashItem; \
+		osrfHashSetCallback( _obj_->value.h, _jsonFreeHashItem ); \
 } else if( newtype == JSON_ARRAY && _obj_->value.l == NULL ) {	\
 		_obj_->value.l = osrfNewList();		\
 		_obj_->value.l->freeItem = _jsonFreeListItem;\
@@ -242,7 +242,7 @@
 	JSON_INIT_CLEAR(o, JSON_HASH);
 	newo->parent = o;
 	osrfHashSet( o->value.h, newo, key );
-	o->size = o->value.h->size;
+	o->size = osrfHashGetCount(o->value.h);
 	return o->size;
 }
 
@@ -322,7 +322,7 @@
 
 			while( (item = osrfHashIteratorNext(itr)) ) {
 				if(i++ > 0) OSRF_BUFFER_ADD(buf, ",");
-				buffer_fadd(buf, "\"%s\":", itr->current);
+				buffer_fadd(buf, "\"%s\":", osrfHashIteratorKey(itr));
 				add_json_to_buffer( item, buf );
 			}
 
@@ -362,7 +362,7 @@
 		if(!itr->hashItr) return NULL;
 		jsonObject* item = osrfHashIteratorNext(itr->hashItr);
 		free(itr->key);
-		itr->key = strdup(itr->hashItr->current);
+		itr->key = strdup( osrfHashIteratorKey(itr->hashItr) );
 		return item;
 	} else {
 		return jsonObjectGetIndex( itr->obj, itr->index++ );

Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2008-04-11 16:28:20 UTC (rev 1309)
+++ trunk/src/router/osrf_router.c	2008-04-12 02:50:12 UTC (rev 1310)
@@ -76,7 +76,7 @@
 
 	
 	router->classes = osrfNewHash(); 
-	router->classes->freeItem = &osrfRouterClassFree;
+	osrfHashSetCallback(router->classes, &osrfRouterClassFree);
 
 	router->connection = client_init( domain, port, NULL, 0 );
 
@@ -128,7 +128,7 @@
 
 			while( (class = osrfHashIteratorNext(itr)) ) {
 
-				const char* classname = itr->current;
+				const char* classname = osrfHashIteratorKey(itr);
 
 				if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 
@@ -292,7 +292,7 @@
 	osrfRouterClass* class = safe_malloc(sizeof(osrfRouterClass));
 	class->nodes = osrfNewHash();
 	class->itr = osrfNewHashIterator(class->nodes);
-	class->nodes->freeItem = &osrfRouterNodeFree;
+	osrfHashSetCallback(class->nodes, &osrfRouterNodeFree);
 	class->router	= router;
 
 	class->connection = client_init( router->domain, router->port, NULL, 0 );
@@ -574,7 +574,7 @@
 	osrfHashIterator* itr = osrfNewHashIterator(router->classes);
 
 	while( (class = osrfHashIteratorNext(itr)) ) {
-		const char* classname = itr->current;
+		const char* classname = osrfHashIteratorKey(itr);
 
 		if( classname && (class = osrfRouterFindClass( router, classname )) ) {
 			sockid = class->ROUTER_SOCKFD;
@@ -732,7 +732,7 @@
 		while( (class = osrfHashIteratorNext(class_itr)) ) {
 
 			jsonObject* class_res = jsonNewObjectType(JSON_HASH);
-			const char* classname = class_itr->current;
+			const char* classname = osrfHashIteratorKey(class_itr);
 
 			osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
 			while( (node = osrfHashIteratorNext(node_itr)) ) {
@@ -756,7 +756,7 @@
 		while( (class = osrfHashIteratorNext(class_itr)) ) {
 
 			count = 0;
-			const char* classname = class_itr->current;
+			const char* classname = osrfHashIteratorKey(class_itr);
 
 			osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes);
 			while( (node = osrfHashIteratorNext(node_itr)) ) {



More information about the opensrf-commits mailing list