static int player_open(OBJECT *obj) { char32 type="file"; char1024 fname=""; char32 flags="r"; struct player *my = OBJECTDATA(obj,struct player); TAPEFUNCS *tf = 0; /* if prefix is omitted (no colons found) */ // if (sscanf(my->file,"%32[^:]:%1024[^:]:%[^:]",type,fname,flags)==1) // { // /* filename is file by default */ strcpy(fname,my->file); // strcpy(type,"file"); // } /* if no filename given */ if (strcmp(fname,"")==0) /* use object name-id as default file name */ sprintf(fname,"%s-%d.%s",obj->parent->oclass->name,obj->parent->id, my->filetype); /* if type is file or file is stdin */ tf = get_ftable(my->mode); if(tf == NULL) return 0; my->ops = tf->player; if(my->ops == NULL) return 0; /* access the input stream to the player */ if ( (my->ops->open)(my, fname, flags)==1 ) { /* set up the delta_mode recorder if enabled */ if ( (obj->flags)&OF_DELTAMODE ) { extern void delta_add_player(OBJECT *); delta_add_player(obj); } return 1; /* success */ } else return 0; /* failure */ }
static int collector_open(OBJECT *obj) { char32 type="file"; char1024 fname=""; char32 flags="w"; TAPEFUNCS *tf = 0; struct collector *my = OBJECTDATA(obj,struct collector); my->interval = (int64)(my->dInterval/TS_SECOND); /* if prefix is omitted (no colons found) */ if (sscanf(my->file,"%32[^:]:%1024[^:]:%[^:]",type,fname,flags)==1) { /* filename is file by default */ strcpy(fname,my->file); strcpy(type,"file"); } /* if no filename given */ if (strcmp(fname,"")==0) { char *p; /* use group spec as default file name */ sprintf(fname,"%s.%s",my->group,my->filetype); /* but change disallowed characters to _ */ for (p=fname; *p!='\0'; p++) { if (!isalnum(*p) && *p!='-' && *p!='.') *p='_'; } } /* if type is file or file is stdin */ tf = get_ftable(type); if(tf == NULL) return 0; my->ops = tf->collector; if(my->ops == NULL) return 0; set_csv_options(); return my->ops->open(my, fname, flags); }
/** * Object initialization is called once after all object have been created * * @param parent a pointer to this object's parent * @return 1 on success, 0 on error */ int histogram::init(OBJECT *parent) { PROPERTY *prop = NULL; OBJECT *obj = OBJECTHDR(this); char tprop[64], tpart[8]; int e = 0; TAPEFUNCS *tf = 0; tprop[0]=0; tpart[0] = 0; if(parent == NULL) /* better have a group... */ { OBJECT *group_obj = NULL; CLASS *oclass = NULL; if(group[0] == NULL){ gl_error("Histogram has no parent and no group"); return 0; } group_list = gl_find_objects(FL_GROUP,group.get_string()); if(group_list == NULL){ gl_error("Histogram group could not be parsed"); return 0; } if(group_list->hit_count < 1){ gl_error("Histogram group is an empty set"); return 0; } /* non-empty set */ /* parse complex part of property */ test_for_complex(tprop, tpart); while(group_obj = gl_find_next(group_list, group_obj)){ prop = gl_find_property(group_obj->oclass, property.get_string()); if(prop == NULL){ gl_error("Histogram group is unable to find prop '%s' in class '%s' for group '%s'", property.get_string(), group_obj->oclass->name, group.get_string()); return 0; } /* check to see if all the group objects are in the same class, allowing us to cache the target property */ if (oclass == NULL){ oclass = group_obj->oclass; prop_ptr = prop; } if(oclass != group_obj->oclass){ prop_ptr = NULL; } } } else { /* if we have a parent, we only focus on that one object */ test_for_complex(tprop, tpart); prop = gl_find_property(parent->oclass, property.get_string()); if(prop == NULL){ gl_error("Histogram parent '%s' of class '%s' does not contain property '%s'", parent->name ? parent->name : "(anon)", parent->oclass->name, property.get_string()); return 0; } else { prop_ptr = prop; /* saved for later */ } } // initialize first timesteps if(counting_interval > 0.0) next_count = gl_globalclock + counting_interval; if(sampling_interval > 0.0) next_sample = gl_globalclock + sampling_interval; /* * This will create a uniform partition over the specified range */ if((bin_count > 0) && (min < max)) { int i=0; double range = max - min; double step = range/bin_count; //throw("Histogram bin_count is temporarily disabled."); bin_list = (BIN *)gl_malloc(sizeof(BIN) * bin_count); if(bin_list == NULL){ gl_error("Histogram malloc error: unable to alloc %i * %i bytes for %s", bin_count, sizeof(BIN), obj->name ? obj->name : "(anon. histogram)"); return 0; } memset(bin_list, 0, sizeof(BIN) * bin_count); for(i = 0; i < bin_count; i++){ bin_list[i].low_val = min + i * step; bin_list[i].high_val = bin_list[i].low_val + step; bin_list[i].low_inc = 1; bin_list[i].high_inc = 0; } bin_list[i-1].high_inc = 1; /* tail value capture */ binctr = (int *)gl_malloc(sizeof(int) * bin_count); memset(binctr, 0, sizeof(int) * bin_count); } else if (bins[0] != 0) /* * This will parse the bin strings as specified. The valid basic form is "(a..b)". Brackets are optional, [ & ] are inclusive. A dash may replace the '..'. * If a or b is not present, the bin will fill in a positve/negative infinity. */ { char *cptr = bins; char bincpy[1025]; int i = 0; bin_count = 1; /* assume at least one */ /* would be better to count the number of times strtok succeeds, but this should work -mh */ //while(*cptr != 0){ for(cptr = bins; *cptr != 0; ++cptr){ if(*cptr == ',' && cptr[1] != 0){ ++bin_count; } // ++cptr; } bin_list = (BIN *)gl_malloc(sizeof(BIN) * bin_count); if(bin_list == NULL){ gl_error("Histogram malloc error: unable to alloc %i * %i bytes for %s", bin_count, sizeof(BIN), obj->name ? obj->name : "(anon. histogram)"); return 0; } memset(bin_list, 0, sizeof(BIN) * bin_count); memcpy(bincpy, bins, 1024); cptr = strtok(bincpy, ",\t\r\n\0"); if(prop->ptype == PT_complex || prop->ptype == PT_double || prop->ptype == PT_int16 || prop->ptype == PT_int32 || prop->ptype == PT_int64 || prop->ptype == PT_float || prop->ptype == PT_real){ for(i = 0; i < bin_count && cptr != NULL; ++i){ if(parse_bin_val(cptr, bin_list+i) == 0){ gl_error("Histogram unable to parse \'%s\' in %s", cptr, obj->name ? obj->name : "(unnamed histogram)"); return 0; } cptr = strtok(NULL, ",\t\r\n\0"); /* minor efficiency gain to use the incremented pointer from parse_bin */ } } else if (prop->ptype == PT_enumeration || prop->ptype == PT_set){ for(i = 0; i < bin_count && cptr != NULL; ++i){ if(parse_bin_enum(cptr, bin_list+i, prop) == 0){ gl_error("Histogram unable to parse \'%s\' in %s", cptr, obj->name ? obj->name : "(unnamed histogram)"); return 0; } cptr = strtok(NULL, ",\t\r\n\0"); /* minor efficiency gain to use the incremented pointer from parse_bin */ } } if(i < bin_count){ gl_error("Histrogram encountered a problem parsing bins for %s", obj->name ? obj->name : "(unnamed histogram)"); return 0; } binctr = (int *)malloc(sizeof(int) * bin_count); memset(binctr, 0, sizeof(int) * bin_count); } else { gl_error("Histogram has neither bins or a bin range to work with"); return 0; } /* open file ~ copied from recorder.c */ /* if prefix is omitted (no colons found) */ // if (sscanf(filename,"%32[^:]:%1024[^:]:%[^:]",ftype,fname,flags)==1) // { /* filename is file by default */ strcpy(fname,filename); // strcpy(ftype,"file"); // } /* if no filename given */ if (strcmp(fname,"")==0) /* use object name-id as default file name */ sprintf(fname,"%s-%d.%s",obj->parent->oclass->name,obj->parent->id, ftype.get_string()); /* if type is file or file is stdin */ tf = get_ftable(mode); if(tf == NULL) return 0; ops = tf->histogram; /* same mentality as a recorder, 'cept for the header properties */ if(ops == NULL) return 0; return ops->open(this, fname, flags); }