Skip to content

Commit

Permalink
Merge pull request #427 from analogdevicesinc/rgetz-fix-name-space-co…
Browse files Browse the repository at this point in the history
…llisions

fix #425: add IIO_ prefix to INFO, WARN, DEBUG and ERROR macros
  • Loading branch information
dNechita authored Apr 8, 2020
2 parents 2099078 + 8188c16 commit 135c189
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 221 deletions.
24 changes: 12 additions & 12 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,50 @@

#if (LOG_LEVEL >= Debug_L)
# ifdef COLOR_DEBUG
# define DEBUG(str, ...) \
# define IIO_DEBUG(str, ...) \
fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__)
# else
# define DEBUG(...) \
# define IIO_DEBUG(...) \
fprintf(stdout, "DEBUG: " __VA_ARGS__)
# endif
#else
#define DEBUG(...) do { } while (0)
#define IIO_DEBUG(...) do { } while (0)
#endif

#if (LOG_LEVEL >= Info_L)
# ifdef COLOR_INFO
# define INFO(str, ...) \
# define IIO_INFO(str, ...) \
fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__)
# else
# define INFO(...) \
# define IIO_INFO(...) \
fprintf(stdout, __VA_ARGS__)
# endif
#else
#define INFO(...) do { } while (0)
#define IIO_INFO(...) do { } while (0)
#endif

#if (LOG_LEVEL >= Warning_L)
# ifdef COLOR_WARNING
# define WARNING(str, ...) \
# define IIO_WARNING(str, ...) \
fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__)
# else
# define WARNING(...) \
# define IIO_WARNING(...) \
fprintf(stderr, "WARNING: " __VA_ARGS__)
# endif
#else
#define WARNING(...) do { } while (0)
#define IIO_WARNING(...) do { } while (0)
#endif

#if (LOG_LEVEL >= Error_L)
# ifdef COLOR_ERROR
# define ERROR(str, ...) \
# define IIO_ERROR(str, ...) \
fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__)
# else
# define ERROR(...) \
# define IIO_ERROR(...) \
fprintf(stderr, "ERROR: " __VA_ARGS__)
# endif
#else
#define ERROR(...) do { } while (0)
#define IIO_ERROR(...) do { } while (0)
#endif

#endif
16 changes: 8 additions & 8 deletions dns_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void dnssd_remove_node(struct dns_sd_discovery_data **ddata, int n)
ldata = ndata;
i++;
}
ERROR("dnssd_remove_node call when %i exceeds list length (%i)\n", n, i);
IIO_ERROR("dnssd_remove_node call when %i exceeds list length (%i)\n", n, i);
}

