/* * indir.c * * Control of memory allocation * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Glass is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include /* * Steel headers */ #define _STDAPP #include "steel/Steel.h" #include "steel/buttons.h" #include "steel/bbc.h" extern void flex_dump(const char *p); /* * Glass headers */ #include "gIcons.h" #include "glass.h" #include "heap.h" #include "indir.h" /*----- Static variables --------------------------------------------------*/ static heap_infostr indir__info; static BOOL indir__outOfDate; static dbox indir__dbox; /*----- Support routines --------------------------------------------------*/ /* * void indir__update(void *handle) * * Use * Updates the heap info window if necessary */ static void indir__update(void *handle) { unused(handle); if (indir__dbox) { indir__info=heap_info(); dbox_setfield(indir__dbox, glass_HEAPSIZE, "%s", utils_cvtSize(indir__info.size)); dbox_setfield(indir__dbox, glass_FREESIZE, "%s", utils_cvtSize(indir__info.free)); dbox_setfield(indir__dbox, glass_LARGEST, "%s", utils_cvtSize(indir__info.largest)); buttons_updateSlider(indir__dbox, glass_HEAPSLIDE, indir__info.size, indir__info.size-indir__info.free, 11, FALSE); } if (indir__outOfDate) { win_removeIdleClaimer(indir__update,0); indir__outOfDate=FALSE; } } /*----- Event handlers ----------------------------------------------------*/ /* * void indir__dboxRedraw(wimp_redrawstr *r,void *handle) * * Use * Redraws the dbox used to show heap information * * Parameters * wimp_redrawstr *r == information about the redraw * void *handle == a pointer (ignored) */ static void indir__dboxRedraw(wimp_redrawstr *r,void *handle) { unused(r); unused(handle); buttons_redrawSlider(indir__dbox,glass_HEAPSLIDE,indir__info.size, indir__info.size-indir__info.free,11,FALSE); } /* * BOOL indir__dboxRaw(dbox d,wimp_eventstr *e,void *handle) * * Use * Handles raw events (just redraw requests for the moment) for the heap * info dialogue. * * Parameters * dbox d == the dbox handle * wimp_eventstr *e == the event that occurred * void *handle == a pointer (ignored) * * Returns * TRUE if the event has been dealt with */ static BOOL indir__dboxRaw(dbox d,wimp_eventstr *e,void *handle) { BOOL handled=FALSE; unused(d); unused(handle); switch (e->e) { case wimp_EREDRAW: wimpt_redraw(indir__dboxRedraw,0); handled=TRUE; break; } return (handled); } /* * void indir__dboxHandler(dbox d,dbox_field f,void *handle) * * Use * Handles events for the heap info dialogue box. * * Parameters * dbox d == the dbox handle * dbox_field f == the event that occurred * void *handle == a pointer (ignored) */ static void indir__dboxHandler(dbox d,dbox_field f,void *handle) { unused(handle); switch (f) { case dbox_CLOSE: dbox_delete(d); win_remove_idle_claimer(indir__update,0); indir__dbox=0; break; #ifdef _dll_NODLL case 9: dbox_clickicon(d,f); dbox_unclick(); bbc_vdu(26); bbc_vdu(4); bbc_vdu(12); bbc_vdu(14); flex_dump("Glass flex dump"); bbc_get(); bbc_vdu(15); bbc_vdu(5); wimpt_forceredraw(); break; #endif case dbox_HELP: help_startHelp(); help_addLine(msgs_lookup("idhHPINF")); help_endHelp(); break; } } /*----- External routines -------------------------------------------------*/ /* * void indir_init(void) * * Use * Jumps in to ensure that indir gets the first flex block, so it doesn't * move. */ void indir_init(void) { heap_init(); } /* * void *indir_alloc(int size) * * Use * Allocate memory from heap. * * Parameters * int size == the number of bytes the caller wants */ void *indir_alloc(size_t size) { if (!indir__outOfDate) { indir__outOfDate=TRUE; win_addIdleClaimer(indir__update,win_DONTCARE,0); } return (heap_alloc(size)); } /* * void indir_free(void *p) * * Use * Reclaims the memory from the block pointed to by p. Some simple checks * are used to ensure that p is valid. * * Parameters * void *p == pointer to a block to free. */ void indir_free(void *p) { if (!indir__outOfDate) { indir__outOfDate=TRUE; win_addIdleClaimer(indir__update,win_DONTCARE,0); } heap_free(p); } /* * void *indir_realloc(void *p,int newsize) * * Use * Resizes a heap block. * * Parameters * void *p == pointer to block to resize * int newsize == the new size to make it * * Returns * Pointer to the block (may have moved) or 0 (failure, block didn't move) */ void *indir_realloc(void *p,int newsize) { if (!indir__outOfDate) { indir__outOfDate=TRUE; win_addIdleClaimer(indir__update,win_DONTCARE,0); } return (heap_realloc(p,newsize)); } /* * void indir_heapInfo(void) * * Use * Displays a dialogue box showing current heap stats */ void indir_heapInfo(void) { if (!indir__dbox) { indir__dbox=dbox_create("heapInfo"); indir__outOfDate=FALSE; indir__update(0); #ifndef _dll_NODLL dbox_shadeicon(indir__dbox,9,TRUE); #endif dbox_eventHandler(indir__dbox,indir__dboxHandler,0); dbox_rawEventHandler(indir__dbox,indir__dboxRaw,0); } dbox_display(indir__dbox,dbox_STATIC_LASTPOS); }