more work on cachengn
This commit is contained in:
parent
658ef3ab08
commit
2c14368cd5
@ -22,8 +22,8 @@ futiles.
|
||||
|
||||
## système de cache
|
||||
|
||||
new: Mon Jul 17 12:49:20 UTC 2023
|
||||
`new: Mon Jul 17 12:49:20 UTC 2023`
|
||||
|
||||
En cours : définition d'à peu-près tout ce qu'il reste à faire
|
||||
pour avoir quelque chose qui fonctionne.
|
||||
Plus d'information dans le [.h](cachegen.h).
|
||||
Plus d'information dans le [.h](cachengn.h).
|
||||
|
@ -3,23 +3,143 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "cachengn.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
static int nombre_slots = -1;
|
||||
static int index_slot = -1;
|
||||
static FimgCacheEntry *le_cache = NULL;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
void cachengn_print_version(int k)
|
||||
{
|
||||
|
||||
printf("this is the version ZERO !!!\n");
|
||||
printf("\t!!! this is the version ZERO !!!\n");
|
||||
|
||||
fprintf(stderr, "sizeof cache entry: %ld\n", sizeof(FimgCacheEntry));
|
||||
|
||||
if (k) fimg_print_version(0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
int init_empty_cache(int iw, int ih, int szc, int nbre)
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int init_empty_cache(int iw, int ih, int szc, int wtfparam)
|
||||
{
|
||||
return -1;
|
||||
int idx;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %d %d %d %d )\n", __func__,
|
||||
iw, ih, szc, wtfparam);
|
||||
|
||||
/* MOLLYGUARD : don't init TWICE, please */
|
||||
if (NULL != le_cache) {
|
||||
fprintf(stderr, "%s: there is a cache at %p\n", __func__,
|
||||
le_cache);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* allocate an prepare memory */
|
||||
if ( NULL==(le_cache=calloc(szc, sizeof(FimgCacheEntry))) ) {
|
||||
fprintf(stderr, "%s: no memory, sorry...\n", __func__);
|
||||
return -3;
|
||||
}
|
||||
fprintf(stderr, " slot array at %p\n", le_cache);
|
||||
for (idx=0; idx<szc; idx++) {
|
||||
le_cache[idx].flags = 0xF0;
|
||||
le_cache[idx].index = idx;
|
||||
}
|
||||
|
||||
/* update private cache metadata */
|
||||
nombre_slots = szc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
FloatImg *give_me_thiz_picz(char *fname, int notused)
|
||||
{
|
||||
int idx, foo, freeslot;
|
||||
FloatImg img;
|
||||
char *nptr;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
||||
|
||||
/* please add molly guard ! */
|
||||
|
||||
if (notused)
|
||||
fprintf(stderr, "in %s, notused was %d\n", __func__, notused);
|
||||
|
||||
/* is the floatimg already in the cahce ? */
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
nptr = le_cache[idx].filename;
|
||||
if (NULL!=nptr && (! strcmp(fname, nptr))) {
|
||||
fprintf(stderr, "found '%s' at %d\n", nptr, idx);
|
||||
return le_cache[idx].image;
|
||||
}
|
||||
}
|
||||
|
||||
/* we not have this picture in ou cache, so we need a free
|
||||
slot for it */
|
||||
freeslot = -1;
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
if (NULL==le_cache[idx].image) {
|
||||
freeslot = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "freeslot = %d\n", freeslot);
|
||||
|
||||
/* check if we can read this file */
|
||||
foo = access(fname, R_OK); /* XXX */
|
||||
if (foo) {
|
||||
perror(__FILE__ ": give_me_thiz_picz");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* try to load the requested file */
|
||||
foo = fimg_create_from_dump(fname, &img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "oups on %s\n", fname);
|
||||
return NULL;
|
||||
}
|
||||
/* OK we have all the pixels in core memorey */
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int liste_le_cache(unsigned int flags)
|
||||
{
|
||||
int idx;
|
||||
|
||||
fprintf(stderr, ">>> %s ( Ox%X )\n", __func__, flags);
|
||||
|
||||
/* please add molly guard here */
|
||||
|
||||
fprintf(stderr, "cache at %p : %d slots, idx = %d\n",
|
||||
le_cache, nombre_slots, index_slot);
|
||||
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
fprintf(stderr, "%5d ", idx);
|
||||
fprintf(stderr, "0x%02x ", le_cache[idx].flags);
|
||||
fprintf(stderr, "%p ", le_cache[idx].image);
|
||||
fprintf(stderr, "%s\n", le_cache[idx].filename);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -4,4 +4,26 @@
|
||||
|
||||
void cachengn_print_version(int k);
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
char *filename;
|
||||
FloatImg *image;
|
||||
int index;
|
||||
} FimgCacheEntry;
|
||||
|
||||
|
||||
/*
|
||||
* parameters:
|
||||
* - iw, ik : image size
|
||||
* - szc : number of slots
|
||||
* - nbre : WTF isthat?
|
||||
*/
|
||||
int init_empty_cache(int iw, int ih, int szc, int nbre);
|
||||
|
||||
|
||||
/* /!\ the floatimg returned must be view as readonly */
|
||||
FloatImg *give_me_thiz_picz(char *fname, int notused);
|
||||
|
||||
|
||||
/* utilities functions */
|
||||
int liste_le_cache(unsigned int flags);
|
||||
|
@ -3,24 +3,45 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "cachengn.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
#define IMGW 320
|
||||
#define IMGH 240
|
||||
#define SIZE 20
|
||||
|
||||
#define SIZE 5 // number of slots
|
||||
#define NBRI 1000
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
FloatImg *picz;
|
||||
char *fname = "quux.fimg";
|
||||
|
||||
fprintf(stderr, "Test of the cache engin - %s %s\n", __DATE__, __TIME__);
|
||||
fprintf(stderr, "\nTest of the cache engin - %s %s\n",
|
||||
__DATE__, __TIME__);
|
||||
cachengn_print_version(1);
|
||||
|
||||
foo = init_empty_cache(IMGW, IMGH, SIZE, NBRI);
|
||||
fprintf(stderr, "init_empty_cache --> %d\n", foo);
|
||||
fprintf(stderr, " init_empty_cache --> %d\n", foo);
|
||||
|
||||
foo = liste_le_cache((unsigned int)'U');
|
||||
fprintf(stderr, " liste le cache --> %d\n", foo);
|
||||
|
||||
picz = give_me_thiz_picz(fname, 0);
|
||||
if (NULL == picz) {
|
||||
fprintf(stderr, " error 'givemeapicz' on '%s'\n", fname);
|
||||
}
|
||||
|
||||
picz = give_me_thiz_picz(fname, 0);
|
||||
if (NULL == picz) {
|
||||
fprintf(stderr, " error 'givemeapicz' on '%s'\n", fname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user