/src/vlc/src/input/services_discovery.c
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * services_discovery.c : Manage playlist services_discovery modules |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 1999-2004 VLC authors and VideoLAN |
5 | | * |
6 | | * Authors: Clément Stenac <zorglub@videolan.org> |
7 | | * |
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. |
12 | | * |
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. |
17 | | * |
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> |
26 | | |
27 | | #include <vlc_common.h> |
28 | | #include <vlc_configuration.h> |
29 | | #include <vlc_services_discovery.h> |
30 | | #include <vlc_probe.h> |
31 | | #include <vlc_modules.h> |
32 | | #include "../libvlc.h" |
33 | | |
34 | | typedef struct |
35 | | { |
36 | | char *name; |
37 | | char *longname; |
38 | | int category; |
39 | | } vlc_sd_probe_t; |
40 | | |
41 | | int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name, |
42 | | const char *longname, int category) |
43 | 0 | { |
44 | 0 | vlc_sd_probe_t names = { strdup(name), strdup(longname), category }; |
45 | |
|
46 | 0 | if (unlikely (names.name == NULL || names.longname == NULL |
47 | 0 | || vlc_probe_add (probe, &names, sizeof (names)))) |
48 | 0 | { |
49 | 0 | free (names.name); |
50 | 0 | free (names.longname); |
51 | 0 | return VLC_ENOMEM; |
52 | 0 | } |
53 | 0 | return VLC_PROBE_CONTINUE; |
54 | 0 | } |
55 | | |
56 | | #undef vlc_sd_GetNames |
57 | | |
58 | | /** |
59 | | * Gets the list of available services discovery plugins. |
60 | | */ |
61 | | char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories) |
62 | 0 | { |
63 | 0 | size_t count; |
64 | 0 | vlc_sd_probe_t *tab = vlc_probe (obj, "services probe", &count); |
65 | |
|
66 | 0 | if (count == 0) |
67 | 0 | { |
68 | 0 | free (tab); |
69 | 0 | return NULL; |
70 | 0 | } |
71 | | |
72 | 0 | char **names = vlc_alloc (count + 1, sizeof(char *)); |
73 | 0 | char **longnames = vlc_alloc (count + 1, sizeof(char *)); |
74 | 0 | int *categories = vlc_alloc (count + 1, sizeof(int)); |
75 | |
|
76 | 0 | if (unlikely (names == NULL || longnames == NULL || categories == NULL)) |
77 | 0 | { |
78 | 0 | free(names); |
79 | 0 | free(longnames); |
80 | 0 | free(categories); |
81 | 0 | free(tab); |
82 | 0 | return NULL; |
83 | 0 | } |
84 | 0 | for( size_t i = 0; i < count; i++ ) |
85 | 0 | { |
86 | 0 | names[i] = tab[i].name; |
87 | 0 | longnames[i] = tab[i].longname; |
88 | 0 | categories[i] = tab[i].category; |
89 | 0 | } |
90 | 0 | free (tab); |
91 | 0 | names[count] = longnames[count] = NULL; |
92 | 0 | categories[count] = 0; |
93 | 0 | *pppsz_longnames = longnames; |
94 | 0 | if( pp_categories ) *pp_categories = categories; |
95 | 0 | else free( categories ); |
96 | 0 | return names; |
97 | 0 | } |
98 | | |
99 | | /* |
100 | | * Services discovery |
101 | | * Basically you just listen to Service discovery event through the |
102 | | * sd's event manager. |
103 | | * That's how the playlist gets Service Discovery information |
104 | | */ |
105 | | |
106 | | #undef vlc_sd_Create |
107 | | services_discovery_t *vlc_sd_Create(vlc_object_t *parent, const char *cfg, |
108 | | const struct services_discovery_owner_t *restrict owner) |
109 | 0 | { |
110 | 0 | services_discovery_t *sd = vlc_custom_create(parent, sizeof (*sd), |
111 | 0 | "services discovery"); |
112 | 0 | if (unlikely(sd == NULL)) |
113 | 0 | return NULL; |
114 | | |
115 | 0 | free(config_ChainCreate(&sd->psz_name, &sd->p_cfg, cfg)); |
116 | 0 | sd->description = NULL; |
117 | 0 | sd->owner = *owner; |
118 | |
|
119 | 0 | sd->p_module = module_need(sd, "services_discovery", |
120 | 0 | sd->psz_name, true); |
121 | 0 | if (sd->p_module == NULL) |
122 | 0 | { |
123 | 0 | msg_Err(sd, "no suitable services discovery module"); |
124 | 0 | vlc_sd_Destroy(sd); |
125 | 0 | sd = NULL; |
126 | 0 | } |
127 | |
|
128 | 0 | return sd; |
129 | 0 | } |
130 | | |
131 | | void vlc_sd_Destroy(services_discovery_t *sd) |
132 | 0 | { |
133 | 0 | if (sd->p_module != NULL) |
134 | 0 | module_unneed(sd, sd->p_module); |
135 | 0 | config_ChainDestroy(sd->p_cfg); |
136 | 0 | free(sd->psz_name); |
137 | 0 | vlc_object_delete(sd); |
138 | 0 | } |