add context initialization and uv loop

This commit is contained in:
latex 2023-01-25 01:10:44 +01:00
parent e8d5b17975
commit 170025ac5d
2 changed files with 49 additions and 0 deletions

34
include/libumumble.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef LIBUMUMBLE_H
#define LIBUMUMBLE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <uv.h>
typedef struct mumble_ctx {
uv_loop_t uv_loop;
} mumble_ctx_t;
/* Initializes a mumble context object.
* This function will allocate initial memory needed for storing e.g. the channel layout.
* Make sure to call mumble_free_ctx() when you're done!
*
* \param ctx the context object to initialize.
* \return int indicating success
* \retval 1 error
*/
int mumble_init_ctx(mumble_ctx_t ctx);
/* Free a mumble context.
*
* \param ctx the context object to free.
*/
void mumble_free_ctx(mumble_ctx_t ctx);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* LIBUMUMBLE_H */

15
src/ctx.c Normal file
View File

@ -0,0 +1,15 @@
#include <libumumble.h>
#include <uv.h>
int mumble_init_ctx(mumble_ctx_t ctx)
{
int result;
result = uv_loop_init(&ctx.uv_loop);
return result;
}
void mumble_free_ctx(mumble_ctx_t ctx)
{
uv_loop_close(&ctx.uv_loop);
}