/* all is an Oec_AList of DataObject entries */ oe_id Oed_Dispatcher_reg_group(T _this_, DataObjectList all, oe_time dur, bool consume, user_callback *match_handler, user_callback *timeout_handler, user_callback_arg args) { oe_id sid = 0; assert(all); List_T group = List_list(NULL); for (Iterator iter = DataObjectList_iterator(all, true); Iterator_hasMore(iter);) { DataObject o = Iterator_next(iter); oe_scalar *templ_p = DataObject_toArray(o); item_ *item = _create_reg_item(_this_, templ_p, dur, consume, match_handler, timeout_handler, args); sid = item->sid; group = List_append(group, List_list(item, NULL)); } item_ **groupitems = (item_**) List_toArray(group, NULL); for (int i = 0; i < List_length(group); i++) { groupitems[i]->group = group; _schedule_item(_this_, groupitems[i]); } Mem_free(groupitems, __FILE__, __LINE__); return sid; //you can cancel the whole group by unreg'ing this one sid }
T Set_singleton (Poly_tyEquals equals, Poly_t x) { T set; Mem_NEW(set); set->equals = equals; set->list = List_list (x, 0); return set; }
void store_name(char* fprint_buffer, char* name_buf, T* table, L* name_list) { const char* fprint = Atom_string(fprint_buffer); const char* name = Atom_string(name_buf); char **name_arr = (char**) List_toArray(*name_list, NULL); for(int z = 0; name_arr[z]; z++) { if(name_arr[z] == name) { fprintf(stderr, "Duplicate name detected: Ignoring input\n"); free (name_arr); return; } } free(name_arr); *name_list = List_push(*name_list, (void*) name); L list = (L) Table_get(*table, fprint); if (list == NULL) { list = List_list((char*) name, NULL); } else { list = List_push(list, (void*) name); } Table_put(*table, fprint, list); }
void read_fgroups(FILE* fp, T* table) { int reading_fprint = 1; int hit_ws = 0; int skip_read = 0; char fprint_buf[513]; char name_buf[513]; L name_list = List_list(NULL); int c = 0, i = 0; do { if (!skip_read) c = getc(fp); else skip_read = 0; if (c == EOF) continue; else if (reading_fprint) { if (isspace(c)) { if (i == 0) { fprintf(stderr, "Input is badly formed. Discarding line\n"); while (c != EOF && c != '\n') { c = getc(fp); } continue; } fprint_buf[i] = 0; hit_ws = 1; i = 0; reading_fprint = 0; } else { if(i >= 512) { fprintf(stderr, "Fingerprint exceeds max size, truncating fingerprint\n"); while (c != EOF && !isspace(c)) { c = getc(fp); } skip_read = 1; } else { fprint_buf[i] = (char) c; i++; } } } else { if (isspace(c) && hit_ws) { continue; } if (c == '\n') { name_buf[i] = 0; reading_fprint = 1; hit_ws = 0; if (i == 0) continue; store_name(fprint_buf, name_buf, table, &name_list); i = 0; } else { if(i >= 512) { fprintf(stderr, "Name exceeds max size, truncating name.\n"); while (c != EOF && c != '\n') { c = getc(fp); } skip_read = 1; } else { //Add check hit_ws = 0; name_buf[i] = (char) c; i++; } } } } while (c != EOF); List_free(&name_list); }
T List_add(T list, void *x) { if(list == NULL ) return List_list(x); return List_append( list, List_list(x)); }