summary refs log tree commit diff stats
path: root/libchatprivacy/src/libchatprivacy.h
blob: 539d8b5e52d81988e9bde6822350c4f1394fd031 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// LibChatPrivacy - C component of ChatPrivacy
// Copyright (C) 2021  Soni L.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#include <emscripten.h>


/// Diagnostic message kind.
// NOTE: We use semver here. Keep these as-is and only add new ones at the end.
// Unless you're making a new major version, in which case do whatever.
enum lcp_diag_kind {
	LCP_DIAG_DEBUG = 0,
	LCP_DIAG_INFO = 1,
	LCP_DIAG_WARN = 2,
	LCP_DIAG_ERROR = 3
};

/// Callback: Prints a message from the given user name.
typedef void lcp_cb_printmsg(char const *const name, char const *const message);

/// Callback: Sends a message to the given user name.
typedef void lcp_cb_sendmsg(char const *const name, char const *const message);

/// Callback: Prints a dialog message.
typedef void lcp_cb_dialogmsg(char const *const message);

/// Callback: Prints a diagnostic message of the given diagnostic kind.
typedef void lcp_cb_diagmsg(enum lcp_diag_kind const kind, char const *const message);

// helper for declaring callback setters.
// these are done as separate functions for convenience on the wasm/kotlin
// side.
#define LCP_CB(name) \
	lcp_cb_##name *lcp_setup_cb_##name(lcp_cb_##name *const func)

/// Sets up print message callback. Must be called before lcp_init!
///
/// Returns the previously registered callback function, or NULL if none had
/// been registered.
EMSCRIPTEN_KEEPALIVE
LCP_CB(printmsg);

/// Sets up send message callback. Must be called before lcp_init!
///
/// Returns the previously registered callback function, or NULL if none had
/// been registered.
EMSCRIPTEN_KEEPALIVE
LCP_CB(sendmsg);

/// Sets up dialog message callback. Must be called before lcp_init!
///
/// Returns the previously registered callback function, or NULL if none had
/// been registered.
EMSCRIPTEN_KEEPALIVE
LCP_CB(dialogmsg);

/// Sets up diagnostic message callback. Optional, may be NULL!
///
/// Returns the previously registered callback function, or NULL if none had
/// been registered.
EMSCRIPTEN_KEEPALIVE
LCP_CB(diagmsg);

#undef LCP_CB


/// Initializes this library for the given unique user identifier and server.
///
/// This should be called exactly once for each wasm instance.
///
/// Returns 1 on success, 0 on failure.
EMSCRIPTEN_KEEPALIVE
int lcp_init(char const *const uuid);

/// Indicate an user has joined. This should be called when an user joins.
///
/// This should also be called for every online user at the time of connecting.
EMSCRIPTEN_KEEPALIVE
void lcp_user_join(char const *const uuid, char const *const name);

/// Indicate an user has left. This should be called when an user leaves.
EMSCRIPTEN_KEEPALIVE
void lcp_user_part(char const *const uuid, char const *const name);

/// Sends a message.
EMSCRIPTEN_KEEPALIVE
void lcp_send(char const *const name, char const *const message);

/// Receives a message.
EMSCRIPTEN_KEEPALIVE
void lcp_recv(char const *const uuid, char const *const message);

/// Executes an OTR/LCP command.
///
/// Example: lcp_cmd("help")
EMSCRIPTEN_KEEPALIVE
void lcp_cmd(char const *const cmd);

/// Updates internal state. Should be called every game tick.
EMSCRIPTEN_KEEPALIVE
void lcp_tick(void);

/// Deinitializes this library.
///
/// This should be called at most once for each wasm instance.
EMSCRIPTEN_KEEPALIVE
int lcp_deinit(void);