playlist demuxer: remove tabs
[vlc.git] / include / vlc_services_discovery.h
blob17114f7c8ffdecfe45e8897401d872d0b6c2d3ee
1 /*****************************************************************************
2 * vlc_services_discovery.h : Services Discover functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
6 * Authors: Pierre d'Herbemont <pdherbemont # 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 *****************************************************************************/
23 #ifndef VLC_SERVICES_DISCOVERY_H_
24 #define VLC_SERVICES_DISCOVERY_H_
26 #include <vlc_input.h>
27 #include <vlc_probe.h>
29 /**
30 * \file
31 * This file lists functions and structures for service discovery (SD) in vlc
34 # ifdef __cplusplus
35 extern "C" {
36 # endif
38 /**
39 * @{
42 struct services_discovery_callbacks
44 void (*item_added)(struct services_discovery_t *sd, input_item_t *parent,
45 input_item_t *item, const char *category);
46 void (*item_removed)(struct services_discovery_t *sd, input_item_t *item);
49 struct services_discovery_owner_t
51 const struct services_discovery_callbacks *cbs;
52 void *sys; /**< Private data for the owner callbacks */
55 /**
56 * Main service discovery structure to build a SD module
58 struct services_discovery_t
60 struct vlc_common_members obj;
61 module_t * p_module; /**< Loaded module */
63 char *psz_name; /**< Main name of the SD */
64 config_chain_t *p_cfg; /**< Configuration for the SD */
66 const char *description; /**< Human-readable name */
68 /** Control function
69 * \see services_discovery_command_e
71 int ( *pf_control ) ( services_discovery_t *, int, va_list );
73 void *p_sys; /**< Custom private data */
75 struct services_discovery_owner_t owner; /**< Owner callbacks */
78 /**
79 * Service discovery categories
80 * \see vlc_sd_probe_Add
82 enum services_discovery_category_e
84 SD_CAT_DEVICES = 1, /**< Devices, like portable music players */
85 SD_CAT_LAN, /**< LAN/WAN services, like Upnp or SAP */
86 SD_CAT_INTERNET, /**< Internet or Website channels services */
87 SD_CAT_MYCOMPUTER /**< Computer services, like Discs or Apps */
90 /**
91 * Service discovery control commands
93 enum services_discovery_command_e
95 SD_CMD_SEARCH = 1, /**< arg1 = query */
96 SD_CMD_DESCRIPTOR /**< arg1 = services_discovery_descriptor_t* */
99 /**
100 * Service discovery capabilities
102 enum services_discovery_capability_e
104 SD_CAP_SEARCH = 1 /**< One can search in the SD */
108 * Service discovery descriptor
109 * \see services_discovery_command_e
111 typedef struct
113 char *psz_short_desc; /**< The short description, human-readable */
114 char *psz_icon_url; /**< URL to the icon that represents it */
115 char *psz_url; /**< URL for the service */
116 int i_capabilities; /**< \see services_discovery_capability_e */
117 } services_discovery_descriptor_t;
120 /***********************************************************************
121 * Service Discovery
122 ***********************************************************************/
125 * Ask for a research in the SD
126 * @param p_sd: the Service Discovery
127 * @param i_control: the command to issue
128 * @param args: the argument list
129 * @return VLC_SUCCESS in case of success, the error code overwise
131 static inline int vlc_sd_control( services_discovery_t *p_sd, int i_control, va_list args )
133 if( p_sd->pf_control )
134 return p_sd->pf_control( p_sd, i_control, args );
135 else
136 return VLC_EGENERIC;
139 /* Get the services discovery modules names to use in Create(), in a null
140 * terminated string array. Array and string must be freed after use. */
141 VLC_API char ** vlc_sd_GetNames( vlc_object_t *, char ***, int ** ) VLC_USED;
142 #define vlc_sd_GetNames(obj, pln, pcat ) \
143 vlc_sd_GetNames(VLC_OBJECT(obj), pln, pcat)
146 * Creates a services discoverer.
148 VLC_API services_discovery_t *vlc_sd_Create(vlc_object_t *parent,
149 const char *chain, const struct services_discovery_owner_t *owner)
150 VLC_USED;
151 #define vlc_sd_Create( obj, a, b ) \
152 vlc_sd_Create( VLC_OBJECT( obj ), a, b )
154 VLC_API void vlc_sd_Destroy( services_discovery_t * );
157 * Added top-level service callback.
159 * This is a convenience wrapper for services_discovery_AddSubItem().
160 * It covers the most comomn case wherby the added item is a top-level service,
161 * i.e. it has no parent node.
163 static inline void services_discovery_AddItem(services_discovery_t *sd,
164 input_item_t *item)
166 sd->owner.cbs->item_added(sd, NULL, item, NULL);
170 * Added service callback.
172 * A services discovery module invokes this function when it "discovers" a new
173 * service, i.e. a new input item.
175 * @note This callback does not take ownership of the input item; it might
176 * however (and most probably will) add one of more references to the item.
178 * The caller is responsible for releasing its own reference(s) eventually.
179 * Keeping a reference is necessary to call services_discovery_RemoveItem() or
180 * to alter the item later. However, if the caller will never remove nor alter
181 * the item, it can drop its reference(s) immediately.
183 * @param sd services discoverer / services discovery module instance
184 * @param item input item to add
186 static inline void services_discovery_AddSubItem(services_discovery_t *sd,
187 input_item_t *parent,
188 input_item_t *item)
190 sd->owner.cbs->item_added(sd, parent, item, NULL);
194 * Added service backward compatibility callback.
196 * @param category Optional name of a group that the item belongs in
197 * (for backward compatibility with legacy modules)
199 VLC_DEPRECATED
200 static inline void services_discovery_AddItemCat(services_discovery_t *sd,
201 input_item_t *item,
202 const char *category)
204 sd->owner.cbs->item_added(sd, NULL, item, category);
208 * Removed service callback.
210 * A services discovery module invokes this function when it senses that a
211 * service is no longer available.
213 static inline void services_discovery_RemoveItem(services_discovery_t *sd,
214 input_item_t *item)
216 sd->owner.cbs->item_removed(sd, item);
219 /* SD probing */
221 VLC_API int vlc_sd_probe_Add(vlc_probe_t *, const char *, const char *, int category);
223 #define VLC_SD_PROBE_SUBMODULE \
224 add_submodule() \
225 set_capability( "services probe", 100 ) \
226 set_callbacks( vlc_sd_probe_Open, NULL )
228 #define VLC_SD_PROBE_HELPER(name, longname, cat) \
229 static int vlc_sd_probe_Open (vlc_object_t *obj) \
231 return vlc_sd_probe_Add ((struct vlc_probe_t *)obj, name, \
232 longname, cat); \
235 /** @} */
236 # ifdef __cplusplus
238 # endif
240 #endif