Commit cfad7658 authored by Dave Thaler's avatar Dave Thaler

Allow passing a context to timer callbacks

This is a pre-requisite for other changes such as multiple devices per process.

Change-Id: I8ce459520bb163901d9bccd39d1cbbe03cf1a2b3
Signed-off-by: default avatarDave Thaler <dthaler@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19763Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
parent 2b44971c
......@@ -52,7 +52,7 @@ extern "C"
#define SECS_YR_2000 (946684800L)
#endif
typedef void(*TimerCallback)();
typedef void(*TimerCallback)(void *ctx);
/**
* Calculate time difference.
......@@ -82,13 +82,13 @@ time_t getSecondsFromAbsTime(struct tm *tp);
int initThread();
void *loop(void *threadid);
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb);
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb, void *ctx);
void unregisterTimer(int id);
#else
time_t timeToSecondsFromNow(tmElements_t *t);
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb);
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb, void *ctx);
void unregisterTimer(int id);
......
......@@ -63,6 +63,7 @@ struct timelist_t
time_t timeout_seconds;
time_t timeout_time;
TimerCallback cb;
void *ctx;
} timeout_list[TIMEOUTS];
time_t timespec_diff(const time_t after, const time_t before)
......@@ -154,7 +155,7 @@ time_t getSecondsFromAbsTime(struct tm *tp)
return delayed_time;
}
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb, void *ctx)
{
time_t now, then;
time_t next;
......@@ -189,6 +190,7 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
timeout_list[idx].timeout_time = then;
timeout_list[idx].timeout_seconds = seconds;
timeout_list[idx].ctx = ctx;
// printf( "\nbefore timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
timeout_list[idx].cb = cb;
......@@ -238,7 +240,7 @@ void checkTimeout()
timeout_list[i].timeout_state = TIMEOUT_UNUSED;
if (timeout_list[i].cb)
{
timeout_list[i].cb();
timeout_list[i].cb(timeout_list[i].ctx);
}
}
}
......@@ -278,7 +280,7 @@ time_t timeToSecondsFromNow(tmElements_t *t_then)
return (time_t) (then - t);
}
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
time_t registerTimer(const time_t seconds, int *id, TimerCallback cb, void *ctx)
{
time_t t, then;
time_t next;
......@@ -308,6 +310,7 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
timeout_list[idx].timeout_time = then;
timeout_list[idx].timeout_seconds = seconds;
timeout_list[idx].ctx = ctx;
// printf( "\nbefore timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
timeout_list[idx].cb = cb;
......@@ -361,7 +364,7 @@ void checkTimeout()
timeout_list[i].timeout_state = TIMEOUT_UNUSED;
if (timeout_list[i].cb)
{
timeout_list[i].cb();
timeout_list[i].cb(timeout_list[i].ctx);
}
}
}
......
......@@ -1581,11 +1581,12 @@ static int InitConfig(mbedtls_ssl_config * conf, int transport, int mode)
/**
* Starts DTLS retransmission.
*/
static void StartRetransmit()
static void StartRetransmit(void *ctx)
{
size_t listIndex = 0;
size_t listLength = 0;
SslEndPoint_t *tep = NULL;
OC_UNUSED(ctx);
oc_mutex_lock(g_sslContextMutex);
if (NULL == g_caSslContext)
......@@ -1615,7 +1616,7 @@ static void StartRetransmit()
if (MBEDTLS_ERR_SSL_CONN_EOF != ret)
{
//start new timer
registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, StartRetransmit);
registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, StartRetransmit, NULL);
//unlock & return
if (!checkSslOperation(tep,
ret,
......@@ -1629,7 +1630,7 @@ static void StartRetransmit()
}
}
//start new timer
registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, StartRetransmit);
registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, StartRetransmit, NULL);
oc_mutex_unlock(g_sslContextMutex);
}
#endif
......@@ -1774,7 +1775,7 @@ CAResult_t CAinitSslAdapter()
oc_mutex_unlock(g_sslContextMutex);
#ifdef __WITH_DTLS__
StartRetransmit();
StartRetransmit(NULL);
#endif
OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__);
......
......@@ -1020,8 +1020,9 @@ OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
return result;
}
void DoScheduledGroupAction()
void DoScheduledGroupAction(void *ctx)
{
OC_UNUSED(ctx);
OIC_LOG(INFO, TAG, "DoScheduledGroupAction Entering...");
ScheduledResourceInfo* info = GetScheduledResource(g_scheduleResourceList);
......@@ -1073,7 +1074,8 @@ void DoScheduledGroupAction()
schedule->time = registerTimer(info->actionset->timesteps,
&schedule->timer_id,
&DoScheduledGroupAction);
&DoScheduledGroupAction,
NULL);
OIC_LOG(INFO, TAG, "Reregistration.");
oc_mutex_unlock(g_scheduledResourceLock);
......@@ -1292,7 +1294,8 @@ OCStackResult BuildCollectionGroupActionCBORResponse(
oc_mutex_lock(g_scheduledResourceLock);
schedule->time = registerTimer(delay,
&schedule->timer_id,
&DoScheduledGroupAction);
&DoScheduledGroupAction,
NULL);
oc_mutex_unlock(g_scheduledResourceLock);
AddScheduledResource(&g_scheduleResourceList,
schedule);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment