Coverage Report

Created: 2025-12-14 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/include/vlc_services_discovery.h
Line
Count
Source
1
/*****************************************************************************
2
 * vlc_services_discovery.h : Services Discover functions
3
 *****************************************************************************
4
 * Copyright (C) 1999-2004 VLC authors and VideoLAN
5
 *
6
 * Authors: Pierre d'Herbemont <pdherbemont # 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
23
#ifndef VLC_SERVICES_DISCOVERY_H_
24
#define VLC_SERVICES_DISCOVERY_H_
25
26
#include <vlc_input.h>
27
#include <vlc_probe.h>
28
29
/**
30
 * \file
31
 * This file lists functions and structures for service discovery (SD) in vlc
32
 */
33
34
# ifdef __cplusplus
35
extern "C" {
36
# endif
37
38
/**
39
 * @{
40
 */
41
42
struct services_discovery_callbacks
43
{
44
    void (*item_added)(struct services_discovery_t *sd, input_item_t *parent,
45
                       input_item_t *item);
46
    void (*item_removed)(struct services_discovery_t *sd, input_item_t *item);
47
};
48
49
struct services_discovery_owner_t
50
{
51
    const struct services_discovery_callbacks *cbs;
52
    void *sys; /**< Private data for the owner callbacks */
53
};
54
55
/**
56
 * Main service discovery structure to build a SD module
57
 */
58
struct services_discovery_t
59
{
60
    struct vlc_object_t obj;
61
    module_t *          p_module;             /**< Loaded module */
62
63
    char *psz_name;                           /**< Main name of the SD */
64
    config_chain_t *p_cfg;                    /**< Configuration for the SD */
65
66
    const char *description; /**< Human-readable name */
67
68
    /** Control function
69
     * \see services_discovery_command_e
70
     */
71
    int ( *pf_control ) ( services_discovery_t *, int, va_list );
72
73
    void *p_sys;                              /**< Custom private data */
74
75
    struct services_discovery_owner_t owner; /**< Owner callbacks */
76
};
77
78
/**
79
 * Service discovery categories
80
 * \see vlc_sd_probe_Add
81
 */
82
enum services_discovery_category_e
83
{
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 */
88
};
89
90
/**
91
 * Service discovery control commands
92
 */
93
enum services_discovery_command_e
94
{
95
    SD_CMD_SEARCH = 1,          /**< arg1 = query */
96
    SD_CMD_DESCRIPTOR           /**< arg1 = services_discovery_descriptor_t* */
97
};
98
99
/**
100
 * Service discovery capabilities
101
 */
102
enum services_discovery_capability_e
103
{
104
    SD_CAP_SEARCH = 1           /**< One can search in the SD */
105
};
106
107
/**
108
 * Service discovery descriptor
109
 * \see services_discovery_command_e
110
 */
111
typedef struct
112
{
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;
118
119
120
/***********************************************************************
121
 * Service Discovery
122
 ***********************************************************************/
123
124
/**
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 otherwise
130
 */
131
static inline int vlc_sd_control( services_discovery_t *p_sd, int i_control, va_list args )
132
0
{
133
0
    if( p_sd->pf_control )
134
0
        return p_sd->pf_control( p_sd, i_control, args );
135
0
    else
136
0
        return VLC_EGENERIC;
137
0
}
Unexecuted instantiation: sap.c:vlc_sd_control
Unexecuted instantiation: libvlc.c:vlc_sd_control
Unexecuted instantiation: media_source.c:vlc_sd_control
Unexecuted instantiation: media_tree.c:vlc_sd_control
Unexecuted instantiation: services_discovery.c:vlc_sd_control
138
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
0
        vlc_sd_GetNames(VLC_OBJECT(obj), pln, pcat)
144
145
/**
146
 * Creates a services discoverer.
147
 */
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
0
        vlc_sd_Create( VLC_OBJECT( obj ), a, b )
153
154
VLC_API void vlc_sd_Destroy( services_discovery_t * );
155
156
/**
157
 * Added top-level service callback.
158
 *
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.
162
 */
163
static inline void services_discovery_AddItem(services_discovery_t *sd,
164
                                              input_item_t *item)
165
0
{
166
0
    sd->owner.cbs->item_added(sd, NULL, item);
167
0
}
Unexecuted instantiation: sap.c:services_discovery_AddItem
Unexecuted instantiation: libvlc.c:services_discovery_AddItem
Unexecuted instantiation: media_source.c:services_discovery_AddItem
Unexecuted instantiation: media_tree.c:services_discovery_AddItem
Unexecuted instantiation: services_discovery.c:services_discovery_AddItem
168
169
/**
170
 * Added service callback.
171
 *
172
 * A services discovery module invokes this function when it "discovers" a new
173
 * service, i.e. a new input item.
174
 *
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.
177
 *
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.
182
 *
183
 * @param sd the service discovery instance exposing the item
184
 * @param parent the parent to attach the item to
185
 * @param item input item to add
186
 */
187
static inline void services_discovery_AddSubItem(services_discovery_t *sd,
188
                                                 input_item_t *parent,
189
                                                 input_item_t *item)
190
0
{
191
0
    sd->owner.cbs->item_added(sd, parent, item);
192
0
}
Unexecuted instantiation: sap.c:services_discovery_AddSubItem
Unexecuted instantiation: libvlc.c:services_discovery_AddSubItem
Unexecuted instantiation: media_source.c:services_discovery_AddSubItem
Unexecuted instantiation: media_tree.c:services_discovery_AddSubItem
Unexecuted instantiation: services_discovery.c:services_discovery_AddSubItem
193
194
/**
195
 * Removed service callback.
196
 *
197
 * A services discovery module invokes this function when it senses that a
198
 * service is no longer available.
199
 */
200
static inline void services_discovery_RemoveItem(services_discovery_t *sd,
201
                                                 input_item_t *item)
202
0
{
203
0
    sd->owner.cbs->item_removed(sd, item);
204
0
}
Unexecuted instantiation: sap.c:services_discovery_RemoveItem
Unexecuted instantiation: libvlc.c:services_discovery_RemoveItem
Unexecuted instantiation: media_source.c:services_discovery_RemoveItem
Unexecuted instantiation: media_tree.c:services_discovery_RemoveItem
Unexecuted instantiation: services_discovery.c:services_discovery_RemoveItem
205
206
/* SD probing */
207
208
VLC_API int vlc_sd_probe_Add(vlc_probe_t *, const char *, const char *, int category);
209
210
#define VLC_SD_PROBE_SUBMODULE \
211
54
    add_submodule() \
212
54
        set_capability( "services probe", 100 ) \
213
54
        set_callback( vlc_sd_probe_Open )
214
215
#define VLC_SD_PROBE_HELPER(name, longname, cat) \
216
0
static int vlc_sd_probe_Open (vlc_object_t *obj) \
217
0
{ \
218
0
    return vlc_sd_probe_Add ((struct vlc_probe_t *)obj, name, \
219
0
                             longname, cat); \
220
0
}
221
222
/** @} */
223
# ifdef __cplusplus
224
}
225
# endif
226
227
#endif