4. Main Data
This is stuff that gets instantiated at startup. For now, this is probably just the database, though this could change.
4.1. Struct
<<typedefs>>=
typedef struct wwserver_d wwserver_d;
Database + http server.
<<structs>>=
struct wwserver_d {
struct http_server_s *server;
weewiki_d *ww;
JanetTable *env;
int use_sqlar;
};
4.2. global data setters/getters
- State "DONE" from "WIP" [2020-01-16 Thu 18:15] - State "WIP" from "TODO" [2020-01-12 Sun 17:29]
<<global_data>>=
static wwserver_d *WWS = NULL;
<<static_funcdefs>>=
static void wwserver_global_set(wwserver_d *p);
<<functions>>=
static void wwserver_global_set(wwserver_d *p)
{
WWS = p;
}
<<static_funcdefs>>=
static wwserver_d * wwserver_global_get(void);
<<functions>>=
static wwserver_d * wwserver_global_get(void)
{
return WWS;
}
4.3. Startup
<<funcdefs>>=
int wwserver_init(wwserver_d *wws, int port);
<<functions>>=
int wwserver_init(wwserver_d *wws, int port)
{
wws->server = http_server_init(port, handle_request);
wws->env = weewiki_janet_setup();
wws->use_sqlar = 0;
return 1;
}
4.4. Cleanup
Database is closed. May need to figure out how to cleanly break out of loop.
<<funcdefs>>=
void wwserver_clean(wwserver_d *wws);
<<functions>>=
void wwserver_clean(wwserver_d *wws)
{
if (wws->server != NULL) {
free(wws->server);
}
weewiki_janet_cleanup();
/* weewiki data gets cleaned elsewhere */
}
prev | home | next