?? cm_bdy5.c
字號:
/********************************************************************20**
Name: common functions - 5
Type: C source file
Desc: C source code for common timer routines;
File: cm_bdy5.c
Sid: cm_bdy5.c 1.13 - 10/14/98 14:29:44
Prg: na
*********************************************************************21*/
/* header include files -- defines (.h) */
#include "envopt.h" /* environment options */
#include "envdep.h" /* environment dependent */
#include "envind.h" /* environment independent */
#include "gen.h" /* general */
#include "cm5.h" /* common functions */
#include "ssi.h" /* system services */
/* header/extern include files (.x) */
#include "gen.x" /* general */
#include "cm5.x" /* common functions */
#include "ssi.x" /* system services */
/* local defines */
/* local externs */
/* forward references */
/* functions in other modules */
/*
*
* Fun: cmPrcTmr
*
* Desc: Handle a timer entry
*
* Ret: RETVOID
*
* Notes: Connection Oriented Control
*
* File: cm_bdy5.c
*
*/
#ifdef ANSI
PUBLIC Void cmPrcTmr
(
CmTqCp *tqCp, /* timing que control point */
CmTqType *tq, /* timing queue */
PFV func /* function */
)
#else
PUBLIC Void cmPrcTmr(tqCp, tq, func)
CmTqCp *tqCp; /* connection control block */
CmTqType *tq; /* message buffer */
PFV func; /* function */
#endif
{
U16 expire;
U16 entry;
S16 event;
PTR cb;
CmTimer *tmp1;
CmTimer **tmp2;
TRC2(cmPrcTmr)
#ifdef CMDBG
{
DateTime dt;
Txt prntBuf[PRNTSZE];
SGetDateTime(&dt);
sprintf(prntBuf,"%s: date: %02d/%02d/%02d time: %02d:%02d:%02d\n",
msArgv[0],dt.month,dt.day,dt.year,dt.hour,dt.min,dt.sec);
SPrint(prntBuf);
}
#endif
++tqCp->nxtEnt;
expire = tqCp->nxtEnt;
entry = (U16) (expire % (U16)(tqCp->tmrLen));
tmp2 = &tq[entry].first;
while ((tmp1 = *tmp2) != NULLP)
{
if (tmp1->tqExpire == expire)
{
event = tmp1->tmrEvnt;
cb = tmp1->cb;
/* remove and reset this timer control block */
(*tmp2) = tmp1->next;
tmp1->tmrEvnt = TMR_NONE;
tmp1->tqExpire = 0;
tmp1->cb = NULLP;
tmp1->next = NULLP;
func(cb, event);
} else
tmp2 = &tmp1->next;
}
RETVOID;
} /* end of cmPrcTmr */
/*
*
* Fun: cmInitTimers
*
* Desc: initialize timers
*
* Ret: RETVOID
*
* Notes: Connection Oriented Control
*
* File: cm_bdy5.c
*
*/
#ifdef ANSI
PUBLIC Void cmInitTimers
(
CmTimer *timers, /* timer list */
U8 max /* maximum tmrs */
)
#else
PUBLIC Void cmInitTimers(timers, max)
CmTimer *timers; /* timer list */
U8 max; /* maximum tmrs */
#endif
{
CmTimer *tPtr;
REG1 U8 i;
TRC2(cmInitTimers)
for (i = 0, tPtr = timers; i < max; i++, tPtr++)
{
tPtr->tmrEvnt = TMR_NONE;
tPtr->tqExpire = 0;
tPtr->cb = 0;
tPtr->next = (struct cmTimer *)NULLP;
}
RETVOID;
} /* end of cmInitTimers */
/*
*
* Fun: cmPlcCbTq
*
* Desc: Places Control Block on Timing Queue
*
* Ret: RETVOID
*
* Notes: None
*
* File: cm_bdy5.c
*
*/
#ifdef ANSI
PUBLIC Void cmPlcCbTq
(
CmTmrArg *arg
)
#else
PUBLIC Void cmPlcCbTq(arg)
CmTmrArg *arg;
#endif
{
REG1 U8 tmrNum;
U16 ent;
U16 expire;
CmTimer **tmp;
TRC2(cmPlcCbTq)
expire = (arg->tqCp->nxtEnt + arg->wait);
ent = (U16)(expire % (U16)(arg->tqCp->tmrLen));
for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
{
if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
{
arg->timers[tmrNum].tmrEvnt = arg->evnt;
arg->timers[tmrNum].tqExpire = expire;
arg->timers[tmrNum].cb = arg->cb;
arg->timers[tmrNum].next = NULLP;
tmp = &(arg->tq[ent].first);
while (*tmp)
tmp = &((*tmp)->next);
*tmp = &arg->timers[tmrNum];
RETVOID;
}
}
RETVOID;
} /* end of cmPlcCbTq */
/*
*
* Fun: cmRmvCbTq
*
* Desc: Removes control block from Timing Queue
*
* Ret: RETVOID
*
* Notes: None
*
* File: cm_bdy5.c
*
*/
#ifdef ANSI
PUBLIC Void cmRmvCbTq
(
CmTmrArg *arg
)
#else
PUBLIC Void cmRmvCbTq(arg)
CmTmrArg *arg;
#endif
{
U16 ent;
CmTimer *target;
CmTimer *tmp1;
CmTimer **tmp2;
TRC2(cmRmvCbTq)
target = &arg->timers[arg->tNum];
if (target->tmrEvnt != TMR_NONE)
{
ent = (U16) (target->tqExpire % (U16)(arg->tqCp->tmrLen));
tmp2 = &arg->tq[ent].first;
while ((tmp1 = *tmp2) != NULLP)
{
if (tmp1 == target)
{
/* find the timer control block to be removed */
(*tmp2) = tmp1->next;
tmp1->tmrEvnt = TMR_NONE;
tmp1->tqExpire = 0;
tmp1->cb = NULLP;
tmp1->next = NULLP;
break;
} else
/* find the next timer control block */
tmp2 = &tmp1->next;
}
}
RETVOID;
} /* end of cmRmvCbTq */
/********************************************************************30**
End of file: cm_bdy5.c 1.13 - 10/14/98 14:29:44
*********************************************************************31*/
/********************************************************************40**
Notes:
*********************************************************************41*/
/********************************************************************50**
*********************************************************************51*/
/********************************************************************60**
Revision history:
*********************************************************************61*/
/********************************************************************80**
version pat init description
----------- ----- ---- ------------------------------------------------
1.1 --- fmg 1. initial release
1.2 --- fmg 1. fixed inconsistent use of Void/RETVOID
--- mc 1. replace (tqCp->tmrLen -1) with (tqCp->tmrLen)
when using % operator.
--- fmg 2. add ERRCHK to cmPlcCbTq
--- fmg 3. add CMDBG to cmPrcTmr
1.3 --- mc 1. remove lm_pt.h and lm_pt.x include files.
--- mc 2. replace ss_pt.? and ss_ms.? with ssi.?.
1.4 --- mc 1. change the order of include files ssi.[hx] and
gen.[hx].
1.5 --- fmg 1. removed redundant function prototypes
1.6 --- mc 1. declared event to be S16 in cmPrcTmr.
1.7 --- rg 1. change cmPlcCbTq to add new timer to the end of
the list, to preserve order of expiry of timers.
1.8 --- aa 1. Removed the checks for parameter inconsistency
and hence the SErrors. The caller of such
functions now should ensure that it is not
passing the bad value to the routines.
1.9 --- ada 1. In cmPrcTmr the next entry is increamented
*++tqCp->nxtEnt* and then used in *expire*
*********************************************************************81*/
/********************************************************************90**
ver pat init description
------------ -------- ---- ----------------------------------------------
1.10 --- bbk 1. Changed copyright header date.
1.12 --- ada 1. Corrected file for chksrc utility
1.13 --- kp 1. Removed include of cm_err.h, not
required
*********************************************************************91*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -