summaryrefslogtreecommitdiff
path: root/src/common/console.h
blob: 643edc3d953bc6d1b8e4422b25738a12f3984e99 (plain) (blame)
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
89
90
91
92
93
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file

#ifndef COMMON_CONSOLE_H
#define COMMON_CONSOLE_H

#include "config/core.h" // MAX_CONSOLE_INPUT

#include "common/cbasetypes.h"
#include "common/mutex.h"
#include "common/spinlock.h"
#include "common/sql.h"
#include "common/thread.h"

/**
 * Queue Max
 * why is there a limit, why not make it dynamic? - I'm playing it safe, I'd rather not play with memory management between threads
 **/
#define CONSOLE_PARSE_SIZE 10

/**
 * Default parsing function abstract prototype
 **/
typedef void (*CParseFunc)(char *line);

/**
 * Console parsing function prototypes
 * CPCMD: Console Parsing CoMmand
 * x - command
 * y - category
 **/
#define CPCMD(x) void console_parse_ ##x (char *line)
#define CPCMD_A(x) console_parse_ ##x
#define CPCMD_C(x,y) void console_parse_ ##y ##x (char *line)
#define CPCMD_C_A(x,y) console_parse_ ##y ##x

#define CP_CMD_LENGTH 20
struct CParseEntry {
	char cmd[CP_CMD_LENGTH];
	union {
		CParseFunc func;
		struct CParseEntry **next;
	} u;
	unsigned short next_count;
};

#ifdef CONSOLE_INPUT
struct console_input_interface {
	/* vars */
	SPIN_LOCK ptlock;/* parse thread lock */
	rAthread *pthread;/* parse thread */
	volatile int32 ptstate;/* parse thread state */
	ramutex *ptmutex;/* parse thread mutex */
	racond *ptcond;/* parse thread cond */
	/* */
	struct CParseEntry **cmd_list;
	struct CParseEntry **cmds;
	unsigned int cmd_count;
	unsigned int cmd_list_count;
	/* */
	Sql *SQL;
	/* */
	void (*parse_init) (void);
	void (*parse_final) (void);
	int (*parse_timer) (int tid, int64 tick, int id, intptr_t data);
	void *(*pthread_main) (void *x);
	void (*parse) (char* line);
	void (*parse_sub) (char* line);
	int (*key_pressed) (void);
	void (*load_defaults) (void);
	void (*parse_list_subs) (struct CParseEntry *cmd, unsigned char depth);
	void (*addCommand) (char *name, CParseFunc func);
	void (*setSQL) (Sql *SQL_handle);
};
#else
struct console_input_interface;
#endif

struct console_interface {
	void (*init) (void);
	void (*final) (void);
	void (*display_title) (void);

	struct console_input_interface *input;
};

struct console_interface *console;

#ifdef HERCULES_CORE
void console_defaults(void);
#endif // HERCULES_CORE

#endif /* COMMON_CONSOLE_H */