1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*----------------------------------------------------------------------------*
* *
* M I N I M A L I S T I C T M R M G R E N T I T Y *
* *
* Copyright (C) 2010 Amit Chawre. *
* *
*----------------------------------------------------------------------------*/
/**
* @file NwMiniTmrMgrEntity.c
* @brief This file ontains example of a minimalistic timer manager entity.
*/
#include <stdio.h>
#include <assert.h>
#include "NwEvt.h"
#include "NwGtpv2c.h"
#include "NwMiniLogMgrEntity.h"
#include "NwMiniTmrMgrEntity.h"
#ifndef NW_ASSERT
#define NW_ASSERT assert
#endif
#ifdef __cplusplus
extern "C" {
#endif
static
NwCharT* gLogLevelStr[] = {"EMER", "ALER", "CRIT", "ERRO", "WARN", "NOTI", "INFO", "DEBG"};
/*---------------------------------------------------------------------------
* Private functions
*--------------------------------------------------------------------------*/
static void
NW_TMR_CALLBACK(nwGtpv2cNodeHandleStackTimerTimeout)
{
NwRcT rc;
NwGtpv2cNodeTmrT *pTmr = (NwGtpv2cNodeTmrT*) arg;
/*
* Send Timeout Request to Gtpv2c Stack Instance
*/
rc = nwGtpv2cProcessTimeout(pTmr->timeoutArg);
NW_ASSERT(NW_OK == rc);
free(pTmr);
return;
}
/*---------------------------------------------------------------------------
* Public functions
*--------------------------------------------------------------------------*/
NwRcT nwTimerStart( NwGtpv2cTimerMgrHandleT tmrMgrHandle,
uint32_t timeoutSec,
uint32_t timeoutUsec,
uint32_t tmrType,
void* timeoutArg,
NwGtpv2cTimerHandleT* hTmr)
{
NwRcT rc = NW_OK;
NwGtpv2cNodeTmrT *pTmr;
struct timeval tv;
pTmr = (NwGtpv2cNodeTmrT*) malloc(sizeof(NwGtpv2cNodeTmrT));
/* set the timevalues*/
timerclear(&tv);
tv.tv_sec = timeoutSec;
tv.tv_usec = timeoutUsec;
pTmr->timeoutArg = timeoutArg;
evtimer_set(&pTmr->ev, nwGtpv2cNodeHandleStackTimerTimeout, pTmr);
/*add event*/
event_add(&(pTmr->ev), &tv);
*hTmr = (NwGtpv2cTimerHandleT)pTmr;
return rc;
}
NwRcT nwTimerStop( NwGtpv2cTimerMgrHandleT tmrMgrHandle,
NwGtpv2cTimerHandleT hTmr)
{
evtimer_del(&(((NwGtpv2cNodeTmrT*)hTmr)->ev));
free((void*)hTmr);
return NW_OK;
}
#ifdef __cplusplus
}
#endif