timer.cpp

来自「ABis无线接口全套资料」· C++ 代码 · 共 212 行

CPP
212
字号
/* ======================================================================== *\
 |
 |
 |  JOYIT Communication Technology
 |  Copyright (C)  2002-2003,  All Right Reserved.
 |
 |  System: Programmable Signaling Gateway
 |  Sub-system: PSG
 |  Filename: timer.cpp
 |  Environment: Red Hat Linux 9.0 & GNU C/C++ Compiler 3.2.2
 |  Function description: Timer.
 |           
 |
\* ======================================================================== */

#ifndef _TIMER_HPP
#include "timer.hpp"
#endif

#include "unistd.h"

extern "C"
{
#include "stdio.h"
#include "sys/msg.h"
#include "fcntl.h"
#include "stdlib.h"
#include "signal.h"
};


STimerQue::STimerQue()
{
	for(int j=0;j<IPC_MAXTIMERQUE;j++)
   		m_opaTimerQue[j]=new EventQueueType;
}

STimerQue::~STimerQue()
{
    delete [] m_opaTimerQue;
}

int STimerQue::DelTimerQue(UINT32 mid)
{
	WEvent ev;
    STimer sTimer;

	for(int j=0;j<IPC_MAXTIMERQUE;j++)
	{
		int cnt=m_opaTimerQue[j]->evtCount();
		for(int i=0;i<cnt;i++)
		{
			m_opaTimerQue[j]->popEvent(ev);
			if(ev.what==0)
				break;

			if(mid==0L)
				continue;
				
			memcpy(&sTimer,ev.msgPtr,sizeof(STimer));
			if(mid==sTimer.ev.smid)
			{
				ev.del();//2004
				continue;
			}

			m_opaTimerQue[j]->pushEvent(ev);
			ev.del();//2004
		}
	}

	return 0;
}

int STimerQue::StartTimer(const WEvent &ev)
{
	STimer st;

	memcpy(&st, ev.msgPtr, ev.msgLen);

	UINT8 qid;

	qid=st.cTimerPrecision;

	if (qid < IPC_MAXTIMERQUE)
	{
		//printf("Start a timer val=%d pre=%d flag=%d\n",st.iTimeVal,st.cTimerPrecision,st.cTimerFlag);
		m_opaTimerQue[qid]->pushEvent(ev);
	}
	else
	{
		printf("Invalid TimerPrecision=%d\n", qid);
		return -1;
	}
	
	return 0;
}

int STimerQue::StopTimer(const WEvent &evt)
{
	WEvent ev;
	STimer sTimer,st;
	memcpy(&st, evt.msgPtr, sizeof(STimer));

	/*
	UINT8 qid;
	
	qid=st.cTimerPrecision;
	if(qid>=IPC_MAXTIMERQUE)
	{
		printf("Invalid TimerPrecision=%d\n",qid);
		return -1;
	}
	*/

	for(int qid=0; qid<IPC_MAXTIMERQUE; qid++)
	{
		for(int i=0; i<m_opaTimerQue[qid]->evtCount(); i++)
		{
			m_opaTimerQue[qid]->popEvent(ev);
			
			if(ev.what == 0)
			{
				break;
			}

			memcpy(&sTimer, ev.msgPtr, sizeof(STimer));
        
			// if (sTimer.ev.evCode == st.ev.evCode) // Modify 2005-01-10, by Wujianjin.
			// It may be stop the timer not owned to the starting module.
			if ((sTimer.ev.evCode == st.ev.evCode)  &&
				(sTimer.ev.smid == st.ev.smid))
			{
				if ((sTimer.ev.tmEvent.subMod == st.ev.tmEvent.subMod)  &&
					(sTimer.ev.tmEvent.brd==st.ev.tmEvent.brd))
				{
					//printf("Stop a timer val=%d pre=%d flag=%d\n",st.iTimeVal,st.cTimerPrecision,st.cTimerFlag);
					ev.del();//2004-01-10
					return 0;
				}
			}

			// Put the timer back.        
			m_opaTimerQue[qid]->pushEvent(ev);
			ev.del();//2004-01-10
		}
	}

	return -1;
}

int STimerQue::VerifyTimer(const WEvent& event) // Add 2005-01-10, by Wujianjin.
{ // To check the timer queue. If the timer not exist in the queue, then start it.
	WEvent ev;
	STimer sTimer,st;
	memcpy(&st, event.msgPtr, sizeof(STimer));

	for(int qid=0; qid<IPC_MAXTIMERQUE; qid++)
	{
		for(int i=0; i<m_opaTimerQue[qid]->evtCount(); i++)
		{
			m_opaTimerQue[qid]->popEvent(ev);
			
			if(ev.what == 0)
			{
				break;
			}

			memcpy(&sTimer, ev.msgPtr, sizeof(STimer));
        
			if ((sTimer.ev.evCode == st.ev.evCode)  &&
				(sTimer.ev.smid == st.ev.smid))
			{
				if ((sTimer.ev.tmEvent.subMod == st.ev.tmEvent.subMod)  &&
					(sTimer.ev.tmEvent.brd==st.ev.tmEvent.brd))
				{
					// Got it.
					// Put the timer back.
					m_opaTimerQue[qid]->pushEvent(ev);
					ev.del();
					return 0;
				}
			}

			// Put the timer back.        
			m_opaTimerQue[qid]->pushEvent(ev);
			ev.del();//2004-01-10
		}
	}

	// The time not exist.
	// Start the timer.
	memcpy(&ev, &event, sizeof(WEvent));
	// ((STimer *)ev.msgPtr)->ev.evCode = SYSMGR_IPC_STARTTIMER;
	ev.evCode = SYSMGR_IPC_STARTTIMER;
	((STimer *)ev.msgPtr)->iTimeLeft -= 4000; // Reduce the HEARTBEAT cycle and MTP3 check links status's delay.
	StartTimer(ev);
	
	return 0;
}

// ------------------------------------------------------------------------
//
//  Revision list.
//  ==============
//
//  1.0,        2003-05-28,     Lu Shengsheng
//      Initial version.
//
// ------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?