📄 schedule.cpp
字号:
// Schedule.cpp: implementation of the CSchedule class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Schedule.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
HANDLE CSchedule::m_hRefMutex = NULL;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPlayItem::CPlayItem()
{
m_pPrev = NULL;
m_pNext = NULL;
m_nPlayItemID = 0;
}
CPlayItem::~CPlayItem()
{
}
//////////////////////////////////////////////////////////////////////////
CChannel::CChannel()
{
m_pNext = NULL;
}
CChannel::~CChannel()
{
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
CSchedule::CSchedule()
{
m_nRefCount = 0;
m_nPlayState = SCHE_PLAY_STATE_NOTDEF;
m_pSeqPlayList_H = NULL;
m_pSeqPlayList_T = NULL;
m_nCurPlayItem = 0;
initRefs();
m_pSetWordList_H = NULL;
m_pSetWordList_T = NULL;
m_pSetNameList_H = NULL;
m_pSetNameList_T = NULL;
}
CSchedule::~CSchedule()
{
CPlayItem *pIter = m_pSeqPlayList_H;
CPlayItem *pBack = NULL;
while (pIter)
{
pBack = pIter->m_pNext;
delete pIter;
pIter = pBack;
}
m_pSeqPlayList_H = NULL;
m_pSeqPlayList_T = NULL;
CWordManage *pRler = m_pSetWordList_H;
CWordManage *pB = NULL;
while (pRler)
{
pB = pRler->pNext;
delete pRler;
pRler = pB;
}
m_pSetWordList_H = NULL;
m_pSetWordList_T = NULL;
CNameManage *pRlse = m_pSetNameList_H;
CNameManage *pb = NULL;
while (pRlse)
{
pb = pRlse->pNext;
delete pRlse;
pRlse = pb;
}
m_pSetNameList_H = NULL;
m_pSetNameList_T = NULL;
}
void CSchedule::Assign( CSchedule *pSche )
{
m_nScheID = pSche->m_nScheID;
m_nScheType = pSche->m_nScheType;
m_strName = pSche->m_strName;
m_strDesc = pSche->m_strDesc;
m_nStartime = pSche->m_nStartime;
m_nStoptime = pSche->m_nStoptime;
m_nPlayState = pSche->m_nPlayState;
m_nLastUpdate = pSche->m_nLastUpdate;
m_strMCastIP = pSche->m_strMCastIP;
m_nMCastPort = pSche->m_nMCastPort;
CPlayItem *pItem = pSche->m_pSeqPlayList_H;
CPlayItem *pNewItem = NULL;
CPlayItem *pBack = NULL;
while ( pItem )
{
pNewItem = new CPlayItem();
*pNewItem = *pItem;
if ( pBack == NULL ) {
m_pSeqPlayList_H = pNewItem;
}
else {
pBack->m_pNext = pNewItem;
}
pBack = pNewItem;
pItem = pItem->m_pNext;
}
m_pSeqPlayList_T = pBack;
}
void CSchedule::SetPlayList( CPlayItem *pItems )
{
m_pSeqPlayList_H = pItems;
while ( pItems ) {
m_pSeqPlayList_T = pItems;
pItems = pItems->m_pNext;
}
}
BOOL CSchedule::AddPlayItem( CPlayItem *pPlayItem )
{
int nPlayItemID = 1;
if ( pPlayItem->m_nPlayOpt == PLAY_OPT_TIMER_DRIVED )
{
if ( m_pSeqPlayList_H == NULL ) {
m_pSeqPlayList_H = pPlayItem;
m_pSeqPlayList_T = pPlayItem;
pPlayItem->m_nPlayItemID = nPlayItemID;
return TRUE;
}
CPlayItem *pIter = m_pSeqPlayList_H;
CPlayItem *pBack = NULL;
while ( pIter )
{
// make a new nPlayItemID
if ( pIter->m_nPlayItemID >= nPlayItemID ) {
nPlayItemID = pIter->m_nPlayItemID+1;
}
// Check the position of the vid
if ( pIter->m_nPlayValue > pPlayItem->m_nPlayValue )
{
if ( pBack ) {
pBack->m_pNext = pPlayItem;
pPlayItem->m_pNext = pIter;
}
else {
m_pSeqPlayList_H = pPlayItem;
pPlayItem->m_pNext = pIter;
}
pPlayItem->m_nPlayItemID = nPlayItemID;
return TRUE;
}
pBack = pIter;
pIter = pIter->m_pNext;
}
if ( pBack )
{
pBack->m_pNext = pPlayItem;
pPlayItem->m_pNext = NULL;
m_pSeqPlayList_T = pPlayItem;
pPlayItem->m_nPlayItemID = nPlayItemID;
}
return TRUE;
}
if ( pPlayItem->m_nPlayOpt == PLAY_OPT_VID_FOLLOWED )
{
CPlayItem *pIter = m_pSeqPlayList_H;
while ( pIter )
{
// make a new nPlayItemID
if ( pIter->m_nPlayItemID >= nPlayItemID ) {
nPlayItemID = pIter->m_nPlayItemID+1;
}
pIter = pIter->m_pNext;
}
if ( m_pSeqPlayList_H == NULL ) {
m_pSeqPlayList_H = pPlayItem;
m_pSeqPlayList_T = pPlayItem;
}
else
{
m_pSeqPlayList_T->m_pNext = pPlayItem;
m_pSeqPlayList_T = pPlayItem;
pPlayItem->m_pNext = NULL;
}
pPlayItem->m_nPlayItemID = nPlayItemID;
return TRUE;
}
return FALSE;
}
BOOL CSchedule::DelPlayItem( int nPlayItemID )
{
CPlayItem *pIter = m_pSeqPlayList_H;
CPlayItem *pBack = NULL;
while ( pIter )
{
if ( pIter->m_nPlayItemID == nPlayItemID ) {
if ( pBack ) {
pBack->m_pNext = pIter->m_pNext;
}
else {
m_pSeqPlayList_H = pIter->m_pNext;
}
delete pIter;
return TRUE;
}
pBack = pIter;
pIter = pIter->m_pNext;
}
return FALSE;
}
BOOL CSchedule::CheckScheState()
{
CTime nowtime = CTime::GetCurrentTime();
int nNewState = SCHE_PLAY_STATE_NOTDEF;
if ( m_nStartime > nowtime ) {
nNewState = SCHE_PLAY_STATE_WAITING;
}
else
if ( m_nStoptime > nowtime ) {
nNewState = SCHE_PLAY_STATE_PLAYING;
}
else {
nNewState = SCHE_PLAY_STATE_OVER;
}
// if there is no change, return FALSE
if ( m_nPlayState == nNewState ) {
return FALSE;
}
// State changed
m_nPlayState = nNewState;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
BOOL CSchedule::initRefs()
{
if ( m_hRefMutex == NULL ) {
m_hRefMutex = CreateMutex( NULL, FALSE, "ScheduleMutex" );
}
if ( m_hRefMutex ) return TRUE;
return FALSE;
}
void CSchedule::closeRefs()
{
if ( m_hRefMutex ) {
CloseHandle(m_hRefMutex);
m_hRefMutex = NULL;
}
}
void CSchedule::addRef()
{
if ( m_hRefMutex == NULL ) return;
WaitForSingleObject( m_hRefMutex, 3000L );
m_nRefCount++;
ReleaseMutex( m_hRefMutex );
}
void CSchedule::release()
{
if ( m_hRefMutex == NULL ) return;
WaitForSingleObject( m_hRefMutex, 3000L );
m_nRefCount--;
if ( m_nRefCount <= 0 )
{
// need to release itself
delete this;
}
ReleaseMutex( m_hRefMutex );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -