void ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) { int size; /* xsize must be a multiple of 4 */ xsize = xsize & ~3; zb->xsize = xsize; zb->ysize = ysize; zb->linesize = (xsize * PSZB + 3) & ~3; size = zb->xsize * zb->ysize * sizeof(unsigned short); gl_free(zb->zbuf); zb->zbuf = gl_malloc(size); if (zb->frame_buffer_allocated) gl_free(zb->pbuf); if (frame_buffer == NULL) { zb->pbuf = gl_malloc(zb->ysize * zb->linesize); zb->frame_buffer_allocated = 1; } else { zb->pbuf = frame_buffer; zb->frame_buffer_allocated = 0; } }
void ZB_resize(ZBuffer *zb, void *frame_buffer, int xsize, int ysize) { int size; // xsize must be a multiple of 4 xsize = xsize & ~3; zb->xsize = xsize; zb->ysize = ysize; zb->linesize = (xsize * PSZB + 3) & ~3; size = zb->xsize * zb->ysize * sizeof(unsigned short); gl_free(zb->zbuf); zb->zbuf = (unsigned short *)gl_malloc(size); size = zb->xsize * zb->ysize * sizeof(unsigned int); gl_free(zb->zbuf2); zb->zbuf2 = (unsigned int *)gl_malloc(size); if (zb->frame_buffer_allocated) gl_free(zb->pbuf); if (!frame_buffer) { zb->pbuf = (PIXEL *)gl_malloc(zb->ysize * zb->linesize); zb->frame_buffer_allocated = 1; } else { zb->pbuf = (PIXEL *)frame_buffer; zb->frame_buffer_allocated = 0; } }
void ZB_close(ZBuffer *zb) { if (zb->frame_buffer_allocated) zb->pbuf.free(); gl_free(zb->zbuf); gl_free(zb); }
void glClose() { GLContext *c = gl_get_context(); specbuf_cleanup(c); for (int i = 0; i < 3; i++) gl_free(c->matrix_stack[i]); endSharedState(c); gl_free(c->vertex); gl_free(c); }
void endSharedState(GLContext *c) { GLSharedState *s = &c->shared_state; free_texture(c, 0); for (int i = 0; i < MAX_DISPLAY_LISTS; i++) { // TODO } gl_free(s->lists); gl_free(s->texture_hash_table); }
void endSharedState(GLContext *c) { GLSharedState *s=&c->shared_state; int i; for(i=0;i<MAX_DISPLAY_LISTS;i++) { /* TODO */ } gl_free(s->lists); gl_free(s->texture_hash_table); }
void ZB_close(ZBuffer * zb) { #ifdef TGL_FEATURE_8_BITS if (zb->mode == ZB_MODE_INDEX) ZB_closeDither(zb); #endif if (zb->frame_buffer_allocated) gl_free(zb->pbuf); gl_free(zb->zbuf); gl_free(zb); }
void glClose() { GLContext *c = gl_get_context(); tglDisposeDrawCallLists(c); tglDisposeResources(c); specbuf_cleanup(c); for (int i = 0; i < 3; i++) gl_free(c->matrix_stack[i]); endSharedState(c); gl_free(c->vertex); delete c; }
void ostgl_delete_context(ostgl_context *context) { int i; for (i = 0; i < context->numbuffers; i++) { ZB_close(context->zbs[i]); } gl_free(context->zbs); gl_free(context->framebuffers); gl_free(context); if (--buffercnt == 0) { glClose(); } }
void ZB_resize(ZBuffer *zb, void *frame_buffer, int xsize, int ysize) { int size; // xsize must be a multiple of 4 xsize = xsize & ~3; zb->xsize = xsize; zb->ysize = ysize; zb->linesize = (xsize * zb->pixelbytes + 3) & ~3; size = zb->xsize * zb->ysize * sizeof(unsigned int); gl_free(zb->zbuf); zb->zbuf = (unsigned int *)gl_malloc(size); if (zb->frame_buffer_allocated) zb->pbuf.free(); if (!frame_buffer) { byte *pbuf = (byte *)gl_malloc(zb->ysize * zb->linesize); zb->pbuf.set(zb->cmode, pbuf); zb->frame_buffer_allocated = 1; } else { zb->pbuf = (byte *)frame_buffer; zb->frame_buffer_allocated = 0; } }
static void gl_init(HDC hdc) { HWND window = WindowFromDC(hdc); bool success = false; RECT rc = {0}; GetClientRect(window, &rc); data.base_cx = rc.right; data.base_cy = rc.bottom; data.hdc = hdc; data.format = DXGI_FORMAT_B8G8R8A8_UNORM; data.using_scale = global_hook_info->use_scale; data.using_shtex = nv_capture_available && !global_hook_info->force_shmem; if (data.using_scale) { data.cx = global_hook_info->cx; data.cy = global_hook_info->cy; } else { data.cx = data.base_cx; data.cy = data.base_cy; } if (data.using_shtex) success = gl_shtex_init(window); else success = gl_shmem_init(window); if (!success) gl_free(); }
static void gl_capture(HDC hdc) { static bool functions_initialized = false; static bool critical_failure = false; if (critical_failure) { return; } if (!functions_initialized) { functions_initialized = init_gl_functions(); if (!functions_initialized) { critical_failure = true; return; } } /* reset error flag */ glGetError(); if (capture_should_stop()) { gl_free(); } if (capture_should_init()) { if (gl_init(hdc) == INIT_SHTEX_FAILED) { data.shmem_fallback = true; gl_init(hdc); } } if (capture_ready() && hdc == data.hdc) { uint32_t new_cx; uint32_t new_cy; /* reset capture if resized */ get_window_size(hdc, &new_cx, &new_cy); if (new_cx != data.base_cx || new_cy != data.base_cy) { if (new_cx != 0 && new_cy != 0) gl_free(); return; } if (data.using_shtex) gl_shtex_capture(); else gl_shmem_capture(); } }
void glXDestroyContext( NGLXContext ctx1 ) { TinyNGLXContext *ctx = (TinyNGLXContext *) ctx1; if (ctx->gl_context != NULL) { glClose(); } gl_free(ctx); }
static void delete_list(GLContext *c, int list) { GLParamBuffer *pb, *pb1; GLList *l; l = find_list(c, list); assert(l); // free param buffer pb = l->first_op_buffer; while (pb) { pb1 = pb->next; gl_free(pb); pb = pb1; } gl_free(l); c->shared_state.lists[list] = NULL; }
void specbuf_cleanup(GLContext *c) { GLSpecBuf *buf, *next; buf = c->specbuf_first; for (int i = 0; i < c->specbuf_num_buffers; ++i) { next = buf->next; gl_free(buf); buf = next; } }
void glopTexImage2D(GLContext *c, GLParam *p) { int target = p[1].i; int level = p[2].i; int components = p[3].i; int width = p[4].i; int height = p[5].i; int border = p[6].i; int format = p[7].i; int type = p[8].i; void *pixels = p[9].p; GLImage *im; unsigned char *pixels1; int do_free; if (!(target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == TGL_RGBA && type == TGL_UNSIGNED_BYTE)) { error("glTexImage2D: combination of parameters not handled"); } do_free = 0; if (width != 256 || height != 256) { pixels1 = (unsigned char *)gl_malloc(256 * 256 * 4); // no interpolation is done here to respect the original image aliasing ! //gl_resizeImageNoInterpolate(pixels1, 256, 256, (unsigned char *)pixels, width, height); // used interpolation anyway, it look much better :) --- aquadran gl_resizeImage(pixels1, 256, 256, (unsigned char *)pixels, width, height); do_free = 1; width = 256; height = 256; } else { pixels1 = (unsigned char *)pixels; } im = &c->current_texture->images[level]; im->xsize = width; im->ysize = height; if (im->pixmap) gl_free(im->pixmap); im->pixmap = gl_malloc(width * height * 3); if (im->pixmap) gl_convertRGB_to_5R6G5B8A((unsigned short *)im->pixmap, pixels1, width, height); if (do_free) gl_free(pixels1); }
int delete_slist(SCHED_LIST *l){ int rv = 0; if(l == NULL){ return -1; /* error */ } if(l->next != NULL){ rv = delete_slist(l->next); /* shouldn't be non-negative but check anyway */ } gl_free(l); return rv; }
static void free_texture(GLContext *c, int h) { GLTexture *t, **ht; GLImage *im; int i; t = find_texture(c, h); if (!t->prev) { ht = &c->shared_state.texture_hash_table[t->handle % TEXTURE_HASH_TABLE_SIZE]; *ht = t->next; } else { t->prev->next = t->next; } if (t->next) t->next->prev = t->prev; for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { im = &t->images[i]; if (im->pixmap) gl_free(im->pixmap); } gl_free(t); }
static BOOL WINAPI hook_wgl_delete_context(HGLRC hrc) { BOOL ret; if (capture_active()) { HDC last_hdc = jimglGetCurrentDC(); HGLRC last_hrc = jimglGetCurrentContext(); jimglMakeCurrent(data.hdc, hrc); gl_free(); jimglMakeCurrent(last_hdc, last_hrc); } unhook(&wgl_delete_context); BOOL (WINAPI *call)(HGLRC) = wgl_delete_context.call_addr; ret = call(hrc); rehook(&wgl_delete_context); return ret; }
static int gl_init(HDC hdc) { HWND window = WindowFromDC(hdc); int ret = INIT_FAILED; bool success = false; RECT rc = {0}; GetClientRect(window, &rc); data.base_cx = rc.right; data.base_cy = rc.bottom; data.hdc = hdc; data.format = DXGI_FORMAT_B8G8R8A8_UNORM; data.using_scale = global_hook_info->use_scale; data.using_shtex = nv_capture_available && !global_hook_info->force_shmem && !data.shmem_fallback; if (data.using_scale) { data.cx = global_hook_info->cx; data.cy = global_hook_info->cy; } else { data.cx = data.base_cx; data.cy = data.base_cy; } if (data.using_shtex) { success = gl_shtex_init(window); if (!success) ret = INIT_SHTEX_FAILED; } else { success = gl_shmem_init(window); } if (!success) gl_free(); else ret = INIT_SUCCESS; return ret; }
FrameBuffer::~FrameBuffer() { if (frame_buffer_allocated) pbuf.free(); gl_free(zbuf); }
void ZB_delOffscreenBuffer(ZBuffer *zb, Buffer *buf) { gl_free(buf->pbuf); gl_free(buf->zbuf); gl_free(buf); }
void ZB_closeDither(ZBuffer *zb) { gl_free(zb->ctable); gl_free(zb->dctable); }
ZBuffer *ZB_open(int xsize, int ysize, int mode, int nb_colors, unsigned char *color_indexes, int *color_table, void *frame_buffer) { ZBuffer *zb; int size; zb = gl_malloc(sizeof(ZBuffer)); if (zb == NULL) return NULL; zb->xsize = xsize; zb->ysize = ysize; zb->mode = mode; zb->linesize = (xsize * PSZB + 3) & ~3; switch (mode) { #ifdef TGL_FEATURE_8_BITS case ZB_MODE_INDEX: ZB_initDither(zb, nb_colors, color_indexes, color_table); break; #endif #ifdef TGL_FEATURE_32_BITS case ZB_MODE_RGBA: #endif #ifdef TGL_FEATURE_24_BITS case ZB_MODE_RGB24: #endif case ZB_MODE_5R6G5B: zb->nb_colors = 0; break; default: goto error; } size = zb->xsize * zb->ysize * sizeof(unsigned short); zb->zbuf = gl_malloc(size); if (zb->zbuf == NULL) goto error; if (frame_buffer == NULL) { zb->pbuf = gl_malloc(zb->ysize * zb->linesize); if (zb->pbuf == NULL) { gl_free(zb->zbuf); goto error; } zb->frame_buffer_allocated = 1; } else { zb->frame_buffer_allocated = 0; zb->pbuf = frame_buffer; } zb->current_texture = NULL; return zb; error: gl_free(zb); return NULL; }
void glopTexImage2D(GLContext *c, GLParam *p) { int target = p[1].i; int level = p[2].i; int components = p[3].i; int width = p[4].i; int height = p[5].i; int border = p[6].i; int format = p[7].i; int type = p[8].i; void *pixels = p[9].p; GLImage *im; byte *pixels1; bool do_free_after_rgb2rgba = false; Graphics::PixelFormat sourceFormat; switch (format) { case TGL_RGBA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); break; case TGL_RGB: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0); break; case TGL_BGRA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); break; case TGL_BGR: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0); break; default: error("glTexImage2D: Pixel format not handled."); } Graphics::PixelFormat pf; switch (format) { case TGL_RGBA: case TGL_RGB: pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); break; case TGL_BGRA: case TGL_BGR: pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); break; default: break; } int bytes = pf.bytesPerPixel; // Simply unpack RGB into RGBA with 255 for Alpha. // FIXME: This will need additional checks when we get around to adding 24/32-bit backend. if (target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0) { if (format == TGL_RGB || format == TGL_BGR) { Graphics::PixelBuffer temp(pf, width * height, DisposeAfterUse::NO); Graphics::PixelBuffer pixPtr(sourceFormat, (byte *)pixels); for (int i = 0; i < width * height; ++i) { uint8 r, g, b; pixPtr.getRGBAt(i, r, g, b); temp.setPixelAt(i, 255, r, g, b); } format = TGL_RGBA; pixels = temp.getRawBuffer(); do_free_after_rgb2rgba = true; } } else if (!(target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == TGL_RGBA && type == TGL_UNSIGNED_BYTE)) { error("glTexImage2D: combination of parameters not handled"); } pixels1 = new byte[256 * 256 * bytes]; if (width != 256 || height != 256) { // no interpolation is done here to respect the original image aliasing ! //gl_resizeImageNoInterpolate(pixels1, 256, 256, (unsigned char *)pixels, width, height); // used interpolation anyway, it look much better :) --- aquadran gl_resizeImage(pixels1, 256, 256, (byte *)pixels, width, height); width = 256; height = 256; } else { memcpy(pixels1, pixels, 256 * 256 * bytes); } im = &c->current_texture->images[level]; im->xsize = width; im->ysize = height; if (im->pixmap) im->pixmap.free(); im->pixmap = Graphics::PixelBuffer(pf, pixels1); if (do_free_after_rgb2rgba) gl_free(pixels); }
void glopVertex(GLContext * c, GLParam * p) { GLVertex *v; int n, i, cnt; gl_assert(c->in_begin != 0); n = c->vertex_n; cnt = c->vertex_cnt; cnt++; c->vertex_cnt = cnt; /* quick fix to avoid crashes on large polygons */ if (n >= c->vertex_max) { GLVertex *newarray; c->vertex_max <<= 1; /* just double size */ newarray = gl_malloc(sizeof(GLVertex) * c->vertex_max); if (!newarray) { gl_fatal_error("unable to allocate GLVertex array.\n"); } memcpy(newarray, c->vertex, n * sizeof(GLVertex)); gl_free(c->vertex); c->vertex = newarray; } /* new vertex entry */ v = &c->vertex[n]; n++; v->coord.X = p[1].f; v->coord.Y = p[2].f; v->coord.Z = p[3].f; v->coord.W = p[4].f; gl_vertex_transform(c, v); /* color */ if (c->lighting_enabled) { gl_shade_vertex(c, v); } else { v->color = c->current_color; } /* tex coords */ if (c->texture_2d_enabled) { if (c->apply_texture_matrix) { gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord); } else { v->tex_coord = c->current_tex_coord; } } /* precompute the mapping to the viewport */ if (v->clip_code == 0) gl_transform_to_viewport(c, v); /* edge flag */ v->edge_flag = c->current_edge_flag; switch (c->begin_type) { case GL_POINTS: gl_draw_point(c, &c->vertex[0]); n = 0; break; case GL_LINES: if (n == 2) { gl_draw_line(c, &c->vertex[0], &c->vertex[1]); n = 0; } break; case GL_LINE_STRIP: case GL_LINE_LOOP: if (n == 1) { c->vertex[2] = c->vertex[0]; } else if (n == 2) { gl_draw_line(c, &c->vertex[0], &c->vertex[1]); c->vertex[0] = c->vertex[1]; n = 1; } break; case GL_TRIANGLES: if (n == 3) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); n = 0; } break; case GL_TRIANGLE_STRIP: if (cnt >= 3) { if (n == 3) n = 0; /* needed to respect triangle orientation */ switch(cnt & 1) { case 0: gl_draw_triangle(c,&c->vertex[2],&c->vertex[1],&c->vertex[0]); break; default: case 1: gl_draw_triangle(c,&c->vertex[0],&c->vertex[1],&c->vertex[2]); break; } } break; case GL_TRIANGLE_FAN: if (n == 3) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); c->vertex[1] = c->vertex[2]; n = 2; } break; case GL_QUADS: if (n == 4) { c->vertex[2].edge_flag = 0; gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); c->vertex[2].edge_flag = 1; c->vertex[0].edge_flag = 0; gl_draw_triangle(c, &c->vertex[0], &c->vertex[2], &c->vertex[3]); n = 0; } break; case GL_QUAD_STRIP: if (n == 4) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]); for (i = 0; i < 2; i++) c->vertex[i] = c->vertex[i + 2]; n = 2; } break; case GL_POLYGON: break; default: gl_fatal_error("glBegin: type %x not handled\n", c->begin_type); } c->vertex_n = n; }
/*! Destroy context */ void pl110_DestroyContext( pl110_Context *ctx ){ if( ctx->gl_context != NULL ){ glClose(); } gl_free( ctx ); }
void pe_term (void) { gl_free (pe.q.tab); gl_free (pe.comb.tab); }
void FrameBuffer::delOffscreenBuffer(Buffer *buf) { gl_free(buf->pbuf); gl_free(buf->zbuf); gl_free(buf); }
/* Object initialization is called once after all object have been created */ int metrics::init(OBJECT *parent) { OBJECT *hdr = OBJECTHDR(this); int index, indexa, indexb, returnval; char work_metrics[1025]; char *startVal, *endVal, *workVal; char workbuffer[1025]; char metricbuffer[257]; FILE *FPVal; FINDLIST *CandidateObjs; OBJECT *temp_obj; bool *temp_bool; FUNCTIONADDR funadd = NULL; //Ensure our "module metrics" object is populated if (module_metrics_obj == NULL) { GL_THROW("Please specify a module metrics object for metrics:%s",hdr->name); /* TROUBLESHOOT To operate properly, the metrics object must have the corresponding module's metrics calculator linked. If this object is missing, metrics has no idea what to calculate and will not proceed. */ } //It's not null, map up the init function and call it (this must exist, even if it does nothing) funadd = (FUNCTIONADDR)(gl_get_function(module_metrics_obj,"init_reliability")); //Make sure it was found if (funadd == NULL) { GL_THROW("Unable to map reliability init function on %s in %s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to initialize the reliability module in the "module of interest" metrics device, a error was encountered. Ensure this object fully supports reliability and try again. If the bug persists, please submit your code and a bug report to the trac website. */ } Extra_Data = ((void *(*)(OBJECT *, OBJECT *))(*funadd))(module_metrics_obj,hdr); //Make sure it worked if (Extra_Data==NULL) { GL_THROW("Unable to map reliability init function on %s in %s",module_metrics_obj->name,hdr->name); //defined above } //Figure out how many indices we should be finding index = 0; while ((metrics_oi[index] != '\0') && (index < 1024)) { if (metrics_oi[index] == ',') { num_indices++; //Increment counter } index++; //Increment pointer } //Make sure we didn't blow the top off if (index == 1024) { GL_THROW("Maximum length exceeded on metrics_of_interest in metrics:%s",hdr->name); /* TROUBLESHOOT While parsing the metrics_of_interest list, the maximum length (1024 characters) was reached. This can cause undesired behavior. Ensure the metrics list is within this character count. If it is, please try again. If the error persists, please submit your code and a bug report via the trac website. */ } //See if at least one was found. If it was, that means there are 2 (it counts commas) if (num_indices >= 1) num_indices++; //See if we were a solitary one - if so, increment accordingly if ((num_indices == 0) && (index > 1)) num_indices = 1; //Make sure at least one was found if (num_indices == 0) { GL_THROW("No indices of interest specified for metrics:%s",hdr->name); /* TROUBLESHOOT No indices were found to read. Please specify the proper indices and try again. */ } //Malloc us up! CalcIndices = (INDEXARRAY*)gl_malloc(num_indices * sizeof(INDEXARRAY)); //Make sure it worked if (CalcIndices == NULL) { GL_THROW("Failure to allocate indices memory in metrics:%s",hdr->name); /* TROUBLESHOOT While allocating the storage matrix for the indices to calculate, an error occurred. Please try again. If the error persists, please submit you code and a bug report using the trac website. */ } //Initialize these, just in case for (index=0; index<num_indices; index++) { CalcIndices[index].MetricLoc = NULL; //No address by default for (indexa=0; indexa<257; indexa++) //+1 due to end \0 CalcIndices[index].MetricName[indexa]='\0'; } //Populate it up - copy it first so we don't destroy the original metrics_oi.copy_to(work_metrics); //Set initial pointers startVal = work_metrics; endVal = work_metrics; //Loop through and find them for (index=0; index<num_indices; index++) //Loop through { //Find the next comma or end point while ((*endVal != ',') && (*endVal != '\0')) { endVal++; } //Replace us (comma) with EOS (\0) *endVal='\0'; //Copy us into the structure workVal = startVal; indexa = 0; while ((workVal<=endVal) && (indexa < 256)) { //Copy the value in CalcIndices[index].MetricName[indexa] = *workVal; //Copy into secondary metricbuffer[indexa] = *workVal; //Increment pointers indexa++; workVal++; } //apply the "_int" portion for the interval search indexb = indexa-1; //Now update pointers appropriately and proceed endVal++; startVal = endVal; //Now try to find this variable CalcIndices[index].MetricLoc = get_metric(module_metrics_obj,CalcIndices[index].MetricName); //Make sure it worked if (CalcIndices[index].MetricLoc == NULL) { GL_THROW("Unable to find metric %s in object %s for metric:%s",CalcIndices[index].MetricName.get_string(),module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to map out a reliability metric, the desired metric was not found. Please check the variable name and ensure the metric is being published in the module metrics object and try again. If the error persists, please submit your code and a bug report to the trac website. */ } //Get the interval metric - if it exists - and there is room if ((indexb+4) <= 256) { metricbuffer[indexb] = '_'; metricbuffer[(indexb+1)] = 'i'; metricbuffer[(indexb+2)] = 'n'; metricbuffer[(indexb+3)] = 't'; metricbuffer[(indexb+4)] = '\0'; //Try to map it CalcIndices[index].MetricLocInterval = get_metric(module_metrics_obj,metricbuffer); //No NULL check - if it wasn't found, we won't deal with it } }//end metric traversion //Map our reset functions for ease reset_interval_func = (FUNCTIONADDR)(gl_get_function(module_metrics_obj,"reset_interval_metrics")); //Make sure it worked if (reset_interval_func == NULL) { GL_THROW("Failed to map interval reset in metrics object %s for metrics:%s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to map the interval statistics reset function, the metrics object encountered a problem. Please make sure the module metrics object supports a "reset_interval_metrics" function. If so, please try again. If the error persists, please submit your code and a bug report using the trac website. */ } reset_annual_func = (FUNCTIONADDR)(gl_get_function(module_metrics_obj,"reset_annual_metrics")); //Make sure it worked if (reset_annual_func == NULL) { GL_THROW("Failed to map annual reset in metrics object %s for metrics:%s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to map the annual statistics reset function, the metrics object encountered a problem. Please make sure the module metrics object supports a "reset_interval_metrics" function. If so, please try again. If the error persists, please submit your code and a bug report using the trac website. */ } compute_metrics = (FUNCTIONADDR)(gl_get_function(module_metrics_obj,"calc_metrics")); //Make sure it worked if (compute_metrics == NULL) { GL_THROW("Failed to map metric computation function in metrics object %s for metrics:%s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to map the function to compute the desired metrics, the metrics object encountered a problem. Please make sure the module metrics object supports a "calc_metrics" function. If so, please try again. If the error persists, please submit your code and a bug report using the trac website. */ } //Call the resets - interval returnval = ((int (*)(OBJECT *, OBJECT *))(*reset_interval_func))(hdr,module_metrics_obj); if (returnval != 1) //See if it failed { GL_THROW("Failed to reset interval metrics for %s by metrics:%s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT The metrics object encountered an error while attempting to reset the interval statistics variables. Please try again. If the error persists, submit your code and a bug report via the trac website. */ } //Call the resets - annual returnval = ((int (*)(OBJECT *, OBJECT *))(*reset_annual_func))(hdr,module_metrics_obj); if (returnval != 1) //See if it failed { GL_THROW("Failed to reset annual metrics for %s by metrics:%s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT The metrics object encountered an error while attempting to reset the annual statistics variables. Please try again. If the error persists, submit your code and a bug report via the trac website. */ } //Convert our calculation interval to a timestamp metric_interval = (TIMESTAMP)metric_interval_dbl; report_interval = (TIMESTAMP)report_interval_dbl; //See if it is a year - flag appropriately if (metric_interval == 31536000) metric_equal_annual = true; //Make sure we have a file name provided if (report_file[0] == '\0') //None specified { GL_THROW("Please specify a proper report file name if you would like an output file from metrics:%s",hdr->name); /* TROUBLESHOOT While attempting to write the report file, an invalid file name was provided. Please provide a valid file name and try again. */ } //Open the file to clear it FPVal = fopen(report_file,"wt"); //Make sure it worked if (FPVal == NULL) { GL_THROW("Unable to create the report file '%s' for metrics:%s",report_file,hdr->name); /* TROUBLESHOOT While attempting to write the metrics output file, an error occurred. Please make sure you have write permissions at that location and try again. If the error persists, please submit your code and a bug report using the trac website. */ } //It must exist - write the typical header nonsense fprintf(FPVal,"Reliability report for %s\n", gl_global_getvar("modelname",workbuffer,(1025*sizeof(char)))); //Find our lucky candidate objects CandidateObjs = gl_find_objects(FL_GROUP,customer_group.get_string()); if (CandidateObjs==NULL) { GL_THROW("Failure to find devices for %s specified as: %s",hdr->name,customer_group.get_string()); /* TROUBLESHOOT While attempting to populate the list of devices to check for reliability metrics, the metrics object failed to find any desired objects. Please make sure the objects exist and try again. If the bug persists, please submit your code using the trac website. */ } //Do a zero-find check as well if (CandidateObjs->hit_count == 0) { GL_THROW("Failure to find devices for %s specified as: %s",hdr->name,customer_group.get_string()); //Defined above } //Pull the count CustomerCount = CandidateObjs->hit_count; //Make us an array! Customers = (CUSTARRAY*)gl_malloc(CustomerCount*sizeof(CUSTARRAY)); //Make sure it worked if (Customers == NULL) { GL_THROW("Failure to allocate customer list memory in metrics:%s",hdr->name); /* TROUBLESHOOT While allocating the memory for the list of customers, GridLAB-D encountered a problem. Please try again. If the error persists, please submit your code and a bug report via the trac website. */ } //Let's populate the beast now! temp_obj = NULL; for (index=0; index<CustomerCount; index++) { //Find the object temp_obj = gl_find_next(CandidateObjs, temp_obj); if (temp_obj == NULL) { GL_THROW("Failed to populate customer list in metrics: %s",hdr->name); /* TROUBLESHOOT While populating the metrics customer list, an object failed to be located. Please try again. If the error persists, please submit your code and a bug report to the trac website. */ } Customers[index].CustomerObj = temp_obj; //Try to find our "outage" indicator and map its address temp_bool = get_outage_flag(temp_obj, "customer_interrupted"); //make sure it found it if (temp_bool == NULL) { GL_THROW("Unable to find interrupted flag for customer object %s in metrics:%s",temp_obj->name,hdr->name); /* TROUBLESHOOT While attempting to link to the 'customer interrupted' flag, an error occurred. Please ensure the object supports being polled by reliability as a customer (customer_interrupted exists as a published property) and try again. If the error persists, please submit your code and a bug report via the trac website. */ } //Write this value in Customers[index].CustInterrupted = temp_bool; if (index == 0) //First customer, handle slightly different { //Populate the secondary index - needs to exist, even if never used //Try to find our secondary "outage" indicator and map its address temp_bool = get_outage_flag(temp_obj, "customer_interrupted_secondary"); //make sure it found it if (temp_bool == NULL) //Not found, assume no one else wants one { gl_warning("Unable to find secondary interruption flag, no secondary interruptions recorded in metrics:%s",hdr->name); /* TROUBLESHOOT While attempting to link to the 'secondary customer interrupted' flag, it was not found. THe object may not support "secondary interruption counts" and this message is valid. If a secondary count was desired, ensure the object supports being polled by reliability as a customer (customer_interrupted_secondary exists as a published property) and try again. If the error persists, please submit your code and a bug report via the trac website. */ } else //One found, assume all want one now { secondary_interruptions_count = true; //Write this value in Customers[index].CustInterrupted_Secondary = temp_bool; } } else if (secondary_interruptions_count == true) //Decided we want it { //Populate the secondary index - needs to exist, even if never used //Try to find our secondary "outage" indicator and map its address temp_bool = get_outage_flag(temp_obj, "customer_interrupted_secondary"); //make sure it found it if (temp_bool == NULL) { GL_THROW("Unable to find secondary interruption flag for customer object %s in metrics:%s",temp_obj->name,hdr->name); /* TROUBLESHOOT While attempting to link to the 'secondary customer interrupted' flag, an error occurred. Please ensure the object supports being polled by reliability as a customer (customer_interrupted_secondary exists as a published property) and try again. If the error persists, please submit your code and a bug report via the trac website. */ } //Write this value in Customers[index].CustInterrupted_Secondary = temp_bool; } //Defaulted else - unwanted }//end population loop //Free up list gl_free(CandidateObjs); //Write the customer count and header information to the file we have going fprintf(FPVal,"Number of customers = %d\n\n",CustomerCount); //See if the particular metrics object has any "comments" to add to the file header (units, notes, etc.) funadd = NULL; //Reset function pointer - just in case //Map up the "extra print" function - if it isn't there, well nothing is done funadd = (FUNCTIONADDR)(gl_get_function(module_metrics_obj,"logfile_extra")); //See if it was found if (funadd != NULL) { //Do the extra printing returnval = ((int (*)(OBJECT *, char *))(*funadd))(module_metrics_obj,workbuffer); //Make sure it worked if (returnval==0) { GL_THROW("Failed to write extra header material for %s in %s",module_metrics_obj->name,hdr->name); /* TROUBLESHOOT While attempting to write the extra material into the file header, an error occurred. Please try again. If the error persists, please submit your code and a bug report via the trac website. */ } //Print it out fprintf(FPVal,"%s",workbuffer); } //Close the file handle fclose(FPVal); return 1; /* return 1 on success, 0 on failure - We're so awesome we always assume we work */ }