aboutsummaryrefslogtreecommitdiff
path: root/core/salis.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/salis.c')
-rw-r--r--core/salis.c58
1 files changed, 17 insertions, 41 deletions
diff --git a/core/salis.c b/core/salis.c
index f6d259f..abed1ec 100644
--- a/core/salis.c
+++ b/core/salis.c
@@ -5,18 +5,18 @@
#include <stdlib.h>
#include <string.h>
#include <threads.h>
-
-#if defined(DATA_PUSH)
-#include <sqlite3.h>
-#include <zlib.h>
-#endif
+#include "logger.c"
#if defined(COMPRESS)
#include <zlib.h>
+#include "compress.c"
#endif
-#if defined(COMPRESS) || defined(DATA_PUSH)
+#if defined(DATA_PUSH)
+#include <sqlite3.h>
+#include <zlib.h>
#include "compress.c"
+#include "sql.c"
#endif
#define INST_CAP 0x80
@@ -92,16 +92,7 @@ const struct Proc g_dead_proc;
char g_asav_pbuf[AUTOSAVE_NAME_LEN];
#endif
-// Each UI must install these logger functions before salis_init() gets invoked
-void (*g_info)(const char *fmt, ...);
-void (*g_warn)(const char *fmt, ...);
-
#if defined(DATA_PUSH)
-// Include custom SQL wrapper
-// This is also used by the data-server
-sqlite3 *g_sim_db;
-#include "sql.c"
-
thrd_t g_eva_thrds[CORES][EVENT_ARRAYS_COUNT];
struct DeflateParams g_eva_deflate_params[CORES][EVENT_ARRAYS_COUNT];
#endif
@@ -695,7 +686,7 @@ void salis_save(const char *path) {
.out = (Bytef *)out,
};
- salis_deflate(&params);
+ comp_deflate(&params);
FILE *fx = fopen(path, "wb");
assert(fx);
@@ -704,7 +695,7 @@ void salis_save(const char *path) {
fwrite(out, sizeof(char), params.strm.total_out, fx);
fclose(fx);
- salis_deflate_end(&params);
+ comp_deflate_end(&params);
free(in);
free(out);
@@ -738,7 +729,7 @@ void salis_push_data_header(void) {
assert(g_sim_db);
g_info("Creating core table in SQLite database");
- salis_exec_sql(
+ sql_exec(
0, NULL, NULL,
"create table core ("
#define EVENT_ARRAY(core, index, ev) \
@@ -810,7 +801,7 @@ void salis_push_data_line(void) {
params->size = EVA_SIZE,
params->in = (Bytef *)in,
params->out = (Bytef *)malloc(EVA_SIZE),
- thrd_create(&g_eva_thrds[i][j], (thrd_start_t)salis_deflate, params);
+ thrd_create(&g_eva_thrds[i][j], (thrd_start_t)comp_deflate, params);
}
}
@@ -825,7 +816,7 @@ void salis_push_data_line(void) {
}
g_info("Pushing row to core table in SQLite database");
- salis_exec_sql(
+ sql_exec(
CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes,
"insert into core ("
#define EVENT_ARRAY(core, index, ev) \
@@ -883,7 +874,7 @@ void salis_push_data_line(void) {
for (int i = 0; i < CORES; ++i) {
for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) {
struct DeflateParams *params = &g_eva_deflate_params[i][j];
- salis_deflate_end(params);
+ comp_deflate_end(params);
free(params->out);
}
}
@@ -924,18 +915,8 @@ void salis_init(void) {
#endif
#if defined(DATA_PUSH)
- sqlite3_open(DATA_PUSH_PATH, &g_sim_db);
- assert(g_sim_db);
-
- // Install busy handler to retry transactions if DB is locked
- sqlite3_busy_timeout(g_sim_db, DATA_PUSH_BUSY_TIMEOUT);
-
- // Enable Write-Ahead Logging (WAL)
- // This seems to help prevent DB locks when displaying live data.
- // See: https://sqlite.org/wal.html
- salis_exec_sql(0, NULL, NULL, "pragma journal_mode=wal;");
-
// Initialize database
+ sql_open();
salis_push_data_header();
salis_push_data_line();
#endif
@@ -971,8 +952,8 @@ void salis_load(void) {
.out = (Bytef *)out,
};
- salis_inflate(&params);
- salis_inflate_end(&params);
+ comp_inflate(&params);
+ comp_inflate_end(&params);
FILE *f = fmemopen(out, size, "rb");
#else
@@ -995,11 +976,7 @@ void salis_load(void) {
#endif
#if defined(DATA_PUSH)
- sqlite3_open(DATA_PUSH_PATH, &g_sim_db);
- assert(g_sim_db);
-
- // Install busy handler to retry transactions if DB is locked
- sqlite3_busy_timeout(g_sim_db, DATA_PUSH_BUSY_TIMEOUT);
+ sql_open();
#endif
}
#endif
@@ -1131,8 +1108,7 @@ void salis_step(uint64_t ns) {
void salis_free(void) {
#if defined(DATA_PUSH)
- assert(g_sim_db);
- sqlite3_close(g_sim_db);
+ sql_close();
#endif
for (int i = 0; i < CORES; ++i) {