gtdc/tdc_store.c
2008-03-18 19:30:21 +01:00

64 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tdc_store.h"
#include "tdc_variable.h"
#include "gui_variable_tab.h"
static char *boardname[8];
static struct tdc_var *varmap[256];
void tdcstore_set_name(int address, char *name)
{
if (boardname[address & 0x7] != NULL)
free(boardname[address & 0x7]);
boardname[address & 0x7] = strdup(name);
printf("ADDR%d:%s\n", address, boardname[address & 0x7]);
}
char * tdcstore_get_name(int address)
{
return boardname[address & 0x7];
}
int tdcstore_set_var(int address, struct tdc_var *var)
{
if (varmap[var->id] != NULL) {
gui_vartab_remove_var(var);
tdcvar_destroy(varmap[var->id]);
}
varmap[var->id] = var;
gui_vartab_add_var(var);
return 0;
}
struct tdc_var * tdcstore_get_var(int address, int id)
{
return varmap[id & 0xFF];
}
void tdcstore_trigger_update(int address, int id)
{
gui_vartab_update_var(varmap[id & 0xFF]);
}
void tdcstore_flush(void)
{
int i;
for (i = 0; i < 8; i++) {
free(boardname[i]);
boardname[i] = NULL;
}
for (i = 0; i < 256; i++) {
gui_vartab_remove_var(varmap[i]);
tdcvar_destroy(varmap[i]);
varmap[i] = NULL;
}
}