libUPnP  1.6.17
Functions
TimerThread.c File Reference
#include "TimerThread.h"
#include <assert.h>
Include dependency graph for TimerThread.c:

Functions

static void FreeTimerEvent (TimerThread *timer, TimerEvent *event)
 Deallocates a dynamically allocated TimerEvent.
static void * TimerThreadWorker (void *arg)
 Implements timer thread.
static int CalculateEventTime (time_t *timeout, TimeoutType type)
 Calculates the appropriate timeout in absolute seconds since Jan 1, 1970.
static TimerEventCreateTimerEvent (TimerThread *timer, ThreadPoolJob *job, Duration persistent, time_t eventTime, int id)
 Creates a Timer Event. (Dynamically allocated).
int TimerThreadInit (TimerThread *timer, ThreadPool *tp)
 Initializes and starts timer thread.
int TimerThreadSchedule (TimerThread *timer, time_t timeout, TimeoutType type, ThreadPoolJob *job, Duration duration, int *id)
 Schedules an event to run at a specified time.
int TimerThreadRemove (TimerThread *timer, int id, ThreadPoolJob *out)
 Removes an event from the timer Q.
int TimerThreadShutdown (TimerThread *timer)
 Shutdown the timer thread.

Detailed Description


Function Documentation

static int CalculateEventTime ( time_t *  timeout,
TimeoutType  type 
) [static]

Calculates the appropriate timeout in absolute seconds since Jan 1, 1970.

Returns:
Parameters:
[in]timeoutTimeout.
[in]typeTimeout type.

References ABS_SEC.

Referenced by TimerThreadSchedule().

static TimerEvent* CreateTimerEvent ( TimerThread timer,
ThreadPoolJob job,
Duration  persistent,
time_t  eventTime,
int  id 
) [static]

Creates a Timer Event. (Dynamically allocated).

Returns:
(TimerEvent *) on success, NULL on failure.
Parameters:
[in]timerValid timer thread pointer.
[in]job.
[in]persistent.
[in]eventTimeThe absoule time of the event in seconds from Jan, 1970.
[in]idId of job.

References TIMEREVENT::eventTime, FreeListAlloc(), and TIMEREVENT::persistent.

Referenced by TimerThreadSchedule().

static void FreeTimerEvent ( TimerThread timer,
TimerEvent event 
) [static]

Deallocates a dynamically allocated TimerEvent.

Parameters:
[in]timerValid timer thread pointer.
[in]eventMust be allocated with CreateTimerEvent

References FreeListFree().

Referenced by TimerThreadRemove(), TimerThreadSchedule(), TimerThreadShutdown(), and TimerThreadWorker().

int TimerThreadInit ( TimerThread timer,
ThreadPool tp 
)

Initializes and starts timer thread.

Returns:
0 on success, nonzero on failure. Returns error from ThreadPoolAddPersistent on failure.
Parameters:
[in]timerValid timer thread pointer.
[in]tpValid thread pool to use. Must be started. Must be valid for lifetime of timer. Timer must be shutdown BEFORE thread pool.

References FreeListDestroy(), FreeListInit(), ListDestroy(), ListInit(), ThreadPoolAddPersistent(), TimerThreadWorker(), TPJobInit(), and TPJobSetPriority().

Referenced by UpnpInitPreamble().

int TimerThreadRemove ( TimerThread timer,
int  id,
ThreadPoolJob out 
)

Removes an event from the timer Q.

Events can only be removed before they have been placed in the thread pool.

Returns:
0 on success, INVALID_EVENT_ID on failure.
Parameters:
[in]timerValid timer thread pointer.
[in]idId of event to remove.
[in]outSpace for thread pool job.

References FreeTimerEvent(), ListDelNode(), ListHead(), and ListNext().

Referenced by free_client_subscription(), and genaRenewSubscription().

int TimerThreadSchedule ( TimerThread timer,
time_t  time,
TimeoutType  type,
ThreadPoolJob job,
Duration  duration,
int *  id 
)

Schedules an event to run at a specified time.

Returns:
0 on success, nonzero on failure, EOUTOFMEM if not enough memory to schedule job.
Parameters:
[in]timerValid timer thread pointer.
[in]timeouttime of event. Either in absolute seconds, or relative seconds in the future.
[in]typeeither ABS_SEC, or REL_SEC. If REL_SEC, then the event will be scheduled at the current time + REL_SEC.
[in]jobValid Thread pool job with following fields.
[in]duration.
[in]idId of timer event. (out, can be null).

References CalculateEventTime(), CreateTimerEvent(), TIMEREVENT::eventTime, FreeTimerEvent(), ListAddBefore(), ListAddTail(), ListHead(), and ListNext().

Referenced by ScheduleGenaAutoRenew(), SearchByTarget(), ssdp_handle_device_request(), and UpnpSendAdvertisementLowPower().

int TimerThreadShutdown ( TimerThread timer)

Shutdown the timer thread.

Events scheduled in the future will NOT be run.

Timer thread should be shutdown BEFORE it's associated thread pool.

Returns:
0 if succesfull, nonzero otherwise. Always returns 0.
Parameters:
[in]timerValid timer thread pointer.

References FreeListDestroy(), FreeTimerEvent(), ListDelNode(), ListDestroy(), ListHead(), and ListNext().

Referenced by UpnpFinish().

static void* TimerThreadWorker ( void *  arg) [static]

Implements timer thread.

Waits for next event to occur and schedules associated job into threadpool.

Parameters:
[in]argarg is cast to (TimerThread *).

References TIMEREVENT::eventTime, FreeTimerEvent(), ListDelNode(), ListHead(), TIMEREVENT::persistent, LINKEDLIST::size, ThreadPoolAdd(), and ThreadPoolAddPersistent().

Referenced by TimerThreadInit().