summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-14 20:15:43 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-14 20:15:43 +0200
commitdc794b38d0726e5104f266d304d987a7a3ad1b18 (patch)
treee3a1012cb36b8ac27af2614124ecb8cb7c704dc7 /src
parentfcad53c745fe4cfa0a13e40f34bbe77a23aa5202 (diff)
ui: make API re-entrant
Diffstat (limited to 'src')
-rw-r--r--src/baresip.c9
-rw-r--r--src/ua.c2
-rw-r--r--src/ui.c45
3 files changed, 38 insertions, 18 deletions
diff --git a/src/baresip.c b/src/baresip.c
index 4ea493f..54a8c2c 100644
--- a/src/baresip.c
+++ b/src/baresip.c
@@ -28,6 +28,7 @@ static struct baresip {
struct list vidsrcl;
struct list vidispl;
struct list vidfiltl;
+ struct ui_sub uis;
} baresip;
@@ -141,6 +142,8 @@ void baresip_close(void)
contact_close(&baresip.contacts);
baresip.net = mem_deref(baresip.net);
+
+ ui_reset(&baresip.uis);
}
@@ -237,3 +240,9 @@ struct list *baresip_vidfiltl(void)
{
return &baresip.vidfiltl;
}
+
+
+struct ui_sub *baresip_uis(void)
+{
+ return &baresip.uis;
+}
diff --git a/src/ua.c b/src/ua.c
index 601c4fc..0e47d3f 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -1392,8 +1392,6 @@ int ua_init(const char *software, bool udp, bool tcp, bool tls,
*/
void ua_close(void)
{
- ui_reset();
-
uag.evsock = mem_deref(uag.evsock);
uag.sock = mem_deref(uag.sock);
uag.lsnr = mem_deref(uag.lsnr);
diff --git a/src/ui.c b/src/ui.c
index 2042ba0..40f476b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -9,10 +9,6 @@
#include "core.h"
-static struct list uil; /**< List of UIs (struct ui) */
-static struct cmd_ctx *uictx;
-
-
static int stdout_handler(const char *p, size_t size, void *arg)
{
(void)arg;
@@ -27,14 +23,15 @@ static int stdout_handler(const char *p, size_t size, void *arg)
/**
* Register a new User-Interface (UI) module
*
- * @param ui The User-Interface (UI) module to register
+ * @param uis UI Subsystem
+ * @param ui The User-Interface (UI) module to register
*/
-void ui_register(struct ui *ui)
+void ui_register(struct ui_sub *uis, struct ui *ui)
{
- if (!ui)
+ if (!uis || !ui)
return;
- list_append(&uil, &ui->le, ui);
+ list_append(&uis->uil, &ui->le, ui);
debug("ui: %s\n", ui->name);
}
@@ -57,12 +54,16 @@ void ui_unregister(struct ui *ui)
/**
* Send an input key to the UI subsystem, with a print function for response
*
+ * @param uis UI Subsystem
* @param key Input character
* @param pf Print function for the response
*/
-void ui_input_key(char key, struct re_printf *pf)
+void ui_input_key(struct ui_sub *uis, char key, struct re_printf *pf)
{
- (void)cmd_process(baresip_commands(), &uictx, key, pf, NULL);
+ if (!uis)
+ return;
+
+ (void)cmd_process(baresip_commands(), &uis->uictx, key, pf, NULL);
}
@@ -112,15 +113,19 @@ int ui_input_pl(struct re_printf *pf, const struct pl *pl)
/**
* Send output to all modules registered in the UI subsystem
*
+ * @param uis UI Subsystem
* @param fmt Formatted output string
*/
-void ui_output(const char *fmt, ...)
+void ui_output(struct ui_sub *uis, const char *fmt, ...)
{
char buf[512];
struct le *le;
va_list ap;
int n;
+ if (!uis)
+ return;
+
va_start(ap, fmt);
n = re_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
@@ -128,7 +133,7 @@ void ui_output(const char *fmt, ...)
if (n < 0)
return;
- for (le = uil.head; le; le = le->next) {
+ for (le = uis->uil.head; le; le = le->next) {
const struct ui *ui = le->data;
if (ui->outputh)
@@ -139,16 +144,24 @@ void ui_output(const char *fmt, ...)
/**
* Reset the state of the UI subsystem, free resources
+ *
+ * @param uis UI Subsystem
*/
-void ui_reset(void)
+void ui_reset(struct ui_sub *uis)
{
- uictx = mem_deref(uictx);
+ if (!uis)
+ return;
+
+ uis->uictx = mem_deref(uis->uictx);
}
-bool ui_isediting(void)
+bool ui_isediting(const struct ui_sub *uis)
{
- return uictx != NULL;
+ if (!uis)
+ return false;
+
+ return uis->uictx != NULL;
}