-
Notifications
You must be signed in to change notification settings - Fork 1
/
kots_dbthread.h
88 lines (73 loc) · 1.97 KB
/
kots_dbthread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef KOTS_DBTHREAD_H
#define KOTS_DBTHREAD_H
#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#pragma warning (disable: 4514 4786)
#pragma warning( push, 3 )
#endif
#include <stdio.h>
#include <mysql.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <pthread.h>
#include <time.h>
//undefine constants quake 2 doesn't like
#undef hyper
#undef small
#undef dprintf
#include "kots_linkedlist.h"
#define KOTS_MAX_DBTHREADS 5
#define KOTS_QUERYBUFFER_SIZE 4096
#define KOTS_MYSQL_TIMEOUT 300
#define KOTS_MYSQL_CONNECT_TIMEOUT 30
typedef struct dbthread_s
{
//thread based information
pthread_t thread;
struct jobitem_s *currentjob;
int is_running;
//mysql connection stuff
MYSQL *mysql;
struct timespec timeout;
char query_buffer[KOTS_QUERYBUFFER_SIZE];
int is_connected;
} dbthread_t;
typedef struct jobitem_s
{
char *name;
void (*function)(dbthread_t *thread, struct jobitem_s *job);
int (*wait_check)(struct jobitem_s *job);
int (*skip_check)(struct jobitem_s *job);
void (*complete_callback)(struct jobitem_s *job);
void *args;
int result;
char *last_error;
time_t queue_time;
} jobitem_t;
dbthread_t *Kots_CreateDbThread();
void Kots_FreeDbThread(dbthread_t *t);
void Kots_StopDbThread(dbthread_t *t);
void Kots_AddDbThreadJob(jobitem_t *job);
void Kots_AddDbOutputJob(jobitem_t *job);
void Kots_InitDbThreads();
void Kots_FreeDbThreads();
void Kots_CloseDbConnections(dbthread_t *thread, jobitem_t *job);
listitem_t *Kots_GetNextDbOutput();
void Kots_FreeJobItem(listitem_t *item);
jobitem_t *Kots_CreateJobItem();
void Kots_WaitForDbThreads();
MYSQL *InitializeDbConnection();
MYSQL *ConnectToDb(MYSQL *mysql);
char *Kots_GetDbUser();
char *Kots_GetDbPass();
char *Kots_GetDbName();
char *Kots_GetDbHostName();
void Kots_SetDbUser(char *value);
void Kots_SetDbPass(char *value);
void Kots_SetDbName(char *value);
void Kots_SetDbHostName(char *value);
int Kots_WaitForSave(jobitem_t *this_job);
int Kots_CheckForNewerSaves(jobitem_t *this_job);
#endif