static void wmem_test_map(void) { wmem_allocator_t *allocator; wmem_map_t *map; gchar *str_key; unsigned int i; void *ret; allocator = wmem_allocator_new(WMEM_ALLOCATOR_STRICT); /* insertion, lookup and removal of simple integer keys */ map = wmem_map_new(allocator, g_direct_hash, g_direct_equal); g_assert(map); for (i=0; i<CONTAINER_ITERS; i++) { ret = wmem_map_insert(map, GINT_TO_POINTER(i), GINT_TO_POINTER(777777)); g_assert(ret == NULL); ret = wmem_map_insert(map, GINT_TO_POINTER(i), GINT_TO_POINTER(i)); g_assert(ret == GINT_TO_POINTER(777777)); ret = wmem_map_insert(map, GINT_TO_POINTER(i), GINT_TO_POINTER(i)); g_assert(ret == GINT_TO_POINTER(i)); } for (i=0; i<CONTAINER_ITERS; i++) { ret = wmem_map_lookup(map, GINT_TO_POINTER(i)); g_assert(ret == GINT_TO_POINTER(i)); ret = wmem_map_remove(map, GINT_TO_POINTER(i)); g_assert(ret == GINT_TO_POINTER(i)); ret = wmem_map_lookup(map, GINT_TO_POINTER(i)); g_assert(ret == NULL); ret = wmem_map_remove(map, GINT_TO_POINTER(i)); g_assert(ret == NULL); } wmem_free_all(allocator); map = wmem_map_new(allocator, wmem_str_hash, g_str_equal); g_assert(map); /* string keys and for-each */ for (i=0; i<CONTAINER_ITERS; i++) { str_key = wmem_test_rand_string(allocator, 1, 64); wmem_map_insert(map, str_key, GINT_TO_POINTER(i)); ret = wmem_map_lookup(map, str_key); g_assert(ret == GINT_TO_POINTER(i)); } wmem_destroy_allocator(allocator); }
static ros_call_response_t * ros_match_call_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint invokeId, gboolean isInvoke) { ros_call_response_t rcr, *rcrp=NULL; ros_conv_info_t *ros_info; conversation_t *conversation; /* first see if we have already matched this */ conversation = find_conversation_pinfo(pinfo, 0); if (conversation == NULL) return NULL; ros_info = (ros_conv_info_t *)conversation_get_proto_data(conversation, proto_ros); if (ros_info == NULL) return NULL; rcr.invokeId=invokeId; rcr.is_request = isInvoke; if(isInvoke) { rcr.req_frame=pinfo->num; rcr.rep_frame=0; } else { rcr.req_frame=0; rcr.rep_frame=pinfo->num; } rcrp=(ros_call_response_t *)wmem_map_lookup(ros_info->matched, &rcr); if(rcrp) { /* we have found a match */ rcrp->is_request=rcr.is_request; } else { /* we haven't found a match - try and match it up */ if(isInvoke) { /* this a a request - add it to the unmatched list */ /* check that we don't already have one of those in the unmatched list and if so remove it */ rcr.invokeId=invokeId; rcrp=(ros_call_response_t *)wmem_map_lookup(ros_info->unmatched, &rcr); if(rcrp){ wmem_map_remove(ros_info->unmatched, rcrp); } /* if we can't reuse the old one, grab a new chunk */ if(!rcrp){ rcrp=wmem_new(wmem_file_scope(), ros_call_response_t); } rcrp->invokeId=invokeId; rcrp->req_frame=pinfo->num; rcrp->req_time=pinfo->abs_ts; rcrp->rep_frame=0; rcrp->is_request=TRUE; wmem_map_insert(ros_info->unmatched, rcrp, rcrp); return NULL; } else { /* this is a result - it should be in our unmatched list */ rcr.invokeId=invokeId; rcrp=(ros_call_response_t *)wmem_map_lookup(ros_info->unmatched, &rcr); if(rcrp){ if(!rcrp->rep_frame){ wmem_map_remove(ros_info->unmatched, rcrp); rcrp->rep_frame=pinfo->num; rcrp->is_request=FALSE; wmem_map_insert(ros_info->matched, rcrp, rcrp); } } } } if(rcrp){ /* we have found a match */ proto_item *item = NULL; if(rcrp->is_request){ item=proto_tree_add_uint(tree, hf_ros_response_in, tvb, 0, 0, rcrp->rep_frame); PROTO_ITEM_SET_GENERATED (item); } else { nstime_t ns; item=proto_tree_add_uint(tree, hf_ros_response_to, tvb, 0, 0, rcrp->req_frame); PROTO_ITEM_SET_GENERATED (item); nstime_delta(&ns, &pinfo->abs_ts, &rcrp->req_time); item=proto_tree_add_time(tree, hf_ros_time, tvb, 0, 0, &ns); PROTO_ITEM_SET_GENERATED (item); } } return rcrp; }