1 /*****************************************************************************
2 * dialog.c: User dialog functions
3 *****************************************************************************
4 * Copyright © 2009 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_dialog.h>
37 static vlc_mutex_t provider_lock = VLC_STATIC_MUTEX;
39 #undef dialog_Register
41 * Registers an object as the dialog provider.
42 * It is assumed that the appropriate variable callbacks are already
45 int dialog_Register (vlc_object_t *obj)
47 libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
48 int ret = VLC_EGENERIC;
50 vlc_mutex_lock (&provider_lock);
51 if (priv->p_dialog_provider == NULL)
52 { /* Since the object is responsible for unregistering itself before
53 * it terminates, at reference is not needed. */
54 priv->p_dialog_provider = obj;
57 vlc_mutex_unlock (&provider_lock);
61 #undef dialog_Unregister
63 * Unregisters the dialog provider.
64 * Note that unless you have unregistered the callbacks already, the provider
65 * might still be in use by other threads. Also, you need to cancel all
66 * pending dialogs yourself.
68 int dialog_Unregister (vlc_object_t *obj)
70 libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
71 int ret = VLC_EGENERIC;
73 vlc_mutex_lock (&provider_lock);
74 if (priv->p_dialog_provider == obj)
76 priv->p_dialog_provider = NULL;
79 vlc_mutex_unlock (&provider_lock);
83 static vlc_object_t *dialog_GetProvider (vlc_object_t *obj)
85 libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
86 vlc_object_t *provider;
88 vlc_mutex_lock (&provider_lock);
89 if ((provider = priv->p_dialog_provider) != NULL)
90 vlc_object_hold (provider);
91 vlc_mutex_unlock (&provider_lock);
96 void dialog_FatalVa (vlc_object_t *obj, const char *title,
97 const char *fmt, va_list ap)
101 if (obj->i_flags & OBJECT_FLAGS_NOINTERACT)
104 vlc_object_t *provider = dialog_GetProvider (obj);
105 if (provider == NULL)
107 msg_Err (obj, "%s", title);
108 msg_GenericVa (obj, VLC_MSG_ERR, MODULE_STRING, fmt, ap);
112 if (vasprintf (&text, fmt, ap) == -1)
115 dialog_fatal_t dialog = { title, text, };
116 var_SetAddress (provider, "dialog-fatal", &dialog);
122 * Notify the user of some fatal error.
123 * This is a fire and forget function.
125 void dialog_Fatal (vlc_object_t *obj, const char *title, const char *fmt, ...)
130 dialog_FatalVa (obj, title, fmt, ap);