#include <iostream>
#include <stdio.h>
#include <pthread.h>
#include <sys/time.h>
#include <error.h>
#include <stdlib.h>
#include <memory.h>
#include <fstream>
//#include <log4cxx/logger.h>
//#include <log4cxx/logstring.h>
//#include <log4cxx/propertyconfigurator.h>
#include "log4cxx_wrapper.h"
#include "interface_api.h"
#include "disp_task.h"
#include "queue_manager.h"
//using namespace log4cxx;
//extern LoggerPtr g_Dslogger;
extern DsManage g_cDsManage;
BOOL32 DsGetTimeInfo( TaskTimeInfo* ptTimeInfo )
{
if( NULL == ptTimeInfo )
{
return FALSE;
}
struct tm tmTemp;
struct timeval ttTemp;
if( 0 != gettimeofday( &ttTemp , NULL ) )
{
return FALSE;
}
tmTemp = *localtime( &ttTemp.tv_sec );
ptTimeInfo->m_wYear = tmTemp.tm_year+1900;
ptTimeInfo->m_wMonth = tmTemp.tm_mon+1;
ptTimeInfo->m_wDay = tmTemp.tm_mday;
ptTimeInfo->m_wHour = tmTemp.tm_hour;
ptTimeInfo->m_wMinute = tmTemp.tm_min;
ptTimeInfo->m_wSecond = tmTemp.tm_sec;
return TRUE;
}
void DsManage::OnRegister(RegisterInfo ®Info, TsSession &session)
{
string json;
TsMessageCodec tmpTsMessageCodec;
RegisterResponse* pResponse = new RegisterResponse;
u32 dwTsIndex=0;
u32 dwTsFreeIndex = 0;
bool bFind = FALSE;
bool bResult = TRUE;
TsType tsType = regInfo.GetTsType();
LoggerWrapper dsLog= LoggerWrapper::GetInstance();
dsLog.Log(TRUE,LOGGER_DEBUG,"session:%d,GetTsId:%s,GetTsIp:%s,GetTstype:%d , [%s][%s][%d]\n",&session,regInfo.GetTsId().c_str(),regInfo.GetTsIp().c_str(),regInfo.GetTsType(),__FILE__,__PRETTY_FUNCTION__,__LINE__);
// printf("GetTsId:%s,GetTsIp:%s,GetTstype:%d\n",regInfo.GetTsId().c_str(),regInfo.GetTsIp().c_str(),regInfo.GetTsType());
//添加注册的转换服务器进入转换服务器队列
if(TS_DYNAMIC_PPT == tsType)
{
for(dwTsIndex=1;dwTsIndex<MAX_DANAMIC_PPT_TRANS_SERVER_NUM;dwTsIndex++)
{
if(TS_UNREGISTERED == g_cDsManage.PPTTs[dwTsIndex].GetState())
{
if(FALSE == bFind)
{
bFind = TRUE;
dwTsFreeIndex = dwTsIndex;
}
}
else if((TS_FREE == g_cDsManage.PPTTs[dwTsIndex].GetState()) ||(TS_RUNNING== g_cDsManage.PPTTs[dwTsIndex].GetState()))
{
if((g_cDsManage.PPTTs[dwTsIndex].GetIpAddr() == regInfo.GetTsIp()) && (g_cDsManage.PPTTs[dwTsIndex].GetTsId() == regInfo.GetTsId()))
{
bResult = FALSE;
break;
}
}
}
if(bFind && bResult)
{
PPTTs[dwTsFreeIndex].SetIpAddr(regInfo.GetTsIp());
PPTTs[dwTsFreeIndex].SetTsId( regInfo.GetTsId());
PPTTs[dwTsFreeIndex].SetTsType( regInfo.GetTsType());
PPTTs[dwTsFreeIndex].SetTsSession( &session);
PPTTs[dwTsFreeIndex].SetState(TS_FREE);
}
}
else if(TS_DOCUMENT_WINDOWS == tsType)
{
for(dwTsIndex=1;dwTsIndex<MAX_DOC_WINDOWS_TRANS_SERVER_NUM;dwTsIndex++)
{
if(TS_UNREGISTERED == g_cDsManage.DocWindowsTs[dwTsIndex].GetState())
{
if(FALSE == bFind)
{
bFind = TRUE;
dwTsFreeIndex = dwTsIndex;
}
}
else if((TS_FREE == g_cDsManage.DocWindowsTs[dwTsIndex].GetState()) ||(TS_RUNNING== g_cDsManage.DocWindowsTs[dwTsIndex].GetState()))
{
if((g_cDsManage.DocWindowsTs[dwTsIndex].GetIpAddr() == regInfo.GetTsIp()) && (g_cDsManage.DocWindowsTs[dwTsIndex].GetTsId() == regInfo.GetTsId()))
{
bResult = FALSE;
break;
}
}
}
if(bFind && bResult)
{
DocWindowsTs[dwTsFreeIndex].SetIpAddr(regInfo.GetTsIp());
DocWindowsTs[dwTsFreeIndex].SetTsId( regInfo.GetTsId());
DocWindowsTs[dwTsFreeIndex].SetTsType( regInfo.GetTsType());
DocWindowsTs[dwTsFreeIndex].SetTsSession( &session);
DocWindowsTs[dwTsFreeIndex].SetState(TS_FREE);
}
}
else if(TS_DOCUMENT == tsType)
{
for(dwTsIndex=1;dwTsIndex<MAX_DOC_TRANS_SERVER_NUM;dwTsIndex++)
{
if(TS_UNREGISTERED == g_cDsManage.DocTs[dwTsIndex].GetState())
{
if(FALSE == bFind)
{
bFind = TRUE;
dwTsFreeIndex = dwTsIndex;
}
}
else if((TS_FREE == g_cDsManage.DocTs[dwTsIndex].GetState()) ||(TS_RUNNING== g_cDsManage.DocTs[dwTsIndex].GetState()))
{
if((g_cDsManage.DocTs[dwTsIndex].GetIpAddr() == regInfo.GetTsIp()) && (g_cDsManage.DocTs[dwTsIndex].GetTsId() == regInfo.GetTsId()))
{
bResult = FALSE;
break;
}
}
}
if(bFind && bResult)
{
DocTs[dwTsFreeIndex].SetIpAddr(regInfo.GetTsIp());
DocTs[dwTsFreeIndex].SetTsId( regInfo.GetTsId());
DocTs[dwTsFreeIndex].SetTsType( regInfo.GetTsType());
DocTs[dwTsFreeIndex].SetTsSession( &session);
DocTs[dwTsFreeIndex].SetState(TS_FREE);
}
}
else if(TS_VIDEO == tsType)
{
for(dwTsIndex=1;dwTsIndex<MAX_VIDEO_TRANS_SERVER_NUM;dwTsIndex++)
{
if(TS_UNREGISTERED == g_cDsManage.VideoTs[dwTsIndex].GetState())
{
if(FALSE == bFind)
{
bFind = TRUE;
dwTsFreeIndex = dwTsIndex;
}
}
else if((TS_FREE == g_cDsManage.VideoTs[dwTsIndex].GetState()) ||(TS_RUNNING== g_cDsManage.VideoTs[dwTsIndex].GetState()))
{
if((g_cDsManage.VideoTs[dwTsIndex].GetIpAddr() == regInfo.GetTsIp()) && (g_cDsManage.VideoTs[dwTsIndex].GetTsId() == regInfo.GetTsId()))
{
bResult = FALSE;
break;
}
}
}
if(bFind && bResult)
{
VideoTs[dwTsFreeIndex].SetIpAddr(regInfo.GetTsIp());
VideoTs[dwTsFreeIndex].SetTsId( regInfo.GetTsId());
VideoTs[dwTsFreeIndex].SetTsType( regInfo.GetTsType());
VideoTs[dwTsFreeIndex].SetTsSession( &session);
VideoTs[dwTsFreeIndex].SetState(TS_FREE);
}
}
else
{
dsLog.Log(TRUE,LOGGER_DEBUG,"error message from transfer server. Register invalid ts server type::%d , [%s][%s][%d]\n",tsType,__FILE__,__PRETTY_FUNCTION__,__LINE__);
// LOG4CXX_ERROR(g_Dslogger, "error message from transfer server. Register invalid ts server type: ");
// LOG4CXX_ERROR(g_Dslogger, tsType);
return;
}
//发送响应消息给转换服务器
if(bFind && bResult)
{
pResponse->SetResult(TRUE);
pResponse->SetErrorCode(RET_OK);
pResponse->SetErrorDetail("");
}
else if(FALSE == bResult)
{
pResponse->SetResult(FALSE);
pResponse->SetErrorCode(RET_E_REPEATED_TS_ID);
pResponse->SetErrorDetail("Same ts id can not be registered repeated!");
}
else if(FALSE == bFind)
{
pResponse->SetResult(FALSE);
pResponse->SetErrorCode(RET_E_TS_USED_UP);
pResponse->SetErrorDetail("No enough ts resource can be registered!");
}
session.SendMessage(*pResponse);
if((FALSE == bResult) || (FALSE == bFind))
{
session.Close();
return;
}
//如果注册成功检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
if(TS_DYNAMIC_PPT == tsType)
{
if (( !m_TransDynamicPptWaitQueue.empty() ) && (TRUE == bResult)&& (TRUE == bFind))
{
AppTaskMessage* pTaskMessage = m_TransDynamicPptWaitQueue.top( );
// printf("4444 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
m_TransDynamicPptWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDynamicPptRunQueue.push_back(pTaskMessage);
PPTTs[dwTsFreeIndex].SetMessageInTs(pTaskMessage);
PPTTs[dwTsFreeIndex].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsFreeIndex);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
PPTTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pTransitionRequest);
// printf("55555 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
// printf("666 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
}
}
else if(TS_DOCUMENT_WINDOWS == tsType)
{
if (( !m_TransDocWindowsWaitQueue.empty() ) && (TRUE == bResult)&& (TRUE == bFind))
{
AppTaskMessage* pTaskMessage = m_TransDocWindowsWaitQueue.top( );
// printf("4444 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
m_TransDocWindowsWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocWindowsRunQueue.push_back(pTaskMessage);
DocWindowsTs[dwTsFreeIndex].SetMessageInTs(pTaskMessage);
DocWindowsTs[dwTsFreeIndex].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsFreeIndex);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocWindowsTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pTransitionRequest);
// printf("55555 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
// printf("666 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
}
}
else if(TS_DOCUMENT == tsType)
{
if (( !m_TransDocWaitQueue.empty() ) && (TRUE == bResult)&& (TRUE == bFind))
{
AppTaskMessage* pTaskMessage = m_TransDocWaitQueue.top( );
// printf("4444 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDocWaitQueue.size());
m_TransDocWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocRunQueue.push_back(pTaskMessage);
DocTs[dwTsFreeIndex].SetMessageInTs(pTaskMessage);
DocTs[dwTsFreeIndex].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsFreeIndex);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pTransitionRequest);
// printf("55555 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDocWaitQueue.size());
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
// printf("666 target:%s,prefix:%s,type:%d\n",pTaskMessage->GetTargetFullPathFileName().c_str(),pTaskMessage->GetFilePrefix().c_str(),pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDocWaitQueue.size());
}
}
else //(TS_VIDEO == tsType)
{
if (( !m_VideoWaitQueue.empty() ) && (TRUE == bResult)&& (TRUE == bFind))
{
AppTaskMessage* pTaskMessage = m_VideoWaitQueue.top( );
m_VideoWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_VideoRunQueue.push_back(pTaskMessage);
VideoTs[dwTsFreeIndex].SetMessageInTs(pTaskMessage);
VideoTs[dwTsFreeIndex].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsFreeIndex);
if(APP_MESSAGE_VIDEO_TRANS_TASK == pTaskMessage->GetAppMessageType())
{
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
VideoTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == pTaskMessage->GetAppMessageType())
{
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
VideoTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
}
else if(APP_MESSAGE_VIDEO_INFO_TASK == pTaskMessage->GetAppMessageType())
{
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
VideoTs[dwTsFreeIndex].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
}
else //error
{
dsLog.Log(TRUE,LOGGER_DEBUG,"error task in the wait queue appMessage type::%d , [%s][%s][%d]\n",pTaskMessage->GetAppMessageType(),__FILE__,__PRETTY_FUNCTION__,__LINE__);
}
}
}
}
void DsManage::OnTaskResult(TaskResult &taskResult, TsSession &session)
{
LoggerWrapper dsLog= LoggerWrapper::GetInstance();
// printf("OnTaskResult, result:%d, session:%d ***************\n",taskResult.GetResult(),&session);
dsLog.Log(TRUE,LOGGER_DEBUG,"OnTaskResult, result:%d, session:%d , [%s][%s][%d]\n",taskResult.GetResult(),&session,__FILE__,__PRETTY_FUNCTION__,__LINE__);
string json;
TsMessageCodec tmpTsMessageCodec;
ResultResponse* pResponse = new ResultResponse;
TsTaskResultType tsTaskResultType = taskResult.GetTsTaskResultType();
bool bFind =FALSE;
//对视频服务器消息的部分单独处理
if(TS_MESSAGE_VIDEO_TRANS_RESULT == tsTaskResultType)
{
pResponse->SetMessageId(taskResult.GetMessageId());
pResponse->SetServerType("Transfer");
}
else if(TS_MESSAGE_VIDEO_CAPTURE_RESULT == tsTaskResultType)
{
pResponse->SetMessageId(taskResult.GetMessageId());
pResponse->SetServerType("CapVideo");
}
else if(TS_MESSAGE_VIDEO_INFO_RESULT == tsTaskResultType)
{
pResponse->SetMessageId(taskResult.GetMessageId());
pResponse->SetServerType("Message");
}
//回复收到转换服务器消息resultresponse
session.SendMessage(*pResponse);
if(NULL != pResponse)
{
delete pResponse;
pResponse = NULL;
}
if(TS_MESSAGE_DOC_TRANS_RESULT == tsTaskResultType)
{
AppDocTransResultMessage* pResult = new AppDocTransResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetResult((taskResult).GetResult());
pResult->SetErrorCode((taskResult).GetErrorCode());
pResult->SetPages((taskResult).GetPages());
//根据转换结果执行相应处理
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDocRunQueue.begin(); iterIdCheck!=m_TransDocRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwRepeatedTimes = pTaskMessage->GetRepeatedTimes();
u32 dwWindowsRepeatedTimes = pTaskMessage->GetMessagePara().unTransDoc.m_dwWindowsRepeatTimes;
// if(((3 == dwRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
if( TRUE == taskResult.GetResult())
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_TransDocRunQueue.erase(iterIdCheck);
}
else if((dwRepeatedTimes<MAX_DOC_TRANS_REPEATED_TIMES)&&(FALSE == taskResult.GetResult()))
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== DocTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
DocTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
DocTs[dwFreeTsNo].SetState(TS_RUNNING);
DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_TransDocWaitQueue.push(pTaskMessage);
DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDocRunQueue.begin(); iterIdCheck!=m_TransDocRunQueue.end(); iterIdCheck++)
{
if(*iterIdCheck ==pTaskMessage)
{
m_TransDocRunQueue.erase(iterIdCheck);
break;
}
}
}
dwRepeatedTimes++;
pTaskMessage->SetRepeatedTimes( dwRepeatedTimes);
}
else if(((MAX_DOC_TRANS_REPEATED_TIMES == dwRepeatedTimes)&&(FALSE == taskResult.GetResult()))&&(0 == dwWindowsRepeatedTimes))
{
//将该任务交给windows版本文档转换处理,同时从运行队列删除
bool bFindWindows = FALSE;
//查找是否存在空闲windows 转换服务器,如果找到,把任务交给它重新处理,并添加到运行队列中,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== DocWindowsTs[dwFreeTsNo].GetState()))
{
DocWindowsTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
DocWindowsTs[dwFreeTsNo].SetState(TS_RUNNING);
DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocWindowsTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindWindows = TRUE;
//将该任务添加到windows版本文档转换运行队列中
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocWindowsRunQueue.push_back(pTaskMessage);
break;
}
}
//如果没有windows 转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列
if(FALSE == bFindWindows)
{
pTaskMessage->SetPriority(9);
m_TransDocWindowsWaitQueue.push(pTaskMessage);
}
//将该任务从linux版文档转换服务器运行队列移除
m_TransDocRunQueue.erase(iterIdCheck);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==DocTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_TransDocWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_TransDocWaitQueue.top( );
m_TransDocWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocRunQueue.push_back(pTaskMessage);
DocTs[dwTsNo].SetMessageInTs(pTaskMessage);
DocTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
}
else
{
DocTs[dwTsNo].SetState(TS_FREE);
DocTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(TS_MESSAGE_DOC_WINDOWS_TRANS_RESULT == tsTaskResultType)
{
//后面跟应用定了协议之后需要创建新的动态PPT的类
AppDocTransResultMessage* pResult = new AppDocTransResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetResult(taskResult.GetResult());
pResult->SetErrorCode(taskResult.GetErrorCode());
pResult->SetPages((taskResult).GetPages());
//根据转换结果执行相应处理
// printf("m_TransDocWindowsRunQueue.size():%d\n",m_TransDocWindowsRunQueue.size());
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDocWindowsRunQueue.begin(); iterIdCheck!=m_TransDocWindowsRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwWindowsRepeatedTimes = pTaskMessage->GetMessagePara().unTransDoc.m_dwWindowsRepeatTimes;
if(((MAX_DOC_WINDOWS_TRANS_REPEATED_TIMES == dwWindowsRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
DocWindowsTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocWindowsTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_TransDocWindowsRunQueue.erase(iterIdCheck);
}
else
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== DocWindowsTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
DocWindowsTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
DocWindowsTs[dwFreeTsNo].SetState(TS_RUNNING);
DocWindowsTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocWindowsTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocWindowsTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_TransDocWindowsWaitQueue.push(pTaskMessage);
DocWindowsTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
DocWindowsTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
m_TransDocWindowsRunQueue.erase(iterIdCheck);
}
dwWindowsRepeatedTimes++;
// pTaskMessage->SetRepeatedTimes( dwWindowsRepeatedTimes);
UnionMessageParam unMessagePara;
unMessagePara = pTaskMessage->GetMessagePara();
unMessagePara.unTransDoc.m_dwWindowsRepeatTimes = dwWindowsRepeatedTimes;
pTaskMessage->SetMessagePara(unMessagePara);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==DocWindowsTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_TransDocWindowsWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_TransDocWindowsWaitQueue.top( );
m_TransDocWindowsWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocWindowsRunQueue.push_back(pTaskMessage);
DocWindowsTs[dwTsNo].SetMessageInTs(pTaskMessage);
DocWindowsTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
DocWindowsTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
}
else
{
DocWindowsTs[dwTsNo].SetState(TS_FREE);
DocWindowsTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(TS_MESSAGE_DYNAMIC_PPT_RESULT == tsTaskResultType)
{
//后面跟应用定了协议之后需要创建新的动态PPT的类
AppDynamicPptTransResultMessage* pResult = new AppDynamicPptTransResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetResult(taskResult.GetResult());
pResult->SetErrorCode(taskResult.GetErrorCode());
pResult->SetPages((taskResult).GetPages());
//根据转换结果执行相应处理
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDynamicPptRunQueue.begin(); iterIdCheck!=m_TransDynamicPptRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwRepeatedTimes = pTaskMessage->GetRepeatedTimes();
if(((3 == dwRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
PPTTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
PPTTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_TransDynamicPptRunQueue.erase(iterIdCheck);
}
else
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== PPTTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
PPTTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
PPTTs[dwFreeTsNo].SetState(TS_RUNNING);
PPTTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
PPTTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
PPTTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_TransDynamicPptWaitQueue.push(pTaskMessage);
PPTTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
PPTTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDynamicPptRunQueue.begin(); iterIdCheck!=m_TransDynamicPptRunQueue.end(); iterIdCheck++)
{
if(*iterIdCheck ==pTaskMessage)
{
m_TransDynamicPptRunQueue.erase(iterIdCheck);
break;
}
}
}
dwRepeatedTimes++;
pTaskMessage->SetRepeatedTimes( dwRepeatedTimes);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==PPTTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_TransDynamicPptWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_TransDynamicPptWaitQueue.top( );
m_TransDynamicPptWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDynamicPptRunQueue.push_back(pTaskMessage);
PPTTs[dwTsNo].SetMessageInTs(pTaskMessage);
PPTTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
PPTTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
}
else
{
PPTTs[dwTsNo].SetState(TS_FREE);
PPTTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(TS_MESSAGE_VIDEO_TRANS_RESULT == tsTaskResultType)
{
AppVideoTransResultMessage* pResult;
pResult = new AppVideoTransResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetResult((taskResult).GetResult());
pResult->SetErrorCode((taskResult).GetErrorCode());
if(FALSE != (taskResult).GetResult())
{
pResult->SetTargetFullPathFileName( taskResult.GetTargetFolder());
}
else
{
pResult->SetTargetFullPathFileName("");
}
//根据转换结果执行相应处理
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwRepeatedTimes = pTaskMessage->GetRepeatedTimes();
if(((3 == dwRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_VideoRunQueue.erase(iterIdCheck);
}
else
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== VideoTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
VideoTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwFreeTsNo].SetState(TS_RUNNING);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
VideoTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_VideoWaitQueue.push(pTaskMessage);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
if(*iterIdCheck ==pTaskMessage)
{
m_VideoRunQueue.erase(iterIdCheck);
break;
}
}
}
dwRepeatedTimes++;
pTaskMessage->SetRepeatedTimes( dwRepeatedTimes);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==VideoTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_VideoWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_VideoWaitQueue.top( );
m_VideoWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_VideoRunQueue.push_back(pTaskMessage);
VideoTs[dwTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
}
else
{
VideoTs[dwTsNo].SetState(TS_FREE);
VideoTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(TS_MESSAGE_VIDEO_CAPTURE_RESULT == tsTaskResultType)
{
AppVideoCaptureResultMessage* pResult;
pResult = new AppVideoCaptureResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetResult(taskResult.GetResult());
pResult->SetErrorCode(taskResult.GetErrorCode());
pResult->SetCount(taskResult.GetCount());
//根据转换结果执行相应处理
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwRepeatedTimes = pTaskMessage->GetRepeatedTimes();
if(((3 == dwRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_VideoRunQueue.erase(iterIdCheck);
}
else
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== VideoTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
VideoTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwFreeTsNo].SetState(TS_RUNNING);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
VideoTs[dwFreeTsNo].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_VideoWaitQueue.push(pTaskMessage);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
if(*iterIdCheck ==pTaskMessage)
{
m_VideoRunQueue.erase(iterIdCheck);
break;
}
}
}
dwRepeatedTimes++;
pTaskMessage->SetRepeatedTimes( dwRepeatedTimes);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==VideoTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_VideoWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_VideoWaitQueue.top( );
m_VideoWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_VideoRunQueue.push_back(pTaskMessage);
VideoTs[dwTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
}
else
{
VideoTs[dwTsNo].SetState(TS_FREE);
VideoTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(TS_MESSAGE_VIDEO_INFO_RESULT == tsTaskResultType)
{
AppVideoInfoResultMessage* pResult;
pResult = new AppVideoInfoResultMessage;
//连接和发送转换结果给应用客户端
pResult->SetMessageId(taskResult.GetMessageId());
pResult->SetDuration(atoll(taskResult.GetDuration().c_str()));
pResult->SetResolution(taskResult.GetResolution());
pResult->SetAudioCode(taskResult.GetAudioCode());
pResult->SetVideoCode(taskResult.GetVideoCode());
pResult->SetAudioTrack(taskResult.GetAudioTrack());
pResult->SetVideoType(taskResult.GetVideoType());
pResult->SetFrameRate(atoi(taskResult.GetFrameRate().c_str()));
pResult->SetBitRate(atoi(taskResult.GetBitRate().c_str()));
pResult->SetResult((taskResult).GetResult());
pResult->SetErrorCode((taskResult).GetErrorCode());
//根据转换结果执行相应处理
//查找运行队列中任务保留该任务ID的IP,端口信息,发送消息给应用端
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == taskResult.GetMessageId())
{
u32 dwRepeatedTimes = pTaskMessage->GetRepeatedTimes();
if(((3 == dwRepeatedTimes)&&(FALSE == taskResult.GetResult())) || (TRUE == taskResult.GetResult()))
{
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
bFind = TRUE;
}
else
{
//error
}
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
m_FreeMessageQueue.push_back(pTaskMessage);
m_VideoRunQueue.erase(iterIdCheck);
}
else
{
bool bFindSecond = FALSE;
//查找是否存在除了自己以外的空闲转换服务器,如果找到,把任务交给它重新处理,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== VideoTs[dwFreeTsNo].GetState()) && (dwFreeTsNo != pTaskMessage->GetTsNum()))
{
VideoTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwFreeTsNo].SetState(TS_RUNNING);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
VideoTs[dwFreeTsNo].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindSecond = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFindSecond)
{
pTaskMessage->SetPriority(9);
m_VideoWaitQueue.push(pTaskMessage);
VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
if(*iterIdCheck ==pTaskMessage)
{
m_VideoRunQueue.erase(iterIdCheck);
break;
}
}
}
dwRepeatedTimes++;
pTaskMessage->SetRepeatedTimes( dwRepeatedTimes);
}
break;
}
}
if(bFind)
{
(SessionManager::GetInstance()).SendAppMessage(*pResult);
}
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,则将该任务分配给该服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==VideoTs[dwTsNo].GetTsSession())
{
// printf("find ts,dwTsNo:%d,m_TransDocWaitQueue.size:%d,m_TransDocWaitQueue.empty():%d\n",dwTsNo,m_TransDocWaitQueue.size(),m_TransDocWaitQueue.empty());
if( !m_VideoWaitQueue.empty() )
{
AppTaskMessage* pTaskMessage = m_VideoWaitQueue.top( );
m_VideoWaitQueue.pop( );
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_VideoRunQueue.push_back(pTaskMessage);
VideoTs[dwTsNo].SetMessageInTs(pTaskMessage);
VideoTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
}
else
{
VideoTs[dwTsNo].SetState(TS_FREE);
VideoTs[dwTsNo].SetMessageInTs(NULL);
}
break;
}
}
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else //if(TS_MESSAGE_PRINT_SCREEN_PROGRESS_RESULT == tsTaskResultType)
{
}
}
void DsManage::OnServerLeave(TsSession &session) //服务器掉线等事件,网络断开与心跳检测失败;
{
LoggerWrapper dsLog= LoggerWrapper::GetInstance();
static int leavecount = 0;
// printf("OnServerLeave enter++++++++++++++++,count:%d\n",++leavecount);
dsLog.Log(TRUE,LOGGER_DEBUG,"OnServerLeave enter,session:%d,count:%d , [%s][%s][%d]\n",&session,++leavecount,__FILE__,__PRETTY_FUNCTION__,__LINE__);
bool bFindServer = FALSE;
//检查服务器是否有任务在处理,没有直接返回,约定底层已经close session了
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_TRANS_SERVER_NUM; dwTsNo++)
{
// printf("OnServerLeave 1111 dwTsNo:%d++++++++++++++++\n",dwTsNo);
if(&session ==DocTs[dwTsNo].GetTsSession())
{
bFindServer = TRUE;
// printf("OnServerLeave 2222 dwTsNo:%d++++++++++++++++\n",dwTsNo);
// printf("DocTs[dwTsNo].GetState():%d\n",DocTs[dwTsNo].GetState());
if(NULL == DocTs[dwTsNo].GetMessageInTs())
printf(" DocTs[dwTsNo].GetMessageInTs() is NULL\n");
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if(/*(TS_RUNNING== DocTs[dwTsNo].GetState()) &&*/(NULL != DocTs[dwTsNo].GetMessageInTs() ))
{
// printf("OnServerLeave 3333 dwTsNo:%d++++++++++++++++\n",dwTsNo);
//如果有任务处理,查找是否有可用其他同类转换服务器空闲
bool bFind = FALSE;
//如果有同类转换服务器空闲,直接将该任务分配给该服务器,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_TRANS_SERVER_NUM; dwFreeTsNo++)
{
// printf("OnServerLeave 4444 dwTsNo:%d, dwFreeTsNo:%d++++++++++++++++\n",dwTsNo,dwFreeTsNo);
if((TS_FREE== DocTs[dwFreeTsNo].GetState())&&(dwFreeTsNo != dwTsNo))
{
DocTs[dwFreeTsNo].SetMessageInTs(DocTs[dwTsNo].GetMessageInTs());
DocTs[dwFreeTsNo].SetState(TS_RUNNING);
DocTs[dwTsNo].SetState(TS_UNREGISTERED);
DocTs[dwTsNo].SetMessageInTs(NULL);
((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->SetTsNum(dwFreeTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->GetMessageId());
pTransitionRequest->SetSrcFile(((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->GetFilePrefix());
pTransitionRequest->SetTransType(((AppTaskMessage*)(DocTs[dwFreeTsNo].GetMessageInTs()))->GetMessagePara().unTransDoc.enumTansType);
DocTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
bFind = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFind)
{
// printf("OnServerLeave 555 dwTsNo:%d ++++++++++++++++\n",dwTsNo);
((AppTaskMessage*)(DocTs[dwTsNo].GetMessageInTs()))->SetPriority(9);
m_TransDocWaitQueue.push((AppTaskMessage*)(DocTs[dwTsNo].GetMessageInTs()));
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDocRunQueue.begin(); iterIdCheck!=m_TransDocRunQueue.end(); iterIdCheck++)
{
// printf("OnServerLeave 6666 dwTsNo:%d,++++++++++++++++\n",dwTsNo);
if(*iterIdCheck ==((AppTaskMessage*)(DocTs[dwTsNo].GetMessageInTs())))
{
// printf("OnServerLeave 7777 dwTsNo:%d:%d++++++++++++++++\n",dwTsNo);
m_TransDocRunQueue.erase(iterIdCheck);
break;
}
}
((AppTaskMessage*)(DocTs[dwTsNo].GetMessageInTs()))->SetTsNum(0);
}
// break;
}
DocTs[dwTsNo].SetState(TS_UNREGISTERED);
DocTs[dwTsNo].SetMessageInTs(NULL);
break;
}
}
if( TRUE == bFindServer)
{
return ;
}
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwTsNo++)
{
// printf("OnServerLeave 8888++++++++++++++++\n");
if(&session ==DocWindowsTs[dwTsNo].GetTsSession())
{
bFindServer = TRUE;
// printf("OnServerLeave 9999++++++++++++++++\n");
// printf("DocTs[dwTsNo].GetState():%d\n",PPTTs[dwTsNo].GetState());
if(NULL == DocWindowsTs[dwTsNo].GetMessageInTs())
printf(" DocWindowsTs[dwTsNo].GetMessageInTs() is NULL\n");
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if((NULL != DocWindowsTs[dwTsNo].GetMessageInTs() ))
{
// printf("OnServerLeave aaaa++++++++++++++++\n");
//如果有任务处理,查找是否有可用其他同类转换服务器空闲
bool bFind = FALSE;
//如果有同类转换服务器空闲,直接将该任务分配给该服务器,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwFreeTsNo++)
{
// printf("OnServerLeave bbbbb++++++++++++++++\n");
if((TS_FREE== DocWindowsTs[dwFreeTsNo].GetState())&&(dwFreeTsNo != dwTsNo))
{
DocWindowsTs[dwFreeTsNo].SetMessageInTs(DocWindowsTs[dwTsNo].GetMessageInTs());
DocWindowsTs[dwFreeTsNo].SetState(TS_RUNNING);
DocWindowsTs[dwTsNo].SetState(TS_UNREGISTERED);
DocWindowsTs[dwTsNo].SetMessageInTs(NULL);
((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->SetTsNum(dwFreeTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->GetMessageId());
pTransitionRequest->SetSrcFile(((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->GetFilePrefix());
pTransitionRequest->SetTransType(((AppTaskMessage*)(DocWindowsTs[dwFreeTsNo].GetMessageInTs()))->GetMessagePara().unTransDoc.enumTansType);
DocWindowsTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
bFind = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFind)
{
// printf("OnServerLeave cccc++++++++++++++++\n");
((AppTaskMessage*)(DocWindowsTs[dwTsNo].GetMessageInTs()))->SetPriority(9);
m_TransDocWindowsWaitQueue.push((AppTaskMessage*)(DocWindowsTs[dwTsNo].GetMessageInTs()));
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDocWindowsRunQueue.begin(); iterIdCheck!=m_TransDocWindowsRunQueue.end(); iterIdCheck++)
{
// printf("OnServerLeave dddd++++++++++++++++\n");
if(*iterIdCheck ==((AppTaskMessage*)(DocWindowsTs[dwTsNo].GetMessageInTs())))
{
// printf("OnServerLeave eeeee++++++++++++++++\n");
m_TransDocWindowsRunQueue.erase(iterIdCheck);
break;
}
}
((AppTaskMessage*)(DocWindowsTs[dwTsNo].GetMessageInTs()))->SetTsNum(0);
}
// break;
}
DocWindowsTs[dwTsNo].SetState(TS_UNREGISTERED);
DocWindowsTs[dwTsNo].SetMessageInTs(NULL);
break;
}
}
if( TRUE == bFindServer)
{
return ;
}
for(u32 dwTsNo =1; dwTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwTsNo++)
{
// printf("OnServerLeave 8888++++++++++++++++\n");
if(&session ==PPTTs[dwTsNo].GetTsSession())
{
bFindServer = TRUE;
// printf("OnServerLeave 9999++++++++++++++++\n");
// printf("DocTs[dwTsNo].GetState():%d\n",PPTTs[dwTsNo].GetState());
if(NULL == PPTTs[dwTsNo].GetMessageInTs())
printf(" PPTTs[dwTsNo].GetMessageInTs() is NULL\n");
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if(/*(TS_RUNNING== PPTTs[dwTsNo].GetState()) &&*/(NULL != PPTTs[dwTsNo].GetMessageInTs() ))
{
// printf("OnServerLeave aaaa++++++++++++++++\n");
//如果有任务处理,查找是否有可用其他同类转换服务器空闲
bool bFind = FALSE;
//如果有同类转换服务器空闲,直接将该任务分配给该服务器,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwFreeTsNo++)
{
// printf("OnServerLeave bbbbb++++++++++++++++\n");
if((TS_FREE== PPTTs[dwFreeTsNo].GetState())&&(dwFreeTsNo != dwTsNo))
{
PPTTs[dwFreeTsNo].SetMessageInTs(PPTTs[dwTsNo].GetMessageInTs());
PPTTs[dwFreeTsNo].SetState(TS_RUNNING);
PPTTs[dwTsNo].SetState(TS_UNREGISTERED);
PPTTs[dwTsNo].SetMessageInTs(NULL);
((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->SetTsNum(dwFreeTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->GetMessageId());
pTransitionRequest->SetSrcFile(((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->GetFilePrefix());
pTransitionRequest->SetTransType(((AppTaskMessage*)(PPTTs[dwFreeTsNo].GetMessageInTs()))->GetMessagePara().unTransDoc.enumTansType);
PPTTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
bFind = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFind)
{
// printf("OnServerLeave cccc++++++++++++++++\n");
((AppTaskMessage*)(PPTTs[dwTsNo].GetMessageInTs()))->SetPriority(9);
m_TransDynamicPptWaitQueue.push((AppTaskMessage*)(PPTTs[dwTsNo].GetMessageInTs()));
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_TransDynamicPptRunQueue.begin(); iterIdCheck!=m_TransDynamicPptRunQueue.end(); iterIdCheck++)
{
// printf("OnServerLeave dddd++++++++++++++++\n");
if(*iterIdCheck ==((AppTaskMessage*)(PPTTs[dwTsNo].GetMessageInTs())))
{
// printf("OnServerLeave eeeee++++++++++++++++\n");
m_TransDynamicPptRunQueue.erase(iterIdCheck);
break;
}
}
((AppTaskMessage*)(PPTTs[dwTsNo].GetMessageInTs()))->SetTsNum(0);
}
// break;
}
PPTTs[dwTsNo].SetState(TS_UNREGISTERED);
PPTTs[dwTsNo].SetMessageInTs(NULL);
break;
}
}
if( TRUE == bFindServer)
{
return ;
}
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
if(&session ==VideoTs[dwTsNo].GetTsSession())
{
bFindServer = TRUE;
if(NULL == VideoTs[dwTsNo].GetMessageInTs())
printf(" VideoTs[dwTsNo].GetMessageInTs() is NULL\n");
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if((NULL != VideoTs[dwTsNo].GetMessageInTs() ))
{
//如果有任务处理,查找是否有可用其他同类转换服务器空闲
bool bFind = FALSE;
//如果有同类转换服务器空闲,直接将该任务分配给该服务器,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== VideoTs[dwFreeTsNo].GetState())&&(dwFreeTsNo != dwTsNo))
{
VideoTs[dwFreeTsNo].SetMessageInTs(VideoTs[dwTsNo].GetMessageInTs());
VideoTs[dwFreeTsNo].SetState(TS_RUNNING);
VideoTs[dwTsNo].SetState(TS_UNREGISTERED);
VideoTs[dwTsNo].SetMessageInTs(NULL);
((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->SetTsNum(dwFreeTsNo);
#if 0
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->GetMessageId());
pTransitionRequest->SetSrcFile(((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->GetFilePrefix());
pTransitionRequest->SetTransType(((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()))->GetMessagePara().unTransDoc.enumTansType);
VideoTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
#endif
AppTaskMessage* pAppTaskMessage = ((AppTaskMessage*)(VideoTs[dwFreeTsNo].GetMessageInTs()));
if(APP_MESSAGE_VIDEO_TRANS_TASK == pAppTaskMessage->GetAppMessageType())
{
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pAppTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pAppTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pAppTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pAppTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pAppTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pAppTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pAppTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
break;
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == pAppTaskMessage->GetAppMessageType())
{
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pAppTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pAppTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pAppTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pAppTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pAppTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pAppTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pAppTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
}
else //if(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType)
{
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pAppTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pAppTaskMessage->GetFullPathFileName());
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
}
bFind = TRUE;
break;
}
}
//如果没有转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列,并从运行队列删除
if(FALSE == bFind)
{
// printf("OnServerLeave 555 dwTsNo:%d ++++++++++++++++\n",dwTsNo);
((AppTaskMessage*)(VideoTs[dwTsNo].GetMessageInTs()))->SetPriority(9);
m_VideoWaitQueue.push((AppTaskMessage*)(VideoTs[dwTsNo].GetMessageInTs()));
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
// printf("OnServerLeave 6666 dwTsNo:%d,++++++++++++++++\n",dwTsNo);
if(*iterIdCheck ==((AppTaskMessage*)(VideoTs[dwTsNo].GetMessageInTs())))
{
m_VideoRunQueue.erase(iterIdCheck);
break;
}
}
((AppTaskMessage*)(VideoTs[dwTsNo].GetMessageInTs()))->SetTsNum(0);
}
// break;
}
VideoTs[dwTsNo].SetState(TS_UNREGISTERED);
VideoTs[dwTsNo].SetMessageInTs(NULL);
break;
}
}
}
void DsManage::OnSessionError(TsSession &session) //协议解析失败等,一般仅仅需要关闭session
{
LoggerWrapper dsLog= LoggerWrapper::GetInstance();
dsLog.Log(TRUE,LOGGER_DEBUG,"OnSessionError enter,session:%d , [%s][%s][%d]\n",&session,__FILE__,__PRETTY_FUNCTION__,__LINE__);
// printf("OnSessionError enter++++++++++++++++\n");
OnServerLeave(session);
//关闭本session
session.Close();
}
void DsManage::OnNewTask(AppTaskMessage &taskInfo)
{
string strMessageId = taskInfo.GetMessageId();
//首先检查该任务是否已在运行列表或者等待列表,如果已存在,给应用客户端返回错误码,并返回
bool bFind = FALSE;
bool bFree = FALSE;
LoggerWrapper dsLog= LoggerWrapper::GetInstance();
// g_Dslogger = Logger::getLogger("DsManage::OnNewTask");
static int count =0;
count ++;
dsLog.Log(TRUE,LOGGER_DEBUG,"OnNewTask,count:%d , [%s][%s][%d]\n",count,__FILE__,__PRETTY_FUNCTION__,__LINE__);
// printf("OnNewTask,count:%d\n",count);
AppMessageType tAppMessageType = taskInfo.GetAppMessageType();
if(APP_MESSAGE_DOC_TRANS_TASK == tAppMessageType)
{
TaskMessageList::const_iterator iterIdCheck;
for (iterIdCheck=m_TransDocRunQueue.begin(); iterIdCheck!=m_TransDocRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
break;
}
}
if(FALSE == bFind)
{
AppTaskMessage* pTaskMessage;
TaskMessagePriorityQueue tmpQueue;
while ( !m_TransDocWaitQueue.empty() )
{
pTaskMessage = m_TransDocWaitQueue.top( );
m_TransDocWaitQueue.pop( );
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
}
tmpQueue.push( pTaskMessage );
}
while ( !tmpQueue.empty() )
{
pTaskMessage = tmpQueue.top( );
tmpQueue.pop( );
m_TransDocWaitQueue.push(pTaskMessage );
}
}
//检查是否在windows文档转换列表中
for (iterIdCheck=m_TransDocWindowsRunQueue.begin(); iterIdCheck!=m_TransDocWindowsRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
break;
}
}
if(FALSE == bFind)
{
AppTaskMessage* pTaskMessage;
TaskMessagePriorityQueue tmpQueue;
while ( !m_TransDocWindowsWaitQueue.empty() )
{
pTaskMessage = m_TransDocWindowsWaitQueue.top( );
m_TransDocWindowsWaitQueue.pop( );
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
}
tmpQueue.push( pTaskMessage );
}
while ( !tmpQueue.empty() )
{
pTaskMessage = tmpQueue.top( );
tmpQueue.pop( );
m_TransDocWindowsWaitQueue.push(pTaskMessage );
}
}
if(TRUE == bFind)
{
//发送错误信息给应用客户端
AppDocTransResultMessage* pResult = new AppDocTransResultMessage;
pResult->SetMessageId(taskInfo.GetMessageId());
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_REPEATED_TS_TRANS_TASK);
pResult->SetAppTargetIp(taskInfo.GetIpAddr());
pResult->SetAppTargetPort(taskInfo.GetPort());
(SessionManager::GetInstance()).SendAppMessage(*pResult);
dsLog.Log(TRUE,LOGGER_ERROR,"error message from application client. Repeated Message ID:%s , [%s][%s][%d]\n",taskInfo.GetMessageId().c_str(),__FILE__,__PRETTY_FUNCTION__,__LINE__);
// LOG4CXX_ERROR(g_Dslogger, "error message from application client. Repeated Message ID: ");
// LOG4CXX_ERROR(g_Dslogger, taskInfo.GetMessageId());
if(NULL != pResult )
{
delete pResult;
pResult = NULL;
}
return;
}
//分发服务器创建一个消息任务的拷贝,避免下层上报的消息在函数返回后被销毁
// printf("000 target:%s,prefix:%s,type:%d\n",taskInfo.GetTargetFullPathFileName().c_str(),taskInfo.GetFilePrefix().c_str(),taskInfo.GetMessagePara().unTransDoc.enumTansType);
AppTaskMessage* pNewAppTaskMessage;
MessageNew(&pNewAppTaskMessage);
memcpy(pNewAppTaskMessage,&taskInfo,sizeof(AppTaskMessage));
// printf("111 target:%s,prefix:%s,type:%d\n",pNewAppTaskMessage->GetTargetFullPathFileName().c_str(),pNewAppTaskMessage->GetFilePrefix().c_str(),pNewAppTaskMessage->GetMessagePara().unTransDoc.enumTansType);
//再检查是否有空闲的转换服务器?
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_TRANS_SERVER_NUM; dwTsNo++)
{
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if(TS_FREE == DocTs[dwTsNo].GetState())
{
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pNewAppTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDocRunQueue.push_back(pNewAppTaskMessage);
bFree = TRUE;
DocTs[dwTsNo].SetMessageInTs(pNewAppTaskMessage);
DocTs[dwTsNo].SetState(TS_RUNNING);
pNewAppTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pNewAppTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pNewAppTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pNewAppTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pNewAppTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pNewAppTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("222 target:%s,prefix:%s\n",pTransitionRequest->GetTargetFolder().c_str(),pTransitionRequest->GetPrefix().c_str());
DocTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
break;
}
}
//如果没有空闲的转换服务器,将该任务加入等待列表
if(FALSE == bFree)
{
m_TransDocWaitQueue.push(pNewAppTaskMessage);
// AppTaskMessage* p=m_TransDocWaitQueue.top();
// printf("333 target:%s,prefix:%s,type:%d\n",p->GetTargetFullPathFileName().c_str(),p->GetFilePrefix().c_str(),p->GetMessagePara().unTransDoc.enumTansType);
printf("m_TransDocWaitQueue.size:%d\n",m_TransDocWaitQueue.size());
}
}
else if((APP_MESSAGE_VIDEO_TRANS_TASK == tAppMessageType)||(APP_MESSAGE_VIDEO_CAPTURE_TASK == tAppMessageType)||(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType))
{
TaskMessageList::const_iterator iterIdCheck;
for (iterIdCheck=m_VideoRunQueue.begin(); iterIdCheck!=m_VideoRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
break;
}
}
if(FALSE == bFind)
{
AppTaskMessage* pTaskMessage;
TaskMessagePriorityQueue tmpQueue;
while ( !m_VideoWaitQueue.empty() )
{
pTaskMessage = m_VideoWaitQueue.top( );
m_VideoWaitQueue.pop( );
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
}
tmpQueue.push( pTaskMessage );
}
while ( !tmpQueue.empty() )
{
pTaskMessage = tmpQueue.top( );
tmpQueue.pop( );
m_VideoWaitQueue.push(pTaskMessage );
}
}
if(TRUE == bFind)
{
//发送错误信息给应用客户端
if(APP_MESSAGE_VIDEO_TRANS_TASK == tAppMessageType)
{
AppVideoTransResultMessage* pResult = new AppVideoTransResultMessage;
pResult->SetMessageId(taskInfo.GetMessageId());
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_REPEATED_TS_TRANS_TASK);
pResult->SetAppTargetIp(taskInfo.GetIpAddr());
pResult->SetAppTargetPort(taskInfo.GetPort());
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == tAppMessageType)
{
AppVideoCaptureResultMessage* pResult = new AppVideoCaptureResultMessage;
pResult->SetMessageId(taskInfo.GetMessageId());
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_REPEATED_TS_TRANS_TASK);
pResult->SetAppTargetIp(taskInfo.GetIpAddr());
pResult->SetAppTargetPort(taskInfo.GetPort());
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
else //if(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType)
{
AppVideoInfoResultMessage* pResult = new AppVideoInfoResultMessage;
pResult->SetMessageId(taskInfo.GetMessageId());
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_REPEATED_TS_TRANS_TASK);
pResult->SetAppTargetIp(taskInfo.GetIpAddr());
pResult->SetAppTargetPort(taskInfo.GetPort());
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
}
dsLog.Log(TRUE,LOGGER_ERROR,"error message from application client. Repeated Message ID:%s , [%s][%s][%d]\n",taskInfo.GetMessageId().c_str(),__FILE__,__PRETTY_FUNCTION__,__LINE__);
return;
}
//分发服务器创建一个消息任务的拷贝,避免下层上报的消息在函数返回后被销毁
// printf("000 target:%s,prefix:%s,type:%d\n",taskInfo.GetTargetFullPathFileName().c_str(),taskInfo.GetFilePrefix().c_str(),taskInfo.GetMessagePara().unTransDoc.enumTansType);
AppTaskMessage* pNewAppTaskMessage;
MessageNew(&pNewAppTaskMessage);
memcpy(pNewAppTaskMessage,&taskInfo,sizeof(AppTaskMessage));
// printf("111 target:%s,prefix:%s,type:%d\n",pNewAppTaskMessage->GetTargetFullPathFileName().c_str(),pNewAppTaskMessage->GetFilePrefix().c_str(),pNewAppTaskMessage->GetMessagePara().unTransDoc.enumTansType);
//再检查是否有空闲的转换服务器?
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if(TS_FREE == VideoTs[dwTsNo].GetState())
{
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pNewAppTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_VideoRunQueue.push_back(pNewAppTaskMessage);
bFree = TRUE;
VideoTs[dwTsNo].SetMessageInTs(pNewAppTaskMessage);
VideoTs[dwTsNo].SetState(TS_RUNNING);
pNewAppTaskMessage->SetTsNum(dwTsNo);
if(APP_MESSAGE_VIDEO_TRANS_TASK == tAppMessageType)
{
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pNewAppTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pNewAppTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pNewAppTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pNewAppTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pNewAppTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pNewAppTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pNewAppTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
break;
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == tAppMessageType)
{
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pNewAppTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pNewAppTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pNewAppTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pNewAppTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pNewAppTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pNewAppTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pNewAppTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
break;
}
else //if(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType)
{
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pNewAppTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pNewAppTaskMessage->GetFullPathFileName());
VideoTs[dwTsNo].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
break;
}
}
}
//如果没有空闲的转换服务器,将该任务加入等待列表
if(FALSE == bFree)
{
m_VideoWaitQueue.push(pNewAppTaskMessage);
// AppTaskMessage* p=m_TransDocWaitQueue.top();
// printf("333 target:%s,prefix:%s,type:%d\n",p->GetTargetFullPathFileName().c_str(),p->GetFilePrefix().c_str(),p->GetMessagePara().unTransDoc.enumTansType);
printf("m_VideoWaitQueue.size:%d\n",m_VideoWaitQueue.size());
}
}
else if(APP_MESSAGE_DYNAMIC_PPT_TRANS_TASK == tAppMessageType)
{
TaskMessageList::const_iterator iterIdCheck;
for (iterIdCheck=m_TransDynamicPptRunQueue.begin(); iterIdCheck!=m_TransDynamicPptRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
break;
}
}
if(FALSE == bFind)
{
AppTaskMessage* pTaskMessage;
TaskMessagePriorityQueue tmpQueue;
while ( !m_TransDynamicPptWaitQueue.empty() )
{
pTaskMessage = m_TransDynamicPptWaitQueue.top( );
m_TransDynamicPptWaitQueue.pop( );
if(pTaskMessage->GetMessageId() == strMessageId)
{
bFind = TRUE;
}
tmpQueue.push( pTaskMessage );
}
while ( !tmpQueue.empty() )
{
pTaskMessage = tmpQueue.top( );
tmpQueue.pop( );
m_TransDynamicPptWaitQueue.push(pTaskMessage );
}
}
if(TRUE == bFind)
{
//发送错误信息给应用客户端
//后面跟应用定了协议之后需要创建新的动态PPT的类
AppDynamicPptTransResultMessage* pResult = new AppDynamicPptTransResultMessage;
pResult->SetMessageId(taskInfo.GetMessageId());
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_REPEATED_TS_TRANS_TASK);
pResult->SetAppTargetIp(taskInfo.GetIpAddr());
pResult->SetAppTargetPort(taskInfo.GetPort());
(SessionManager::GetInstance()).SendAppMessage(*pResult);
dsLog.Log(TRUE,LOGGER_ERROR,"error message from application client. Repeated Message ID:%s , [%s][%s][%d]\n",taskInfo.GetMessageId().c_str(),__FILE__,__PRETTY_FUNCTION__,__LINE__);
// LOG4CXX_ERROR(g_Dslogger, "error message from application client. Repeated Message ID: ");
// LOG4CXX_ERROR(g_Dslogger, taskInfo.GetMessageId());
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
return;
}
//分发服务器创建一个消息任务的拷贝,避免下层上报的消息在函数返回后被销毁
// printf("aaaa target:%s,prefix:%s,type:%d\n",taskInfo.GetTargetFullPathFileName().c_str(),taskInfo.GetFilePrefix().c_str(),taskInfo.GetMessagePara().unTransDoc.enumTansType);
AppTaskMessage* pNewAppTaskMessage;
MessageNew(&pNewAppTaskMessage);
memcpy(pNewAppTaskMessage,&taskInfo,sizeof(AppTaskMessage));
// printf("bbb target:%s,prefix:%s,type:%d\n",pNewAppTaskMessage->GetTargetFullPathFileName().c_str(),pNewAppTaskMessage->GetFilePrefix().c_str(),pNewAppTaskMessage->GetMessagePara().unTransDoc.enumTansType);
//再检查是否有空闲的转换服务器?
for(u32 dwTsNo =1; dwTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwTsNo++)
{
// printf("PPTTs[dwTsNo].GetState():%d,dwTsNo:%d\n",PPTTs[dwTsNo].GetState(),dwTsNo);
//如果有空闲的转换服务器,将该任务提交到转换服务器,发送消息给转换服务器,并将它加入运行列表
if(TS_FREE == PPTTs[dwTsNo].GetState())
{
// printf("find free ppt server dwtsno:%d\n",dwTsNo);
TaskTimeInfo tTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return;
}
pNewAppTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
m_TransDynamicPptRunQueue.push_back(pNewAppTaskMessage);
bFree = TRUE;
PPTTs[dwTsNo].SetMessageInTs(pNewAppTaskMessage);
PPTTs[dwTsNo].SetState(TS_RUNNING);
pNewAppTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pNewAppTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pNewAppTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pNewAppTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pNewAppTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pNewAppTaskMessage->GetMessagePara().unTransDoc.enumTansType);
// printf("ccc target:%s,prefix:%s\n",pTransitionRequest->GetTargetFolder().c_str(),pTransitionRequest->GetPrefix().c_str());
PPTTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
break;
}
}
//如果没有空闲的转换服务器,将该任务加入等待列表
if(FALSE == bFree)
{
m_TransDynamicPptWaitQueue.push(pNewAppTaskMessage);
AppTaskMessage* p=m_TransDynamicPptWaitQueue.top();
// printf("dddd target:%s,prefix:%s,type:%d\n",p->GetTargetFullPathFileName().c_str(),p->GetFilePrefix().c_str(),p->GetMessagePara().unTransDoc.enumTansType);
// printf("m_TransDocWaitQueue.size:%d\n",m_TransDynamicPptWaitQueue.size());
}
}
else
{
//error
}
}
s32 DsManage::OnTimer()
{
//初始化是否存在四种队列超时任务
bool bFindPPT = FALSE;
bool bFindVideo = FALSE;
bool bFindDoc = FALSE;
bool bFindDocWindows = FALSE;
TaskTimeInfo tTaskTimeInfo;
if(FALSE == DsGetTimeInfo(&tTaskTimeInfo))
{
return -1;
}
//检查视频转换列表
TaskMessageList::iterator iterIdCheck;
for (iterIdCheck=g_cDsManage.m_VideoRunQueue.begin(); iterIdCheck!=g_cDsManage.m_VideoRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
string strMessageId;
if(MAX_VIDEO_TASK_TIMEOUT_MINUTES == (((tTaskTimeInfo.m_wHour)*60+tTaskTimeInfo.m_wMinute)-((pTaskMessage->GetTaskTimeInfo()->m_wHour)*60+pTaskMessage->GetTaskTimeInfo()->m_wMinute)))
{
bFindVideo= TRUE;
AppMessageType tAppMessageType = pTaskMessage->GetAppMessageType();
if(APP_MESSAGE_VIDEO_TRANS_TASK == tAppMessageType)
{
AppVideoTransResultMessage* pResult = new AppVideoTransResultMessage;
//报告失败
//连接和发送转换结果给应用客户端
strMessageId = pTaskMessage->GetMessageId();
pResult->SetMessageId(strMessageId);
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_EXCUTE_TASK_TIMEOUT);
pResult->SetTargetFullPathFileName("");
//根据转换结果执行相应处理
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
}
else
{
//error
}
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
g_cDsManage.m_FreeMessageQueue.push_back(pTaskMessage);
g_cDsManage.m_VideoRunQueue.erase(iterIdCheck);
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
break;
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == tAppMessageType)
{
AppVideoCaptureResultMessage* pResult = new AppVideoCaptureResultMessage;
//报告失败
//连接和发送转换结果给应用客户端
strMessageId = pTaskMessage->GetMessageId();
pResult->SetMessageId(strMessageId);
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_EXCUTE_TASK_TIMEOUT);
pResult->SetCount(0);
//根据转换结果执行相应处理
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
}
else
{
//error
}
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
g_cDsManage.m_FreeMessageQueue.push_back(pTaskMessage);
g_cDsManage.m_VideoRunQueue.erase(iterIdCheck);
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
break;
}
else if(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType)
{
AppVideoInfoResultMessage* pResult = new AppVideoInfoResultMessage;
//报告失败
//连接和发送转换结果给应用客户端
strMessageId = pTaskMessage->GetMessageId();
pResult->SetMessageId(strMessageId);
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_EXCUTE_TASK_TIMEOUT);
pResult->SetDuration(0);
pResult->SetResolution("");
pResult->SetAudioCode("");
pResult->SetVideoCode("");
pResult->SetAudioTrack("");
pResult->SetVideoType("");
pResult->SetFrameRate(0);
pResult->SetBitRate(0);
//根据转换结果执行相应处理
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
}
else
{
//error
}
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.VideoTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
g_cDsManage.m_FreeMessageQueue.push_back(pTaskMessage);
g_cDsManage.m_VideoRunQueue.erase(iterIdCheck);
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
break;
}
else
{
//错误日志
}
}
}
if(TRUE == bFindVideo)
{
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,为其分配一个可用的空闲服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
if( !g_cDsManage.m_VideoWaitQueue.empty() )
{
for(u32 dwTsNo =1; dwTsNo <MAX_VIDEO_TRANS_SERVER_NUM; dwTsNo++)
{
if(TS_FREE == g_cDsManage.VideoTs[dwTsNo].GetState())
{
AppTaskMessage* pTaskMessage = g_cDsManage.m_VideoWaitQueue.top( );
AppMessageType tAppMessageType = pTaskMessage->GetAppMessageType();
g_cDsManage.m_VideoWaitQueue.pop( );
//设置时间
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
g_cDsManage.m_VideoRunQueue.push_back(pTaskMessage);
g_cDsManage.VideoTs[dwTsNo].SetMessageInTs(pTaskMessage);
g_cDsManage.VideoTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
if(APP_MESSAGE_VIDEO_TRANS_TASK == tAppMessageType)
{
TransVideoRequest* pTransVideoRequest = new TransVideoRequest;
pTransVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
char cFormat[100];
sprintf(cFormat, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwFormat);
pTransVideoRequest->SetFormat(cFormat);
char cBitRate[100];
sprintf(cBitRate, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwBitrate);
pTransVideoRequest->SetBitRate(cBitRate);
char cWidth[100];
char cHeight[100];
string strWidth,strHeight,strResolution;
sprintf(cWidth, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionWidth);
sprintf(cHeight, "%d", pTaskMessage->GetMessagePara().unTransVideo.dwResolutionHeight);
strWidth = cWidth;
strHeight = cHeight;
strResolution = strWidth +"*"+strHeight;
pTransVideoRequest->SetResolution(strResolution);
g_cDsManage.VideoTs[dwTsNo].GetTsSession()->SendMessage(*pTransVideoRequest);
if(NULL != pTransVideoRequest)
{
delete pTransVideoRequest;
pTransVideoRequest = NULL;
}
}
else if(APP_MESSAGE_VIDEO_CAPTURE_TASK == tAppMessageType)
{
CapVideoRequest* pCapVideoRequest = new CapVideoRequest;
pCapVideoRequest->SetMessageId(pTaskMessage->GetMessageId());
pCapVideoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pCapVideoRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pCapVideoRequest->SetPrefix(pTaskMessage->GetFilePrefix());
char cStart[100];
sprintf(cStart, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwStartTIme);
pCapVideoRequest->SetStart(cStart);
char cCount[100];
sprintf(cCount, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwPhotoCount);
pCapVideoRequest->SetCount(cCount);
char cInterval[100];
sprintf(cInterval, "%d", pTaskMessage->GetMessagePara().unCapVideo.dwSustainedTime);
pCapVideoRequest->SetInterval(cInterval);
g_cDsManage.VideoTs[dwTsNo].GetTsSession()->SendMessage(*pCapVideoRequest);
if(NULL != pCapVideoRequest)
{
delete pCapVideoRequest;
pCapVideoRequest = NULL;
}
}
else //if(APP_MESSAGE_VIDEO_INFO_TASK == tAppMessageType)
{
GetVideoInfoRequest* pVideoInfoRequest = new GetVideoInfoRequest;
pVideoInfoRequest->SetMessageId(pTaskMessage->GetMessageId());
pVideoInfoRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
g_cDsManage.VideoTs[dwTsNo].GetTsSession()->SendMessage(*pVideoInfoRequest);
if(NULL != pVideoInfoRequest)
{
delete pVideoInfoRequest;
pVideoInfoRequest = NULL;
}
}
break;
}
}
}
}
//检查动态ppt 列表
for (iterIdCheck=g_cDsManage.m_TransDynamicPptRunQueue.begin(); iterIdCheck!=g_cDsManage.m_TransDynamicPptRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
string strMessageId;
if(MAX_DYNAMIC_PPT_TASK_TIMEOUT_MINUTES <= (((tTaskTimeInfo.m_wHour)*60+tTaskTimeInfo.m_wMinute)-((pTaskMessage->GetTaskTimeInfo()->m_wHour)*60+pTaskMessage->GetTaskTimeInfo()->m_wMinute)))
{
bFindPPT = TRUE;
//报告失败
AppDynamicPptTransResultMessage* pResult = new AppDynamicPptTransResultMessage;
//连接和发送转换结果给应用客户端
strMessageId = pTaskMessage->GetMessageId();
pResult->SetMessageId(strMessageId);
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_EXCUTE_TASK_TIMEOUT);
pResult->SetPages(0);
//根据转换结果执行相应处理
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
}
else
{
//error
}
g_cDsManage.PPTTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.PPTTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
g_cDsManage.m_FreeMessageQueue.push_back(pTaskMessage);
g_cDsManage.m_TransDynamicPptRunQueue.erase(iterIdCheck);
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
break;
}
}
if(TRUE == bFindPPT)
{
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,为其分配一个可用的空闲服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
if( !g_cDsManage.m_TransDynamicPptWaitQueue.empty() )
{
for(u32 dwTsNo =1; dwTsNo <MAX_DANAMIC_PPT_TRANS_SERVER_NUM; dwTsNo++)
{
if(TS_FREE == g_cDsManage.PPTTs[dwTsNo].GetState())
{
AppTaskMessage* pTaskMessage = g_cDsManage.m_TransDynamicPptWaitQueue.top( );
g_cDsManage.m_TransDynamicPptWaitQueue.pop( );
//设置时间
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
g_cDsManage.m_TransDynamicPptRunQueue.push_back(pTaskMessage);
g_cDsManage.PPTTs[dwTsNo].SetMessageInTs(pTaskMessage);
g_cDsManage.PPTTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
g_cDsManage.PPTTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
break;
}
}
}
}
//检查linux文档转换列表
for (iterIdCheck=g_cDsManage.m_TransDocRunQueue.begin(); iterIdCheck!=g_cDsManage.m_TransDocRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
string strMessageId;
if(MAX_DOC_TASK_TIMEOUT_MINUTES <= (((tTaskTimeInfo.m_wHour)*60+tTaskTimeInfo.m_wMinute)-((pTaskMessage->GetTaskTimeInfo()->m_wHour)*60+pTaskMessage->GetTaskTimeInfo()->m_wMinute)))
{
bFindDoc = TRUE;
//将该任务交给windows版本文档转换处理,同时从运行队列删除
bool bFindWindows = FALSE;
//查找是否存在空闲windows 转换服务器,如果找到,把任务交给它重新处理,并添加到运行队列中,发送任务消息给相关服务器
for(u32 dwFreeTsNo =1; dwFreeTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwFreeTsNo++)
{
if((TS_FREE== g_cDsManage.DocWindowsTs[dwFreeTsNo].GetState()))
{
g_cDsManage.DocWindowsTs[dwFreeTsNo].SetMessageInTs(pTaskMessage);
g_cDsManage.DocWindowsTs[dwFreeTsNo].SetState(TS_RUNNING);
g_cDsManage.DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
g_cDsManage.DocWindowsTs[dwFreeTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
pTaskMessage->SetTsNum(dwFreeTsNo);
bFindWindows = TRUE;
//将该任务添加到windows版本文档转换运行队列中
TaskTimeInfo tNewTaskTimeInfo ;
if(FALSE == DsGetTimeInfo(&tNewTaskTimeInfo))
{
return -1;
}
pTaskMessage->SetTaskTimeInfo(tNewTaskTimeInfo);
g_cDsManage.m_TransDocWindowsRunQueue.push_back(pTaskMessage);
break;
}
}
//如果没有windows 转换服务器空闲,则提升该任务优先级到最高,将该任务加入等待队列
if(FALSE == bFindWindows)
{
pTaskMessage->SetPriority(9);
g_cDsManage.m_TransDocWindowsWaitQueue.push(pTaskMessage);
}
//将该任务从linux版文档转换服务器运行队列移除
g_cDsManage.DocTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.DocTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
g_cDsManage.m_TransDocRunQueue.erase(iterIdCheck);
break;
}
}
if(TRUE == bFindDoc)
{
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,为其分配一个可用的空闲服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
if( !g_cDsManage.m_TransDocWaitQueue.empty() )
{
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_TRANS_SERVER_NUM; dwTsNo++)
{
if(TS_FREE == g_cDsManage.DocTs[dwTsNo].GetState())
{
AppTaskMessage* pTaskMessage = g_cDsManage.m_TransDocWaitQueue.top( );
g_cDsManage.m_TransDocWaitQueue.pop( );
//设置时间
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
g_cDsManage.m_TransDocRunQueue.push_back(pTaskMessage);
g_cDsManage.DocTs[dwTsNo].SetMessageInTs(pTaskMessage);
g_cDsManage.DocTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
g_cDsManage.DocTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
break;
}
}
}
}
//检查windows文档转换列表
for (iterIdCheck=g_cDsManage.m_TransDocWindowsRunQueue.begin(); iterIdCheck!=g_cDsManage.m_TransDocWindowsRunQueue.end(); iterIdCheck++)
{
AppTaskMessage* pTaskMessage = *iterIdCheck;
string strMessageId;
if(MAX_DOC_TASK_TIMEOUT_MINUTES <= (((tTaskTimeInfo.m_wHour)*60+tTaskTimeInfo.m_wMinute)-((pTaskMessage->GetTaskTimeInfo()->m_wHour)*60+pTaskMessage->GetTaskTimeInfo()->m_wMinute)))
{
bFindDocWindows = TRUE;
//报告失败
AppDocTransResultMessage* pResult = new AppDocTransResultMessage;
//连接和发送转换结果给应用客户端
strMessageId = pTaskMessage->GetMessageId();
pResult->SetMessageId(strMessageId);
pResult->SetResult(FALSE);
pResult->SetErrorCode(RET_E_EXCUTE_TASK_TIMEOUT);
pResult->SetPages(0);
//根据转换结果执行相应处理
string strAppTargetIp;
u32 dwAppTargetPort;
if(pTaskMessage->GetAppTargetInfo(strAppTargetIp,dwAppTargetPort))
{
pResult->SetAppTargetIp(strAppTargetIp);
pResult->SetAppTargetPort(dwAppTargetPort);
}
else
{
//error
}
g_cDsManage.DocWindowsTs[pTaskMessage->GetTsNum()].SetState(TS_FREE);
g_cDsManage.DocWindowsTs[pTaskMessage->GetTsNum()].SetMessageInTs(NULL);
//将该任务从运行队列移除,并归还给空闲队列
pTaskMessage->Initialize();
g_cDsManage.m_FreeMessageQueue.push_back(pTaskMessage);
g_cDsManage.m_TransDocWindowsRunQueue.erase(iterIdCheck);
(SessionManager::GetInstance()).SendAppMessage(*pResult);
if(NULL != pResult)
{
delete pResult;
pResult = NULL;
}
break;
}
}
if(TRUE == bFindDocWindows)
{
//检查任务等待队列是否有转换任务在等待,没有则直接返回
//如果有,为其分配一个可用的空闲服务器,并发送转换命令给转换服务器,同时将该任务添加到运行队列
if( !g_cDsManage.m_TransDocWindowsWaitQueue.empty() )
{
for(u32 dwTsNo =1; dwTsNo <MAX_DOC_WINDOWS_TRANS_SERVER_NUM; dwTsNo++)
{
if(TS_FREE == g_cDsManage.DocWindowsTs[dwTsNo].GetState())
{
AppTaskMessage* pTaskMessage = g_cDsManage.m_TransDocWindowsWaitQueue.top( );
g_cDsManage.m_TransDocWindowsWaitQueue.pop( );
//设置时间
pTaskMessage->SetTaskTimeInfo(tTaskTimeInfo);
g_cDsManage.m_TransDocWindowsRunQueue.push_back(pTaskMessage);
g_cDsManage.DocWindowsTs[dwTsNo].SetMessageInTs(pTaskMessage);
g_cDsManage.DocWindowsTs[dwTsNo].SetState(TS_RUNNING);
pTaskMessage->SetTsNum(dwTsNo);
TransitionRequest* pTransitionRequest = new TransitionRequest;
pTransitionRequest->SetMessageId(pTaskMessage->GetMessageId());
pTransitionRequest->SetSrcFile(pTaskMessage->GetFullPathFileName());
pTransitionRequest->SetTargetFolder(pTaskMessage->GetTargetFullPathFileName());
pTransitionRequest->SetPrefix(pTaskMessage->GetFilePrefix());
pTransitionRequest->SetTransType(pTaskMessage->GetMessagePara().unTransDoc.enumTansType);
g_cDsManage.DocWindowsTs[dwTsNo].GetTsSession()->SendMessage(*pTransitionRequest);
if(NULL != pTransitionRequest)
{
delete pTransitionRequest;
pTransitionRequest = NULL;
}
break;
}
}
}
}
}