gui: macos: use float for rate
[vlc.git] / src / input / services_discovery.c
blobf2a833f075a76fced9f90b5ccba160728cec8da9
1 /*****************************************************************************
2 * services_discovery.c : Manage playlist services_discovery modules
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
6 * Authors: Clément Stenac <zorglub@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25 #include <assert.h>
27 #include <vlc_common.h>
28 #include <vlc_services_discovery.h>
29 #include <vlc_probe.h>
30 #include <vlc_modules.h>
31 #include "../libvlc.h"
33 typedef struct
35 char *name;
36 char *longname;
37 int category;
38 } vlc_sd_probe_t;
40 int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name,
41 const char *longname, int category)
43 vlc_sd_probe_t names = { strdup(name), strdup(longname), category };
45 if (unlikely (names.name == NULL || names.longname == NULL
46 || vlc_probe_add (probe, &names, sizeof (names))))
48 free (names.name);
49 free (names.longname);
50 return VLC_ENOMEM;
52 return VLC_PROBE_CONTINUE;
55 #undef vlc_sd_GetNames
57 /**
58 * Gets the list of available services discovery plugins.
60 char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories)
62 size_t count;
63 vlc_sd_probe_t *tab = vlc_probe (obj, "services probe", &count);
65 if (count == 0)
67 free (tab);
68 return NULL;
71 char **names = vlc_alloc (count + 1, sizeof(char *));
72 char **longnames = vlc_alloc (count + 1, sizeof(char *));
73 int *categories = vlc_alloc (count + 1, sizeof(int));
75 if (unlikely (names == NULL || longnames == NULL || categories == NULL))
77 free(names);
78 free(longnames);
79 free(categories);
80 free(tab);
81 return NULL;
83 for( size_t i = 0; i < count; i++ )
85 names[i] = tab[i].name;
86 longnames[i] = tab[i].longname;
87 categories[i] = tab[i].category;
89 free (tab);
90 names[count] = longnames[count] = NULL;
91 categories[count] = 0;
92 *pppsz_longnames = longnames;
93 if( pp_categories ) *pp_categories = categories;
94 else free( categories );
95 return names;
99 * Services discovery
100 * Basically you just listen to Service discovery event through the
101 * sd's event manager.
102 * That's how the playlist get's Service Discovery information
105 #undef vlc_sd_Create
106 services_discovery_t *vlc_sd_Create(vlc_object_t *parent, const char *cfg,
107 const struct services_discovery_owner_t *restrict owner)
109 services_discovery_t *sd = vlc_custom_create(parent, sizeof (*sd),
110 "services discovery");
111 if (unlikely(sd == NULL))
112 return NULL;
114 free(config_ChainCreate(&sd->psz_name, &sd->p_cfg, cfg));
115 sd->description = NULL;
116 sd->owner = *owner;
118 sd->p_module = module_need(sd, "services_discovery",
119 sd->psz_name, true);
120 if (sd->p_module == NULL)
122 msg_Err(sd, "no suitable services discovery module");
123 vlc_sd_Destroy(sd);
124 sd = NULL;
127 return sd;
130 void vlc_sd_Destroy(services_discovery_t *sd)
132 if (sd->p_module != NULL)
133 module_unneed(sd, sd->p_module);
134 config_ChainDestroy(sd->p_cfg);
135 free(sd->psz_name);
136 vlc_object_release(sd);