Make use of JAYLINK_LOG_LEVEL_DEBUG_IO
[libjaylink.git] / libjaylink / discovery.c
blob1ac96e755589e5a08d0c58a43e1ac93cb6c756cb
1 /*
2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2016 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdlib.h>
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include "libjaylink.h"
26 #include "libjaylink-internal.h"
28 /**
29 * @file
31 * Device discovery.
34 static void clear_discovery_list(struct jaylink_context *ctx)
36 struct list *item;
37 struct list *tmp;
38 struct jaylink_device *dev;
40 item = ctx->discovered_devs;
42 while (item) {
43 dev = (struct jaylink_device *)item->data;
44 jaylink_unref_device(dev);
46 tmp = item;
47 item = item->next;
48 free(tmp);
51 ctx->discovered_devs = NULL;
54 /**
55 * Scan for devices.
57 * @param[in,out] ctx libjaylink context.
58 * @param[in] ifaces Host interfaces to scan for devices. Use bitwise OR to
59 * specify multiple interfaces, or 0 to use all available
60 * interfaces. See #jaylink_host_interface for a description
61 * of the interfaces.
63 * @retval JAYLINK_OK Success.
64 * @retval JAYLINK_ERR_ARG Invalid arguments.
65 * @retval JAYLINK_ERR_IO Input/output error.
66 * @retval JAYLINK_ERR Other error conditions.
68 * @see jaylink_get_devices()
70 * @since 0.1.0
72 JAYLINK_API int jaylink_discovery_scan(struct jaylink_context *ctx,
73 uint32_t ifaces)
75 int ret;
77 if (!ctx)
78 return JAYLINK_ERR_ARG;
80 if (!ifaces)
81 ifaces = JAYLINK_HIF_USB | JAYLINK_HIF_TCP;
83 clear_discovery_list(ctx);
85 #ifdef HAVE_LIBUSB
86 if (ifaces & JAYLINK_HIF_USB) {
87 ret = discovery_usb_scan(ctx);
89 if (ret != JAYLINK_OK) {
90 log_err(ctx, "USB device discovery failed.");
91 return ret;
94 #endif
96 if (ifaces & JAYLINK_HIF_TCP) {
97 ret = discovery_tcp_scan(ctx);
99 if (ret != JAYLINK_OK) {
100 log_err(ctx, "TCP/IP device discovery failed.");
101 return ret;
105 return JAYLINK_OK;