gint message_handler_add_v2 (const char *name, message_matcher_f m, message_handler_v2_f h, const GPtrArray* tags, GError **err) { struct message_handler_s *mh; if (!name || !m || !h) { GSETERROR(err,"Invalid parameters"); return 0; } mh = g_malloc0 (sizeof(struct message_handler_s)); mh->matcher = m; mh->handler = NULL; strncpy (mh->name, name, SIZE_MSGHANDLERNAME-1); mh->next = BEACON_MSGHANDLER.next; mh->handler_v2 = h; BEACON_MSGHANDLER.next = mh; if(!serv_tags) serv_tags = g_ptr_array_new(); /* if the handlers have stats for our service info, load it */ if (tags) { gsize i; for (i=0; i<tags->len; i++) { struct service_tag_s* tag = g_ptr_array_index(tags, i); g_ptr_array_add(serv_tags, service_tag_dup(tag)); } } DEBUG ("new message handler added : %s", name); return 1; }
GPtrArray * service_info_copy_tags(GPtrArray * original) { int i, max; GPtrArray *copied; if (!original) return NULL; copied = g_ptr_array_new(); for (i = 0, max = original->len; i < max; i++) { struct service_tag_s *tag, *tag_dup; tag = g_ptr_array_index(original, i); if (tag) { tag_dup = service_tag_dup(tag); g_ptr_array_add(copied, tag_dup); } } return copied; }