OpenOCD
discovery.c
Go to the documentation of this file.
1 /*
2  * This file is part of the libjaylink project.
3  *
4  * Copyright (C) 2014-2016 Marc Schink <jaylink-dev@marcschink.de>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 #include <stdlib.h>
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include "libjaylink.h"
26 #include "libjaylink-internal.h"
27 
34 static void clear_discovery_list(struct jaylink_context *ctx)
35 {
36  struct list *item;
37  struct list *tmp;
38  struct jaylink_device *dev;
39 
40  item = ctx->discovered_devs;
41 
42  while (item) {
43  dev = (struct jaylink_device *)item->data;
45 
46  tmp = item;
47  item = item->next;
48  free(tmp);
49  }
50 
51  ctx->discovered_devs = NULL;
52 }
53 
73  uint32_t ifaces)
74 {
75  int ret;
76 
77  if (!ctx)
78  return JAYLINK_ERR_ARG;
79 
80  if (!ifaces)
82 
84 
85 #ifdef HAVE_LIBUSB
86  if (ifaces & JAYLINK_HIF_USB) {
87  ret = discovery_usb_scan(ctx);
88 
89  if (ret != JAYLINK_OK) {
90  log_err(ctx, "USB device discovery failed.");
91  return ret;
92  }
93  }
94 #endif
95 
96  if (ifaces & JAYLINK_HIF_TCP) {
97  ret = discovery_tcp_scan(ctx);
98 
99  if (ret != JAYLINK_OK) {
100  log_err(ctx, "TCP/IP device discovery failed.");
101  return ret;
102  }
103  }
104 
105  return JAYLINK_OK;
106 }
static void clear_discovery_list(struct jaylink_context *ctx)
Definition: discovery.c:34
JAYLINK_PRIV int discovery_usb_scan(struct jaylink_context *ctx)
JAYLINK_API int jaylink_discovery_scan(struct jaylink_context *ctx, uint32_t ifaces)
Scan for devices.
Definition: discovery.c:72
JAYLINK_API void jaylink_unref_device(struct jaylink_device *dev)
Decrement the reference count of a device.
Definition: device.c:536
#define NULL
Definition: usb.h:27
struct list * next