Jonathan Gordon | 18a8e52 | 2009-08-16 18:23:00 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Bertrik Sikken | 6fef14b | 2010-01-03 14:28:09 +0000 | [diff] [blame] | 8 | * $Id$ |
Jonathan Gordon | 18a8e52 | 2009-08-16 18:23:00 +0000 | [diff] [blame] | 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * Copyright (C) 2009 Jonathan Gordon |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License |
| 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | * of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
| 22 | |
| 23 | #ifndef _SKIN_BUFFER_H_ |
| 24 | #define _SKIN_BUFFER_H_ |
| 25 | |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <stdlib.h> |
| 30 | |
| 31 | /* int the global buffer */ |
| 32 | void skin_buffer_init(void); |
| 33 | |
| 34 | /* get the number of bytes currently being used */ |
| 35 | size_t skin_buffer_usage(void); |
Jonathan Gordon | 98756fe | 2009-08-19 04:19:08 +0000 | [diff] [blame] | 36 | size_t skin_buffer_freespace(void); |
Jonathan Gordon | 18a8e52 | 2009-08-16 18:23:00 +0000 | [diff] [blame] | 37 | |
| 38 | /* Allocate size bytes from the buffer */ |
| 39 | void* skin_buffer_alloc(size_t size); |
| 40 | |
| 41 | |
| 42 | /* Get a pointer to the skin buffer and the count of how much is free |
| 43 | * used to do your own buffer management. |
| 44 | * Any memory used will be overwritten next time wps_buffer_alloc() |
| 45 | * is called unless skin_buffer_increment() is called first |
Jonathan Gordon | 98756fe | 2009-08-19 04:19:08 +0000 | [diff] [blame] | 46 | * |
| 47 | * This is from the start of the buffer, it is YOUR responsility to make |
| 48 | * sure you dont ever use more then *freespace, and bear in mind this will only |
| 49 | * be valid untill skin_buffer_alloc() is next called... |
| 50 | * so call skin_buffer_increment() and skin_buffer_freespace() regularly |
Jonathan Gordon | 18a8e52 | 2009-08-16 18:23:00 +0000 | [diff] [blame] | 51 | */ |
| 52 | void* skin_buffer_grab(size_t *freespace); |
| 53 | |
Jonathan Gordon | 98756fe | 2009-08-19 04:19:08 +0000 | [diff] [blame] | 54 | /* Use after skin_buffer_grab() to specify how much buffer was used. |
| 55 | * align should always be true unless there is a possibility that you will need |
| 56 | * more space *immediatly* after the previous allocation. (i.e in an array). |
| 57 | * NEVER leave the buffer unaligned */ |
| 58 | void skin_buffer_increment(size_t used, bool align); |
| 59 | |
| 60 | /* free previously skin_buffer_increment()'ed space. This just moves the pointer |
| 61 | * back 'used' bytes so make sure you actually want to do this */ |
| 62 | void skin_buffer_free_from_front(size_t used); |
Jonathan Gordon | 18a8e52 | 2009-08-16 18:23:00 +0000 | [diff] [blame] | 63 | |
| 64 | #endif /* _SKIN_BUFFER_H_ */ |