Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[core] Added nfc_target_set_transmit_timeout() function. JB#50724
That allows to implement interface, protocol, technology or even tag
specific timeout.
  • Loading branch information
monich committed Aug 6, 2020
1 parent c1562c8 commit 6b23d09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
10 changes: 10 additions & 0 deletions core/include/nfc_target.h
Expand Up @@ -88,6 +88,16 @@ void
nfc_target_unref(
NfcTarget* target);

/*
* -1: Use default timeout
* 0: No timeout at all
* >0: Transmision timeout in milliseconds
*/
void
nfc_target_set_transmit_timeout(
NfcTarget* target,
int ms); /* Since 1.0.37 */

gulong
nfc_target_add_sequence_handler(
NfcTarget* target,
Expand Down
33 changes: 29 additions & 4 deletions core/src/nfc_target.c
Expand Up @@ -38,7 +38,7 @@

#include <gutil_misc.h>

#define TRANSMIT_TIMEOUT_MS (500)
#define DEFAULT_TRANSMIT_TIMEOUT_MS (500)
#define DEFAULT_REACTIVATION_TIMEOUT_MS (1000)

typedef struct nfc_target_request NfcTargetRequest;
Expand Down Expand Up @@ -77,6 +77,7 @@ struct nfc_target_priv {
NfcTargetRequest* req_active;
NfcTargetSequenceQueue seq_queue;
NfcTargetRequestQueue req_queue;
guint tx_timeout_ms;
/* Reactivation */
NfcTargetFunc ra_func;
void* ra_data;
Expand Down Expand Up @@ -367,9 +368,11 @@ nfc_target_submit_request(
nfc_target_set_sequence(self, req->seq);
}
if (NFC_TARGET_GET_CLASS(self)->transmit(self, data, len)) {
GASSERT(!req->timeout);
req->timeout = g_timeout_add(TRANSMIT_TIMEOUT_MS,
nfc_target_transmit_timeout, req);
if (priv->tx_timeout_ms) {
GASSERT(!req->timeout);
req->timeout = g_timeout_add(priv->tx_timeout_ms,
nfc_target_transmit_timeout, req);
}
return TRUE;
} else {
priv->req_active = NULL;
Expand Down Expand Up @@ -591,6 +594,27 @@ nfc_target_cancel_transmit(
return FALSE;
}

void
nfc_target_set_transmit_timeout(
NfcTarget* self,
int ms) /* Since 1.0.37 */
{
if (G_LIKELY(self)) {
NfcTargetPriv* priv = self->priv;

if (ms < 0) {
priv->tx_timeout_ms = DEFAULT_TRANSMIT_TIMEOUT_MS;
} else {
priv->tx_timeout_ms = ms;
if (priv->tx_timeout_ms) {
GDEBUG("Transmission timeout %u ms", priv->tx_timeout_ms);
} else {
GDEBUG("No transmission timeout");
}
}
}
}

void
nfc_target_deactivate(
NfcTarget* self)
Expand Down Expand Up @@ -797,6 +821,7 @@ nfc_target_init(
self->present = TRUE;
self->priv = priv;
priv->ra_timeout_ms = DEFAULT_REACTIVATION_TIMEOUT_MS;
priv->tx_timeout_ms = DEFAULT_TRANSMIT_TIMEOUT_MS;
}

static
Expand Down

0 comments on commit 6b23d09

Please sign in to comment.