-
Notifications
You must be signed in to change notification settings - Fork 451
How to add new modules
Baresip is highly modular, and new functionality can be added using modules.
To create a new module, choose a descriptive name and put it in the modules
folder.
The module must have a makefile snippet
called module.mk
MOD := foo
$(MOD)_SRCS += foo.c
include mk/mod.mk
Here is an example source file (foo.c):
/**
* @file foo.c Foo module
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re.h>
#include <baresip.h>
static int module_init(void)
{
info("foo: module init\n");
return 0;
}
static int module_close(void)
{
info("foo: module closed\n");
return 0;
}
const struct mod_export DECL_EXPORTS(foo) = {
"foo",
"application",
module_init,
module_close
};
The struct mod_export
declaration is global and is the entry-point
used by the module loader (for example dlopen
for Unix).
The first string "foo" is the name of the module.
The second string "application" indicates the type of module. This string can be set to e.g. "application" for application modules. Other string values can be "vidsrc", "vidcodec", "mnat", "menc" etc.
The function module_init
is called after the module has been loaded.
The function module_close
is called before the module is unloaded.
From the module_init
function you can register your handlers
and initialise things.
If you want the build system to pick up your new module, you must
add it to mk/modules.mk
:
MODULES += foo
If the module has external dependencies such as 3rd party libraries, you can add conditionals to detect presence of header files. Or use a makefile variable:
ifneq ($(USE_FOO),)
MODULES += foo
endif