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
_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;\
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;
}
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 );
}
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++ );
router->classes = osrfNewHash();
- router->classes->freeItem = &osrfRouterClassFree;
+ osrfHashSetCallback(router->classes, &osrfRouterClassFree);
router->connection = client_init( domain, port, NULL, 0 );
while( (class = osrfHashIteratorNext(itr)) ) {
- const char* classname = itr->current;
+ const char* classname = osrfHashIteratorKey(itr);
if( classname && (class = osrfRouterFindClass( router, classname )) ) {
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 );
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;
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)) ) {
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)) ) {