// 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);