From: Rémi Denis-Courmont Date: Sat, 19 Dec 2009 18:26:30 +0000 (+0200) Subject: probe: infrastructure for run-time features probing X-Git-Tag: 1.1.0-ff~1820 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=15d640b84294de5f865dd49d040c0ca24abcd091;p=vlc probe: infrastructure for run-time features probing --- diff --git a/include/vlc_probe.h b/include/vlc_probe.h new file mode 100644 index 0000000000..227889b773 --- /dev/null +++ b/include/vlc_probe.h @@ -0,0 +1,70 @@ +/***************************************************************************** + * vlc_probe.h: service probing interface + ***************************************************************************** + * Copyright (C) 2009 Rémi Denis-Courmont + * + * This program 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 program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef VLC_PROBE_H +# define VLC_PROBE_H 1 + +# include + +/** + * \file + * This file defines functions and structures to run-time probe VLC extensions + */ + +# ifdef __cplusplus +extern "C" { +# endif + +VLC_EXPORT(void *, vlc_probe, (vlc_object_t *, const char *, + size_t *restrict)); +#define vlc_probe(obj, cap, pcount) \ + vlc_probe(VLC_OBJECT(obj), cap, pcount) + +struct vlc_probe_t +{ + VLC_COMMON_MEMBERS + + void *list; + size_t count; +}; + +typedef struct vlc_probe_t vlc_probe_t; + +static inline int vlc_probe_add(vlc_probe_t *obj, const void *data, + size_t len) +{ + char *tab = (char *)realloc (obj->list, (obj->count + 1) * len); + + if (unlikely(tab == NULL)) + return VLC_ENOMEM; + memcpy(tab + (obj->count * len), data, len); + obj->list = tab; + obj->count++; + return VLC_SUCCESS; +} + +# define VLC_PROBE_CONTINUE VLC_EGENERIC +# define VLC_PROBE_STOP VLC_SUCCESS + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 3084e3f229..4da4a1068a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -88,6 +88,7 @@ pluginsinclude_HEADERS = \ ../include/vlc_picture_pool.h \ ../include/vlc_playlist.h \ ../include/vlc_plugin.h \ + ../include/vlc_probe.h \ ../include/vlc_rand.h \ ../include/vlc_services_discovery.h \ ../include/vlc_sql.h \ @@ -402,6 +403,7 @@ SOURCES_libvlc_common = \ text/iso_lang.c \ text/iso-639_def.h \ misc/md5.c \ + misc/probe.c \ misc/rand.c \ misc/mtime.c \ misc/block.c \ diff --git a/src/misc/probe.c b/src/misc/probe.c new file mode 100644 index 0000000000..79922fa66e --- /dev/null +++ b/src/misc/probe.c @@ -0,0 +1,51 @@ +/***************************************************************************** + * probe.c : run-time service listing + ***************************************************************************** + * Copyright © 2009 Rémi Denis-Courmont + * + * This program 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 program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include "libvlc.h" + +#undef vlc_probe +void *vlc_probe (vlc_object_t *obj, + const char *capability, size_t *restrict pcount) +{ + vlc_probe_t *probe = vlc_custom_create (obj, sizeof(*probe), + VLC_OBJECT_GENERIC, "probe"); + if (unlikely(probe == NULL)) + { + *pcount = 0; + return NULL; + } + probe->list = NULL; + probe->count = 0; + + module_t *mod = module_need (probe, capability, NULL, false); + if (mod != NULL) + module_unneed (probe, mod); + + void *ret = probe->list; + *pcount = probe->count; + vlc_object_release (probe); + return ret; +}