71 lines
1.3 KiB
C
71 lines
1.3 KiB
C
|
#include <stdlib.h>
|
||
|
#include "config.h"
|
||
|
#include "log.h"
|
||
|
|
||
|
#define EXITFUNCBLOCK_FUNCCOUNT 64
|
||
|
|
||
|
typedef struct tagEXITFUNCBLOCK
|
||
|
{
|
||
|
struct tagEXITFUNCBLOCK *next;
|
||
|
int num_funcs;
|
||
|
PEXITFUNC funcs[EXITFUNCBLOCK_FUNCCOUNT];
|
||
|
} EXITFUNCBLOCK, *PEXITFUNCBLOCK;
|
||
|
|
||
|
/* The global configuration data */
|
||
|
GLOBAL_CONFIG Gconfig;
|
||
|
|
||
|
static PEXITFUNCBLOCK exitfuncs = NULL;
|
||
|
|
||
|
static void run_exit_funcs(void)
|
||
|
{
|
||
|
int i;
|
||
|
PEXITFUNCBLOCK p;
|
||
|
|
||
|
while (exitfuncs)
|
||
|
{
|
||
|
p = exitfuncs;
|
||
|
exitfuncs = p->next;
|
||
|
for (i = p->num_funcs - 1; i >= 0; i++)
|
||
|
(*(p->funcs[i]))();
|
||
|
free(p);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void init_defaults(void)
|
||
|
{
|
||
|
Gconfig.framebuffer_device = "/dev/fb1";
|
||
|
Gconfig.button_debounce = 100;
|
||
|
Gconfig.sys_mq_length = 64;
|
||
|
}
|
||
|
|
||
|
HRESULT Config_setup(void)
|
||
|
{
|
||
|
if (atexit(run_exit_funcs))
|
||
|
{
|
||
|
Log(LFATAL, "Unable to set up exit function mechanism");
|
||
|
return E_FAIL;
|
||
|
}
|
||
|
init_defaults();
|
||
|
return S_OK;
|
||
|
}
|
||
|
|
||
|
HRESULT Config_exitfunc(PEXITFUNC pfn)
|
||
|
{
|
||
|
PEXITFUNCBLOCK p;
|
||
|
|
||
|
if (!exitfuncs || (exitfuncs->num_funcs == EXITFUNCBLOCK_FUNCCOUNT))
|
||
|
{
|
||
|
p = (PEXITFUNCBLOCK)malloc(sizeof(EXITFUNCBLOCK));
|
||
|
if (!p)
|
||
|
{
|
||
|
Log(LERROR, "unable to allocate another exit function block");
|
||
|
return E_OUTOFMEMORY;
|
||
|
}
|
||
|
p->next = exitfuncs;
|
||
|
p->num_funcs = 0;
|
||
|
exitfuncs = p;
|
||
|
}
|
||
|
exitfuncs->funcs[exitfuncs->num_funcs++] = pfn;
|
||
|
return S_OK;
|
||
|
}
|