/*
*
*/
-#if ENABLE_TRACE
static void
access_dump_a(access_t *a)
{
tvhtrace("access", "%s", buf);
}
-#else
-static inline void
-access_dump_a(access_t *a)
-{
-}
-#endif
/*
*
a->aa_rights = 0;
}
- access_dump_a(a);
+ if (tvhtrace_enabled())
+ access_dump_a(a);
return a;
}
a->aa_rights = 0;
}
- access_dump_a(a);
+ if (tvhtrace_enabled())
+ access_dump_a(a);
return a;
}
#pragma once
+#include <stdint.h>
+
static inline int
atomic_add(volatile int *ptr, int incr)
{
mpegts_service_t *svc;
channel_t *ch;
int sid, cid, cnum, unk;
-#if ENABLE_TRACE
int type;
-#endif
int save = 0;
int i = 2;
while (i < len) {
sid = ((int)buf[i] << 8) | buf[i+1];
-#if ENABLE_TRACE
type = buf[2];
-#endif
cid = ((int)buf[i+3] << 8) | buf[i+4];
cnum = ((int)buf[i+5] << 8) | buf[i+6];
unk = ((int)buf[i+7] << 8) | buf[i+8];
}
if (epg_flag < 0 || epg_flag == MM_EPG_DISABLE) {
-#if ENABLE_TRACE
- char name[256];
- mpegts_mux_nice_name(mm, name, sizeof(name));
- tvhtrace("epggrab", "epg mux %s is disabled, skipping", name);
-#endif
+ if (tvhtrace_enabled()) {
+ char name[256];
+ mpegts_mux_nice_name(mm, name, sizeof(name));
+ tvhtrace("epggrab", "epg mux %s is disabled, skipping", name);
+ }
goto done;
}
if (kick)
epggrab_ota_kick(64); /* a random number? */
-#if ENABLE_TRACE
- i = r = 0;
- RB_FOREACH(om, &epggrab_ota_all, om_global_link)
- i++;
- TAILQ_FOREACH(om, &epggrab_ota_pending, om_q_link)
- r++;
- tvhtrace("epggrab", "mux stats - all %i pending %i", i, r);
-#endif
+ if (tvhtrace_enabled()) {
+ i = r = 0;
+ RB_FOREACH(om, &epggrab_ota_all, om_global_link)
+ i++;
+ TAILQ_FOREACH(om, &epggrab_ota_pending, om_q_link)
+ r++;
+ tvhtrace("epggrab", "mux stats - all %i pending %i", i, r);
+ }
}
/*
epggrab_ota_svc_link_t *svcl,
const char *op )
{
-#if ENABLE_TRACE
char buf[256];
- mpegts_mux_t *mm = mpegts_mux_find(ota->om_mux_uuid);
- mpegts_service_t *svc = mpegts_service_find_by_uuid(svcl->uuid);
+ mpegts_mux_t *mm;
+ mpegts_service_t *svc;
+
+ if (!tvhtrace_enabled())
+ return;
+
+ mm = mpegts_mux_find(ota->om_mux_uuid);
+ svc = mpegts_service_find_by_uuid(svcl->uuid);
if (mm && svc) {
mpegts_mux_nice_name(mm, buf, sizeof(buf));
tvhtrace("epggrab", "ota %s %s service %s", buf, op, svc->s_nicename);
} else if (tvheadend_running)
tvhtrace("epggrab", "ota %s, problem? (%p %p)", op, mm, svc);
-#endif
}
void
hts_settings_remove("epggrab/otamux/%s", uuid);
return;
}
-#if ENABLE_TRACE
- {
+ if (tvhtrace_enabled()) {
char name[256];
mpegts_mux_nice_name(mm, name, sizeof(name));
tvhtrace("epggrab", "loading config for %s", name);
}
-#endif
ota = calloc(1, sizeof(epggrab_ota_mux_t));
ota->om_mux_uuid = strdup(uuid);
/*
* Dump request
*/
-#if ENABLE_TRACE
static void
dump_request(http_connection_t *hc)
{
tvhtrace("http", "%s %s %s%s", http_ver2str(hc->hc_version),
http_cmd2str(hc->hc_cmd), hc->hc_url, buf);
}
-#else
-static inline void
-dump_request(http_connection_t *hc)
-{
-}
-#endif
/**
* HTTP GET
char *remain;
char *args;
- dump_request(hc);
+ if (tvhtrace_enabled())
+ dump_request(hc);
hp = http_resolve(hc, &remain, &args);
if(hp == NULL) {
http_parse_get_args(hc, hc->hc_post_data);
}
- dump_request(hc);
+ if (tvhtrace_enabled())
+ dump_request(hc);
hp = http_resolve(hc, &remain, &args);
if(hp == NULL) {
switch(hc->hc_version) {
case RTSP_VERSION_1_0:
- dump_request(hc);
+ if (tvhtrace_enabled())
+ dump_request(hc);
if (hc->hc_cseq)
rval = hc->hc_process(hc, spill);
else
body = malloc(body_size);
htsbuf_read(&q, body, body_size);
-#if ENABLE_TRACE
- tvhtrace("httpc", "%04X: sending %s cmd", shortid(hc), http_ver2str(hc->hc_version));
- tvhlog_hexdump("httpc", body, body_size);
-#endif
+ if (tvhtrace_enabled()) {
+ tvhtrace("httpc", "%04X: sending %s cmd", shortid(hc), http_ver2str(hc->hc_version));
+ tvhlog_hexdump("httpc", body, body_size);
+ }
wcmd->wbuf = body;
wcmd->wsize = body_size;
http_client_wcmd_t *wcmd;
int res;
-#if ENABLE_TRACE
- if (hc->hc_data) {
+ if (hc->hc_data && tvhtrace_enabled()) {
tvhtrace("httpc", "%04X: received %s data", shortid(hc), http_ver2str(hc->hc_version));
tvhlog_hexdump("httpc", hc->hc_data, hc->hc_csize);
}
-#endif
if (hc->hc_data_complete) {
res = hc->hc_data_complete(hc);
if (res < 0)
return HTTP_CON_RECEIVING;
return http_client_flush(hc, -errno);
}
-#if ENABLE_TRACE
- if (r > 0) {
+ if (r > 0 && tvhtrace_enabled()) {
tvhtrace("httpc", "%04X: received %s answer", shortid(hc), http_ver2str(hc->hc_version));
tvhlog_hexdump("httpc", buf, r);
}
-#endif
if (hc->hc_in_data) {
res = http_client_data_received(hc, buf, r, 0);
( dvb_bat_id_t *bi, const char *dstr, const uint8_t *ptr, int len )
{
uint16_t sid, lcn, regionid;
-#if ENABLE_TRACE
uint16_t unk;
-#endif
dvb_freesat_svc_t *fs;
int len2;
while (len > 4) {
sid = (ptr[0] << 8) | ptr[1];
-#if ENABLE_TRACE
unk = (ptr[2] << 8) | ptr[3];
-#endif
len2 = ptr[4];
ptr += 5;
len -= 5;
if (len2 > len)
break;
-#if ENABLE_TRACE
tvhtrace(dstr, " sid %04X (%d) uknown %04X (%d)", sid, sid, unk, unk);
-#endif
while (len2 > 3) {
lcn = ((ptr[0] & 0x0f) << 8) | ptr[1];
regionid = (ptr[2] << 8) | ptr[3];
const uint8_t *ptr, int len, mpegts_mux_t *mm )
{
uint16_t sid, lcn, regionid;
-#if ENABLE_TRACE
uint16_t unk, stype;
-#endif
dvb_freesat_region_t *fr;
dvb_freesat_svc_t *fs;
dvb_bat_svc_t *bs;
while (len > 8) {
sid = (ptr[0] << 8) | ptr[1];
lcn = (ptr[5] << 8) | ptr[6];
-#if ENABLE_TRACE
stype = ptr[2];
unk = (ptr[3] << 8) | ptr[4];
-#endif
ptr += 9;
len -= 9;
-#if ENABLE_TRACE
tvhtrace(dstr, " sid %04X (%d) type %02X (%d) lcn %d unknown %04X (%d)",
sid, sid, stype, stype, lcn, unk, unk);
-#endif
TAILQ_FOREACH(fs, &bi->fservices, link)
if (fs->sid == sid && fs->regionid == regionid)
return "UNKNOWN";
}
-#if ENABLE_TRACE
const static char *
ca_pmt_list_mgmt2str(uint8_t v)
{
}
return "UNKNOWN";
}
-#endif
-#if ENABLE_TRACE
const static char *
ca_pmt_cmd_id2str(uint8_t v)
{
}
return "UNKNOWN";
}
-#endif
struct linuxdvb_ca_capmt {
TAILQ_ENTRY(linuxdvb_ca_capmt) lcc_link;
*/
dmc = &lm->lm_tuning;
-#if ENABLE_TRACE
- {
+ if (tvhtrace_enabled()) {
char buf2[256];
dvb_mux_conf_str(&lm->lm_tuning, buf2, sizeof(buf2));
tvhtrace("linuxdvb", "tuner %s tunning to %s (freq %i)", buf1, buf2, freq);
}
-#endif
memset(&p, 0, sizeof(p));
p.frequency = dmc->dmc_fe_freq;
p.inversion = TR(inversion, inv_tbl, INVERSION_AUTO);
/* S2 tuning */
#if DVB_API_VERSION >= 5
-#if ENABLE_TRACE
- int i;
- for (i = 0; i < cmdseq.num; i++)
- tvhtrace("linuxdvb", "S2CMD %02u => %u", cmds[i].cmd, cmds[i].u.data);
-#endif
+ if (tvhtrace_enabled()) {
+ int i;
+ for (i = 0; i < cmdseq.num; i++)
+ tvhtrace("linuxdvb", "S2CMD %02u => %u", cmds[i].cmd, cmds[i].u.data);
+ }
r = ioctl(lfe->lfe_fe_fd, FE_SET_PROPERTY, &cmdseq);
/* v3 tuning */
int i;
va_list ap;
struct dvb_diseqc_master_cmd message;
-#if ENABLE_TRACE
char buf[256];
size_t c = 0;
-#endif
+ int tr = tvhtrace_enabled();
/* Build message */
message.msg_len = len + 3;
va_start(ap, len);
for (i = 0; i < len; i++) {
message.msg[3 + i] = (uint8_t)va_arg(ap, int);
-#if ENABLE_TRACE
- tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[3 + i]);
-#endif
+ if (tr)
+ tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[3 + i]);
}
va_end(ap);
- tvhtrace("diseqc", "sending diseqc (len %d) %02X %02X %02X %s",
- len + 3, framing, addr, cmd, buf);
+ if (tr)
+ tvhtrace("diseqc", "sending diseqc (len %d) %02X %02X %02X %s",
+ len + 3, framing, addr, cmd, buf);
/* Send */
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &message)) {
mm->mm_onid = onid;
mpegts_mux_nice_name(mm, buf, sizeof(buf));
mm->mm_config_save(mm);
- tvhtrace("mpegts", "%s - set onid %04X (%d)", buf, onid, onid);
idnode_notify_changed(&mm->mm_id);
return 1;
}
return 0;
mm->mm_tsid = tsid;
mm->mm_config_save(mm);
-#if ENABLE_TRACE
- char buf[256];
- mpegts_mux_nice_name(mm, buf, sizeof(buf));
- tvhtrace("mpegts", "%s - set tsid %04X (%d)", buf, tsid, tsid);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[256];
+ mpegts_mux_nice_name(mm, buf, sizeof(buf));
+ tvhtrace("mpegts", "%s - set tsid %04X (%d)", buf, tsid, tsid);
+ }
idnode_notify_changed(&mm->mm_id);
return 1;
}
return 0;
tvh_str_update(&mm->mm_crid_authority, defauth);
mm->mm_config_save(mm);
-#if ENABLE_TRACE
- char buf[256];
- mpegts_mux_nice_name(mm, buf, sizeof(buf));
- tvhtrace("mpegts", "%s - set crid authority %s", buf, defauth);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[256];
+ mpegts_mux_nice_name(mm, buf, sizeof(buf));
+ tvhtrace("mpegts", "%s - set crid authority %s", buf, defauth);
+ }
idnode_notify_changed(&mm->mm_id);
return 1;
}
mpegts_mux_remove_subscriber
( mpegts_mux_t *mm, th_subscription_t *s, int reason )
{
-#if ENABLE_TRACE
- char buf[256];
- mpegts_mux_nice_name(mm, buf, sizeof(buf));
- tvhtrace("mpegts", "%s - remove subscriber (reason %i)", buf, reason);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[256];
+ mpegts_mux_nice_name(mm, buf, sizeof(buf));
+ tvhtrace("mpegts", "%s - remove subscriber (reason %i)", buf, reason);
+ }
mm->mm_stop(mm, 0, reason);
}
dmc, NULL, NULL);
if (mm)
mm->mm_config_save((mpegts_mux_t *)mm);
-#if ENABLE_TRACE
- char buf[128];
- dvb_mux_conf_str(dmc, buf, sizeof(buf));
- tvhtrace("scanfile", "mux %p %s added to network %s", mm, buf, ln->mn_network_name);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[128];
+ dvb_mux_conf_str(dmc, buf, sizeof(buf));
+ tvhtrace("scanfile", "mux %p %s added to network %s", mm, buf, ln->mn_network_name);
+ }
} else {
-#if ENABLE_TRACE
- char buf[128];
- dvb_mux_conf_str(dmc, buf, sizeof(buf));
- tvhtrace("scanfile", "mux %p skipped %s in network %s", mm, buf, ln->mn_network_name);
- dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
- tvhtrace("scanfile", "mux %p exists %s in network %s", mm, buf, ln->mn_network_name);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[128];
+ dvb_mux_conf_str(dmc, buf, sizeof(buf));
+ tvhtrace("scanfile", "mux %p skipped %s in network %s", mm, buf, ln->mn_network_name);
+ dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
+ tvhtrace("scanfile", "mux %p exists %s in network %s", mm, buf, ln->mn_network_name);
+ }
}
}
return 0;
}
if (save) {
mm = dvb_mux_create0(ln, onid, tsid, dmc, NULL, NULL);
-#if ENABLE_TRACE
- char buf[128];
- dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
- tvhtrace("mpegts", "mux %p %s onid %i tsid %i added to network %s (autodiscovery)",
- mm, buf, onid, tsid, mm->mm_network->mn_network_name);
-#endif
+ if (tvhtrace_enabled()) {
+ char buf[128];
+ dvb_mux_conf_str(&((dvb_mux_t *)mm)->lm_tuning, buf, sizeof(buf));
+ tvhtrace("mpegts", "mux %p %s onid %i tsid %i added to network %s (autodiscovery)",
+ mm, buf, onid, tsid, mm->mm_network->mn_network_name);
+ }
}
} else if (mm) {
dvb_mux_t *lm = (dvb_mux_t*)mm;
/* accept information only from one origin mux */
if (mm->mm_dmc_origin_expire > dispatch_clock && mm->mm_dmc_origin && mm->mm_dmc_origin != origin)
goto noop;
-#if ENABLE_TRACE
#define COMPARE(x) ({ \
int xr = dmc->x != lm->lm_tuning.x; \
if (xr) { \
" (%li)", (long)dmc->x, (long)lm->lm_tuning.x); \
lm->lm_tuning.x = dmc->x; \
} xr; })
-#else
- #define COMPARE(x) ({ \
- int xr = dmc->x != lm->lm_tuning.x; \
- if (xr) lm->lm_tuning.x = dmc->x; \
- xr; })
- /* note - zero means NONE, one means AUTO */
- #define COMPAREN(x) ({ \
- int xr = dmc->x != 0 && dmc->x != 1 && dmc->x != lm->lm_tuning.x; \
- if (xr) lm->lm_tuning.x = dmc->x; \
- xr; })
-#endif
dvb_mux_conf_t tuning_old;
char buf[128];
tuning_old = lm->lm_tuning;
void
mpegts_table_consistency_check ( mpegts_mux_t *mm )
{
-#if ENABLE_TRACE
- int i, c = 0;
+ int i, c;
mpegts_table_t *mt;
+ if (!tvhtrace_enabled())
+ return;
+
+ c = 0;
+
lock_assert(&mm->mm_tables_lock);
i = mm->mm_num_tables;
tvherror("mpegts", "table: mux %p count inconsistency (num %d, list %d)", mm, i, c);
abort();
}
-#endif
}
static void
if (mt->mt_destroy)
mt->mt_destroy(mt);
free(mt->mt_name);
-#if ENABLE_TRACE
- /* poison */
- memset(mt, 0xa5, sizeof(*mt));
-#endif
+ if (tvhtrace_enabled()) {
+ /* poison */
+ memset(mt, 0xa5, sizeof(*mt));
+ }
free(mt);
}
return;
}
-#if ENABLE_TRACE
- tvhtrace("satip", "received XML description from %s", hc->hc_host);
- tvhlog_hexdump("satip", hc->hc_data, hc->hc_data_size);
-#endif
+ if (tvhtrace_enabled()) {
+ tvhtrace("satip", "received XML description from %s", hc->hc_host);
+ tvhlog_hexdump("satip", hc->hc_data, hc->hc_data_size);
+ }
if (d->myaddr == NULL || d->myaddr[0] == '\0') {
struct sockaddr_storage ip;
}
}
-#if ENABLE_TRACE
- for(i = 0; i < ss->ss_num_components; i++) {
- ssc = &ss->ss_components[i];
- tvhtrace("parser", "stream %d %s%s%s (PID %i) complete time %"PRId64"%s",
- ssc->ssc_index, streaming_component_type2txt(ssc->ssc_type),
- ssc->ssc_lang[0] ? " " : "", ssc->ssc_lang, ssc->ssc_pid,
- gh_queue_delay(gh, ssc->ssc_index),
- ssc->ssc_disabled ? " disabled" : "");
+ if (tvhtrace_enabled()) {
+ for(i = 0; i < ss->ss_num_components; i++) {
+ ssc = &ss->ss_components[i];
+ tvhtrace("parser", "stream %d %s%s%s (PID %i) complete time %"PRId64"%s",
+ ssc->ssc_index, streaming_component_type2txt(ssc->ssc_type),
+ ssc->ssc_lang[0] ? " " : "", ssc->ssc_lang, ssc->ssc_pid,
+ gh_queue_delay(gh, ssc->ssc_index),
+ ssc->ssc_disabled ? " disabled" : "");
+ }
}
-#endif
return 1;
}
if (satips_upnp_discovery == NULL || satip_server_rtsp_port <= 0)
return;
-#if ENABLE_TRACE
- tcp_get_str_from_ip((struct sockaddr *)dst, buf, sizeof(buf));
- tvhtrace("satips", "sending discover reply to %s:%d%s%s",
- buf, IP_PORT(*dst), deviceid ? " device: " : "", deviceid ?: "");
-#endif
+ if (tvhtrace_enabled()) {
+ tcp_get_str_from_ip((struct sockaddr *)dst, buf, sizeof(buf));
+ tvhtrace("satips", "sending discover reply to %s:%d%s%s",
+ buf, IP_PORT(*dst), deviceid ? " device: " : "", deviceid ?: "");
+ }
snprintf(buf, sizeof(buf), MSG, UPNP_MAX_AGE,
http_server_ip, http_server_port, tvheadend_version,
if (!conn->multicast && strcmp(argv[0], http_server_ip))
return;
-#if ENABLE_TRACE
- tcp_get_str_from_ip((struct sockaddr *)storage, buf2, sizeof(buf2));
- tvhtrace("satips", "received %s M-SEARCH from %s:%d",
- conn->multicast ? "multicast" : "unicast",
- buf2, ntohs(IP_PORT(*storage)));
-#endif
+ if (tvhtrace_enabled()) {
+ tcp_get_str_from_ip((struct sockaddr *)storage, buf2, sizeof(buf2));
+ tvhtrace("satips", "received %s M-SEARCH from %s:%d",
+ conn->multicast ? "multicast" : "unicast",
+ buf2, ntohs(IP_PORT(*storage)));
+ }
/* Check for deviceid collision */
if (!conn->multicast) {
s = subscription_create(prch, weight, name, flags, subscription_input,
hostname, username, client);
-#if ENABLE_TRACE
- const char *pro_name = prch->prch_pro ? (prch->prch_pro->pro_name ?: "") : "<none>";
- if (ch)
- tvhtrace("subscription", "%04X: creating subscription for %s weight %d using profile %s",
- shortid(s), channel_get_name(ch), weight, pro_name);
- else
- tvhtrace("subscription", "%04X: creating subscription for service %s weight %d using profile %s",
- shortid(s), service->s_nicename, weight, pro_name);
-#endif
+ if (tvhtrace_enabled()) {
+ const char *pro_name = prch->prch_pro ? (prch->prch_pro->pro_name ?: "") : "<none>";
+ if (ch)
+ tvhtrace("subscription", "%04X: creating subscription for %s weight %d using profile %s",
+ shortid(s), channel_get_name(ch), weight, pro_name);
+ else
+ tvhtrace("subscription", "%04X: creating subscription for service %s weight %d using profile %s",
+ shortid(s), service->s_nicename, weight, pro_name);
+ }
s->ths_channel = ch;
s->ths_service = service;
s->ths_source = ti;
static void timeshift_reaper_remove ( timeshift_file_t *tsf )
{
-#if ENABLE_TRACE
- if (tsf->path)
- tvhtrace("timeshift", "queue file for removal %s", tsf->path);
- else
- tvhtrace("timeshift", "queue file for removal - RAM segment time %li", (long)tsf->time);
-#endif
+ if (tvhtrace_enabled()) {
+ if (tsf->path)
+ tvhtrace("timeshift", "queue file for removal %s", tsf->path);
+ else
+ tvhtrace("timeshift", "queue file for removal - RAM segment time %li", (long)tsf->time);
+ }
pthread_mutex_lock(×hift_reaper_lock);
TAILQ_INSERT_TAIL(×hift_reaper_list, tsf, link);
pthread_cond_signal(×hift_reaper_cond);
if (tsf->wfd >= 0)
close(tsf->wfd);
assert(tsf->rfd < 0);
-#if ENABLE_TRACE
- if (tsf->path)
- tvhdebug("timeshift", "ts %d remove %s", ts->id, tsf->path);
- else
- tvhdebug("timeshift", "ts %d RAM segment remove time %li", ts->id, (long)tsf->time);
-#endif
+ if (tvhtrace_enabled()) {
+ if (tsf->path)
+ tvhdebug("timeshift", "ts %d remove %s", ts->id, tsf->path);
+ else
+ tvhdebug("timeshift", "ts %d RAM segment remove time %li", ts->id, (long)tsf->time);
+ }
TAILQ_REMOVE(&ts->files, tsf, link);
atomic_dec_u64(×hift_total_size, tsf->size);
if (tsf->ram)
(((cur_speed < 0) && (sm->sm_time >= deliver)) ||
((cur_speed > 0) && (sm->sm_time <= deliver))))) {
- if (sm->sm_type == SMT_PACKET) {
-#if ENABLE_TRACE
+ if (sm->sm_type == SMT_PACKET && tvhtrace_enabled()) {
th_pkt_t *pkt = sm->sm_data;
tvhtrace("timeshift",
"ts %d pkt out - stream %d type %c pts %10"PRId64
ts_rescale(pkt->pkt_dts, 1000000),
pkt->pkt_duration,
pktbuf_len(pkt->pkt_payload), sm->sm_time);
-#endif
}
last_time = sm->sm_time;
streaming_target_deliver2(ts->output, sm);
const char *subsys,
const uint8_t *data, ssize_t len )
{
- int i, c, skip;
+ int i, c;
char str[1024];
- /* Don't process if trace is OFF */
- pthread_mutex_lock(&tvhlog_mutex);
- skip = (severity > tvhlog_level);
- pthread_mutex_unlock(&tvhlog_mutex);
- if (skip) return;
-
+ /* Assume that severify was validated before call */
+
/* Build and log output */
while (len > 0) {
c = 0;
#include <pthread.h>
#include <stdarg.h>
+#include "atomic.h"
#include "htsmsg.h"
typedef struct {
#define tvhlog_spawn(severity, subsys, fmt, ...)\
_tvhlog(__FILE__, __LINE__, 0, severity, subsys, fmt, ##__VA_ARGS__)
#if ENABLE_TRACE
-#define tvhtrace(subsys, fmt, ...)\
- _tvhlog(__FILE__, __LINE__, 0, LOG_TRACE, subsys, fmt, ##__VA_ARGS__)
-#define tvhlog_hexdump(subsys, data, len)\
- _tvhlog_hexdump(__FILE__, __LINE__, 0, LOG_TRACE, subsys, (uint8_t*)data, len)
+#define tvhtrace_enabled() LOG_TRACE <= atomic_add(&tvhlog_level, 0)
+#define tvhtrace(subsys, fmt, ...) \
+ do { \
+ if (tvhtrace_enabled()) \
+ _tvhlog(__FILE__, __LINE__, 0, LOG_TRACE, subsys, fmt, ##__VA_ARGS__); \
+ } while (0)
+#define tvhlog_hexdump(subsys, data, len) \
+ do { \
+ if (tvhtrace_enabled()) \
+ _tvhlog_hexdump(__FILE__, __LINE__, 0, LOG_TRACE, subsys, (uint8_t*)data, len); \
+ } while (0)
#else
-#define tvhtrace(...) (void)0
-#define tvhlog_hexdump(...) (void)0
+static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; }
+#define tvhtrace_enabled() 0
+#define tvhtrace(subsys, fmt, ...) do { tvhtrace_no_warnings(NULL, subsys, fmt, ##__VA_ARGS__); } while (0)
+#define tvhlog_hexdump(subsys, data, len) do { tvhtrace_no_warnings(NULL, subsys, data, len); } while (0)
#endif
#define tvhftrace(subsys, fcn) do { \
iplen = sizeof(ip);
size = recvfrom(conn->fd, buf, sizeof(buf), 0,
(struct sockaddr *)&ip, &iplen);
-#if ENABLE_TRACE
- if (size > 0) {
+ if (size > 0 && tvhtrace_enabled()) {
char tbuf[256];
inet_ntop(ip.ss_family, IP_IN_ADDR(ip), tbuf, sizeof(tbuf));
tvhtrace("upnp", "%s - received data from %s:%hu [size=%zi]",
tbuf, (unsigned short) IP_PORT(ip), size);
tvhlog_hexdump("upnp", buf, size);
}
-#endif
/* TODO: a filter */
TAILQ_FOREACH(us, &upnp_services, us_link)
us->us_received(buf, size, conn, &ip);