mux: extradata: parametrize extradata type
[vlc.git] / include / vlc_services_discovery.h
blobe117a1c0a527c64c93adb42022c390c31b85ec23
1 /*****************************************************************************
2 * vlc_services_discovery.h : Services Discover functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_SERVICES_DISCOVERY_H_
25 #define VLC_SERVICES_DISCOVERY_H_
27 #include <vlc_input.h>
28 #include <vlc_probe.h>
30 /**
31 * \file
32 * This file lists functions and structures for service discovery (SD) in vlc
35 # ifdef __cplusplus
36 extern "C" {
37 # endif
39 /**
40 * @{
43 struct services_discovery_callbacks
45 void (*item_added)(struct services_discovery_t *sd, input_item_t *parent,
46 input_item_t *item, const char *category);
47 void (*item_removed)(struct services_discovery_t *sd, input_item_t *item);
50 struct services_discovery_owner_t
52 const struct services_discovery_callbacks *cbs;
53 void *sys; /**< Private data for the owner callbacks */
56 /**
57 * Main service discovery structure to build a SD module
59 struct services_discovery_t
61 struct vlc_common_members obj;
62 module_t * p_module; /**< Loaded module */
64 char *psz_name; /**< Main name of the SD */
65 config_chain_t *p_cfg; /**< Configuration for the SD */
67 const char *description; /**< Human-readable name */
69 /** Control function
70 * \see services_discovery_command_e
72 int ( *pf_control ) ( services_discovery_t *, int, va_list );
74 void *p_sys; /**< Custom private data */
76 struct services_discovery_owner_t owner; /**< Owner callbacks */
79 /**
80 * Service discovery categories
81 * \see vlc_sd_probe_Add
83 enum services_discovery_category_e
85 SD_CAT_DEVICES = 1, /**< Devices, like portable music players */
86 SD_CAT_LAN, /**< LAN/WAN services, like Upnp or SAP */
87 SD_CAT_INTERNET, /**< Internet or Website channels services */
88 SD_CAT_MYCOMPUTER /**< Computer services, like Discs or Apps */
91 /**
92 * Service discovery control commands
94 enum services_discovery_command_e
96 SD_CMD_SEARCH = 1, /**< arg1 = query */
97 SD_CMD_DESCRIPTOR /**< arg1 = services_discovery_descriptor_t* */
101 * Service discovery capabilities
103 enum services_discovery_capability_e
105 SD_CAP_SEARCH = 1 /**< One can search in the SD */
109 * Service discovery descriptor
110 * \see services_discovery_command_e
112 typedef struct
114 char *psz_short_desc; /**< The short description, human-readable */
115 char *psz_icon_url; /**< URL to the icon that represents it */
116 char *psz_url; /**< URL for the service */
117 int i_capabilities; /**< \see services_discovery_capability_e */
118 } services_discovery_descriptor_t;
121 /***********************************************************************
122 * Service Discovery
123 ***********************************************************************/
126 * Ask for a research in the SD
127 * @param p_sd: the Service Discovery
128 * @param i_control: the command to issue
129 * @param args: the argument list
130 * @return VLC_SUCCESS in case of success, the error code overwise
132 static inline int vlc_sd_control( services_discovery_t *p_sd, int i_control, va_list args )
134 if( p_sd->pf_control )
135 return p_sd->pf_control( p_sd, i_control, args );
136 else
137 return VLC_EGENERIC;
140 /* Get the services discovery modules names to use in Create(), in a null
141 * terminated string array. Array and string must be freed after use. */
142 VLC_API char ** vlc_sd_GetNames( vlc_object_t *, char ***, int ** ) VLC_USED;
143 #define vlc_sd_GetNames(obj, pln, pcat ) \
144 vlc_sd_GetNames(VLC_OBJECT(obj), pln, pcat)
147 * Creates a services discoverer.
149 VLC_API services_discovery_t *vlc_sd_Create(vlc_object_t *parent,
150 const char *chain, const struct services_discovery_owner_t *owner)
151 VLC_USED;
152 #define vlc_sd_Create( obj, a, b ) \
153 vlc_sd_Create( VLC_OBJECT( obj ), a, b )
155 VLC_API void vlc_sd_Destroy( services_discovery_t * );
158 * Added top-level service callback.
160 * This is a convenience wrapper for services_discovery_AddSubItem().
161 * It covers the most comomn case wherby the added item is a top-level service,
162 * i.e. it has no parent node.
164 static inline void services_discovery_AddItem(services_discovery_t *sd,
165 input_item_t *item)
167 sd->owner.cbs->item_added(sd, NULL, item, NULL);
171 * Added service callback.
173 * A services discovery module invokes this function when it "discovers" a new
174 * service, i.e. a new input item.
176 * @note This callback does not take ownership of the input item; it might
177 * however (and most probably will) add one of more references to the item.
179 * The caller is responsible for releasing its own reference(s) eventually.
180 * Keeping a reference is necessary to call services_discovery_RemoveItem() or
181 * to alter the item later. However, if the caller will never remove nor alter
182 * the item, it can drop its reference(s) immediately.
184 * @param sd services discoverer / services discovery module instance
185 * @param item input item to add
187 static inline void services_discovery_AddSubItem(services_discovery_t *sd,
188 input_item_t *parent,
189 input_item_t *item)
191 sd->owner.cbs->item_added(sd, parent, item, NULL);
195 * Added service backward compatibility callback.
197 * @param category Optional name of a group that the item belongs in
198 * (for backward compatibility with legacy modules)
200 VLC_DEPRECATED
201 static inline void services_discovery_AddItemCat(services_discovery_t *sd,
202 input_item_t *item,
203 const char *category)
205 sd->owner.cbs->item_added(sd, NULL, item, category);
209 * Removed service callback.
211 * A services discovery module invokes this function when it senses that a
212 * service is no longer available.
214 static inline void services_discovery_RemoveItem(services_discovery_t *sd,
215 input_item_t *item)
217 sd->owner.cbs->item_removed(sd, item);
220 /* SD probing */
222 VLC_API int vlc_sd_probe_Add(vlc_probe_t *, const char *, const char *, int category);
224 #define VLC_SD_PROBE_SUBMODULE \
225 add_submodule() \
226 set_capability( "services probe", 100 ) \
227 set_callbacks( vlc_sd_probe_Open, NULL )
229 #define VLC_SD_PROBE_HELPER(name, longname, cat) \
230 static int vlc_sd_probe_Open (vlc_object_t *obj) \
232 return vlc_sd_probe_Add ((struct vlc_probe_t *)obj, name, \
233 longname, cat); \
236 /** @} */
237 # ifdef __cplusplus
239 # endif
241 #endif