*ddata = d;
Expand All @@ -78,7 +78,7 @@ static int dnssd_fill_context_info(struct iio_context_info *info,

ctx = network_create_context(addr_str);
if (!ctx) {
ERROR("No context at %s\n", addr_str);
IIO_ERROR("No context at %s\n", addr_str);
return -ENOMEM;
}

Expand Down Expand Up @@ -173,20 +173,20 @@ void port_knock_discovery_data(struct dns_sd_discovery_data **ddata)

/* getaddrinfo() returns a list of address structures */
if (ret) {
DEBUG("Unable to find host ('%s'): %s\n",
IIO_DEBUG("Unable to find host ('%s'): %s\n",
ndata->hostname,
gai_strerror(ret));
} else {
for (rp = res; rp != NULL; rp = rp->ai_next) {
fd = create_socket(rp, DEFAULT_TIMEOUT_MS);
if (fd < 0) {
DEBUG("Unable to open %s%s socket ('%s:%d' %s)\n",
IIO_DEBUG("Unable to open %s%s socket ('%s:%d' %s)\n",
rp->ai_family == AF_INET ? "ipv4" : "",
rp->ai_family == AF_INET6? "ipv6" : "",
ndata->hostname, ndata->port, ndata->addr_str);
} else {
close(fd);
DEBUG("Something %s%s at '%s:%d' %s)\n",
IIO_DEBUG("Something %s%s at '%s:%d' %s)\n",
rp->ai_family == AF_INET ? "ipv4" : "",
rp->ai_family == AF_INET6? "ipv6" : "",
ndata->hostname, ndata->port, ndata->addr_str);
Expand Down Expand Up @@ -226,7 +226,7 @@ void remove_dup_discovery_data(struct dns_sd_discovery_data **ddata)
for (j = i + 1, mdata = ndata->next; mdata->next != NULL; mdata = mdata->next) {
if (!strcmp(mdata->hostname, ndata->hostname) &&
!strcmp(mdata->addr_str, ndata->addr_str)){
DEBUG("Removing duplicate in list: '%s'\n",
IIO_DEBUG("Removing duplicate in list: '%s'\n",
ndata->hostname);
dnssd_remove_node(&d, j);
}
Expand Down Expand Up @@ -260,15 +260,15 @@ int dnssd_context_scan(struct iio_scan_backend_context *ctx,
for (ndata = ddata; ndata->next != NULL; ndata = ndata->next) {
info = iio_scan_result_add(scan_result, 1);
if (!info) {
ERROR("Out of memory when adding new scan result\n");
IIO_ERROR("Out of memory when adding new scan result\n");
ret = -ENOMEM;
break;
}

ret = dnssd_fill_context_info(*info,
ndata->hostname, ndata->addr_str,ndata->port);
if (ret < 0) {
DEBUG("Failed to add %s (%s) err: %d\n", ndata->hostname, ndata->addr_str, ret);
IIO_DEBUG("Failed to add %s (%s) err: %d\n", ndata->hostname, ndata->addr_str, ret);
break;
}
}
Expand Down
30 changes: 15 additions & 15 deletions dns_sd_avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ static void __avahi_resolver_cb(AvahiServiceResolver *resolver,
struct dns_sd_discovery_data *ddata = (struct dns_sd_discovery_data *) d;

if (!resolver) {
ERROR("Fatal Error in Avahi Resolver\n");
IIO_ERROR("Fatal Error in Avahi Resolver\n");
return;
}

switch(event) {
case AVAHI_RESOLVER_FAILURE:
ERROR("Avahi Resolver: Failed resolve service '%s' "
IIO_ERROR("Avahi Resolver: Failed resolve service '%s' "
"of type '%s' in domain '%s': %s\n",
name, type, domain,
avahi_strerror(
Expand Down Expand Up @@ -114,13 +114,13 @@ static void __avahi_resolver_cb(AvahiServiceResolver *resolver,
ddata->next->poll = ddata->poll;
ddata->next->lock = ddata->lock;
} else {
ERROR("Avahi Resolver : memory failure\n");
IIO_ERROR("Avahi Resolver : memory failure\n");
}
iio_mutex_unlock(ddata->lock);

DEBUG("Avahi Resolver : service '%s' of type '%s' in domain '%s':\n",
IIO_DEBUG("Avahi Resolver : service '%s' of type '%s' in domain '%s':\n",
name, type, domain);
DEBUG("\t\t%s:%u (%s)\n", host_name, port, ddata->addr_str);
IIO_DEBUG("\t\t%s:%u (%s)\n", host_name, port, ddata->addr_str);

break;
}
Expand All @@ -139,25 +139,25 @@ static void __avahi_browser_cb(AvahiServiceBrowser *browser,
int i;

if (!browser) {
ERROR("Fatal Error in Avahi Browser\n");
IIO_ERROR("Fatal Error in Avahi Browser\n");
return;
}

switch (event) {
case AVAHI_BROWSER_REMOVE:
DEBUG("Avahi Browser : REMOVE : "
IIO_DEBUG("Avahi Browser : REMOVE : "
"service '%s' of type '%s' in domain '%s'\n",
name, type, domain);
break;
case AVAHI_BROWSER_NEW:
DEBUG("Avahi Browser : NEW: "
IIO_DEBUG("Avahi Browser : NEW: "
"service '%s' of type '%s' in domain '%s'\n",
name, type, domain);
if(!avahi_service_resolver_new(client, iface,
proto, name, type, domain,
AVAHI_PROTO_UNSPEC, 0,
__avahi_resolver_cb, d)) {
ERROR("Failed to resolve service '%s\n", name);
IIO_ERROR("Failed to resolve service '%s\n", name);
} else {
iio_mutex_lock(ddata->lock);
ddata->found++;
Expand All @@ -167,7 +167,7 @@ static void __avahi_browser_cb(AvahiServiceBrowser *browser,
case AVAHI_BROWSER_ALL_FOR_NOW:
/* Wait for a max of 1 second */
i = 0;
DEBUG("Avahi Browser : ALL_FOR_NOW Browser : %d, Resolved : %d\n",
IIO_DEBUG("Avahi Browser : ALL_FOR_NOW Browser : %d, Resolved : %d\n",
ddata->found, ddata->resolved);
/* 200 * 5ms = wait 1 second */
while ((ddata->found != ddata->resolved) && i <= 200) {
Expand All @@ -180,11 +180,11 @@ static void __avahi_browser_cb(AvahiServiceBrowser *browser,
avahi_simple_poll_quit(ddata->poll);
break;
case AVAHI_BROWSER_FAILURE:
DEBUG("Avahi Browser : FAILURE\n");
IIO_DEBUG("Avahi Browser : FAILURE\n");
avahi_simple_poll_quit(ddata->poll);
break;
case AVAHI_BROWSER_CACHE_EXHAUSTED:
DEBUG("Avahi Browser : CACHE_EXHAUSTED\n");
IIO_DEBUG("Avahi Browser : CACHE_EXHAUSTED\n");
break;
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
client = avahi_client_new(avahi_simple_poll_get(d->poll),
0, NULL, NULL, &ret);
if (!client) {
ERROR("Unable to create Avahi DNS-SD client :%s\n",
IIO_ERROR("Unable to create Avahi DNS-SD client :%s\n",
avahi_strerror(ret));
goto err_free_poll;
}
Expand All @@ -230,12 +230,12 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
"_iio._tcp", NULL, 0, __avahi_browser_cb, d);
if (!browser) {
ret = avahi_client_errno(client);
ERROR("Unable to create Avahi DNS-SD browser: %s\n",
IIO_ERROR("Unable to create Avahi DNS-SD browser: %s\n",
avahi_strerror(ret));
goto err_free_client;
}

DEBUG("Trying to discover host\n");
IIO_DEBUG("Trying to discover host\n");
avahi_simple_poll_loop(d->poll);

if (d->resolved) {
Expand Down
Loading

0 comments on commit 135c189

Please sign in to comment.