📄 vsinterpreter.cpp
字号:
若以后要实现一个通道对应一个SOURCEMONITOR窗口,就要改现在
的解释器和窗口的通讯机制,变为窗口消息传递机制,
变m_psourceMonitor为数组
*****************************************************/
int iChannelNo;
struct GDIThreadParam *pgdiThreadParam = (struct GDIThreadParam *)pParam;
//取得所监视指令文件的路径,而不是由GDITHREADPARAM取得
char aszInstructionFile[100] = "\0";
if((iChannelNo = GetPrivateProfileInt(SECTION_SCRIPT, KEY_MONITOREDCHANNEL, 0, CONFIGFILE))
== 0)
{
AfxMessageBox("Can't find MonitoredChannel Key in Setup.ini");
return -1;
}
if(GetInstructionFile(iChannelNo, aszInstructionFile) != 0)
{
AfxMessageBox("Can't find Instruction file refered by Setup.ini");
return -1;
}
CSourceMonitor *psourceMonitor = new CSourceMonitor;
if(psourceMonitor->Create(pgdiThreadParam->pvsInterpreter) == -1)
return -1;
// psourceMonitor->ShowWindow(SW_SHOWDEFAULT);
if(psourceMonitor->Run(aszInstructionFile, iChannelNo) == -1)
return -1;
psourceMonitor->ShowWindow( SW_HIDE );
CVSInterpreter *pvsInterpreter = pgdiThreadParam->pvsInterpreter;
pvsInterpreter->m_psourceMonitor = psourceMonitor;
pvsInterpreter->m_hwndSourceMonitor = psourceMonitor->m_hWnd;
//唤醒VSINTERPRETER
pgdiThreadParam->bGDIThreadRunning = TRUE;
//消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if(msg.hwnd != NULL)
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
else
{
switch(msg.message)
{
case WM_GDI_CREATEMONITOR:
if(IsWindow(psourceMonitor[iChannelNo - 1].m_hWnd))
{
ShowWindow(psourceMonitor[iChannelNo - 1].m_hWnd, SW_SHOWDEFAULT);
}
else
{
iChannelNo = (int)(msg.wParam);
CreateSourceMonitor(&(psourceMonitor[iChannelNo - 1]), (char *)(msg.lParam), iChannelNo, pvsInterpreter);
}
break;
default:
break;
}
}
}//end of while(getmessage())
return 0;
/*
CSourceMonitor *psourceMonitor = new CSourceMonitor[pgdiThreadParam->iChannelCount];
//消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if(msg.hwnd != NULL)
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
else
{
switch(msg.message)
{
case WM_GDI_CREATEMONITOR:
if(IsWindow(psourceMonitor[iChannelNo - 1].m_hWnd))
{
ShowWindow(psourceMonitor[iChannelNo - 1].m_hWnd, SW_SHOWDEFAULT);
}
else
{
iChannelNo = (int)(msg.wParam);
CreateSourceMonitor(&(psourceMonitor[iChannelNo - 1]), (char *)(msg.lParam), iChannelNo);
}
break;
default:
break;
}
}
}//end of while(getmessage())
return 0;
*/
}
//*******************end of 解释器自带的GDI线程******************************
//**********************解释器要在单独线程里创建************************
CVSInterpreter vsInterpreter;
UINT VSInterpreterThread(LPVOID pParam)
{
struct VSInterpreterThreadParam *pthreadParam = (struct VSInterpreterThreadParam *)pParam;
if(pthreadParam == NULL)
{
AfxMessageBox("vsinterpreter thread param can't be null");
return -1;
}
char aszInstructionFileName[100] = "\0";
strcpy(aszInstructionFileName, pthreadParam->aszInstructionFileName);
int iChannelCount = pthreadParam->iChannelCount;
free(pParam);
//add by lj 2003/09/15
GetIniFile();
//add end
if(vsInterpreter.Create(iChannelCount) != 0)
return 4;
if(vsInterpreter.Initialize() != 0)
return 3;
//通知其他线程解释器初始化完毕(暂时没有哪个线程需要它,SENDREQUESTTHREAD也不再需要)
HANDLE hVSI_Initialized = CreateEvent(NULL, FALSE, FALSE, NAME_VSI_INITIALIZED);
if(hVSI_Initialized == NULL)
return 2;
SetEvent(hVSI_Initialized);
//这时再创建SERVICEBROKER中的线程,因为VSI刚把队列创建好
//创建服务请求发送线程(监视应用服务队列)
AfxBeginThread( SendRequestThread, NULL );
//add by lj
int nStart = GetPrivateProfileInt("DB_START" , "start" , 0 , ".\\setup.ini");
if(nStart)
AfxBeginThread(ProcessDbRequest, NULL);
//创建TCP线程(由TCP发送服务请求和接收应答)
struct TcpThreadParam *ptcpThreadParam1 = (struct TcpThreadParam *)malloc(sizeof(struct TcpThreadParam));
strcpy(ptcpThreadParam1->aszServerDescription, SECTION_VRD);
ptcpThreadParam1->bSetTimer = TRUE; //见结构定义
AfxBeginThread( TCPThread, ptcpThreadParam1 );
//执行解释器
vsInterpreter.Run();
//创建死循环,不让这个线程释放它的资源(例如Event Handle,所有都会被释放,那么所有别的线程中的WAITFORSINGLEOBJECT都会立刻返回,若WAITFORSINGLEOBJECT在WHILE中,就会死循环)
while(1)
Sleep(1000);
return(0);
}
//**********************end of 解释器要在单独线程里创建************************
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVSInterpreter::CVSInterpreter()
{
m_pcurrentState = NULL;
// m_szInstructionFile = NULL;
// m_szSourceInstructionFile = NULL;
// m_szTempInstructionFile = NULL;
m_vsFileBufList.vsFileBuf = NULL;
m_vsFileBufList.iCount = 0;
m_iChannelCount = 0;
m_iCountOfTurnOnOfTotal_In = 0;
m_iCountOfTurnOnOfTotal_Out = 0;
m_psourceMonitor = NULL;
}
CVSInterpreter::~CVSInterpreter()
{
int i, j;
//释放所有的通道状态表
for(i = 0; i < m_iChannelCount; i ++)
{
if(m_pcurrentState == NULL)
break;
/*
在类的FreeServiceParamList的时候以被释放,因为它只是指向ReplyParamList的指针
if(m_pcurrentState[i].presultSet != NULL)
{
CResultSet::Free(m_pcurrentState[i].presultSet);
}
*/
//释放GLOBAL
if(m_pcurrentState[i].m_globalVariableList_Integer.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_globalVariableList_Integer.nCount; j ++)
{
free((m_pcurrentState[i].m_globalVariableList_Integer.Global)[j].szName);
free((m_pcurrentState[i].m_globalVariableList_Integer.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_globalVariableList_Integer.Global);
}
if(m_pcurrentState[i].m_globalVariableList_String.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_globalVariableList_String.nCount; j ++)
{
free((m_pcurrentState[i].m_globalVariableList_String.Global)[j].szName);
free((m_pcurrentState[i].m_globalVariableList_String.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_globalVariableList_String.Global);
}
if(m_pcurrentState[i].m_globalVariableList_Float.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_globalVariableList_Float.nCount; j ++)
{
free((m_pcurrentState[i].m_globalVariableList_Float.Global)[j].szName);
free((m_pcurrentState[i].m_globalVariableList_Float.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_globalVariableList_Float.Global);
}
//释放UNIVERSAL
if(m_pcurrentState[i].m_universalVariableList_Integer.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_universalVariableList_Integer.nCount; j ++)
{
free((m_pcurrentState[i].m_universalVariableList_Integer.Global)[j].szName);
free((m_pcurrentState[i].m_universalVariableList_Integer.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_universalVariableList_Integer.Global);
}
if(m_pcurrentState[i].m_universalVariableList_String.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_universalVariableList_String.nCount; j ++)
{
free((m_pcurrentState[i].m_universalVariableList_String.Global)[j].szName);
free((m_pcurrentState[i].m_universalVariableList_String.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_universalVariableList_String.Global);
}
if(m_pcurrentState[i].m_universalVariableList_Float.Global != NULL)
{
for(j = 0; j < m_pcurrentState[i].m_universalVariableList_Float.nCount; j ++)
{
free((m_pcurrentState[i].m_universalVariableList_Float.Global)[j].szName);
free((m_pcurrentState[i].m_universalVariableList_Float.Global)[j].pVariable);
}
free(m_pcurrentState[i].m_universalVariableList_Float.Global);
}
//释放VSI
free(m_pcurrentState[i].vsi.szAction);
free(m_pcurrentState[i].vsi.szInParam);
free(m_pcurrentState[i].vsi.szNext);
free(m_pcurrentState[i].vsi.szOutParam);
free(m_pcurrentState[i].vsi.szOnError);
//释放VOICELIST
}
free(m_pcurrentState);
//释放脚本文件缓冲
for(i = 0; i < m_vsFileBufList.iCount; i ++)
{
free((m_vsFileBufList.vsFileBuf)[i].szFileBuf);
}
free(m_vsFileBufList.vsFileBuf);
//其他成员
// free(m_szInstructionFile);
// free(m_szSourceInstructionFile);
// free(m_szTempInstructionFile);
if(IsWindow(m_hwndSourceMonitor))
{
delete m_psourceMonitor;
}
if(hAI2002 != NULL)
{
// if( !ExitDB() )
// AfxMessageBox("failed!");
if( g_Connected )
ExitDB();
FreeLibrary(hAI2002);
hAI2002 = NULL;
}
}
int CVSInterpreter::Create(int iChannelCount)
{
//创建脚本监视器
struct GDIThreadParam *pgdiThreadParam = (struct GDIThreadParam *)malloc(sizeof(struct GDIThreadParam));
pgdiThreadParam->pvsInterpreter = this;
pgdiThreadParam->bGDIThreadRunning = FALSE;
//CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GDIThread, pgdiThreadParam, 0, &m_dwGDIThreadID));
AfxBeginThread( GDIThread,(LPVOID)pgdiThreadParam );
while(!pgdiThreadParam->bGDIThreadRunning)
{//等待SOURCEMONITOR初始化完毕
Sleep(100);
}
//free(pgdiThreadParam);
//初始化语音通道的数量
m_iChannelCount = iChannelCount;
//创建LOG文件和DEBUG WINDOW
static BOOL bLogPathCreated = FALSE;
char aszLogFileName[100] = "\0";
if(bLogPathCreated == FALSE)
{
if(CreateDirectory(".\\Log", NULL) == FALSE)
{
if(GetLastError() != ERROR_ALREADY_EXISTS)
return -1;
else
bLogPathCreated = TRUE;
}
else
bLogPathCreated = TRUE;
}
struct tm *nowtime;
time_t ltime = time(NULL);
nowtime = localtime(<ime);
char aszTime[100] = "\0";
sprintf(aszTime, "%4d%02d%02d_%02d%02d%02d", nowtime->tm_year + 1900, nowtime->tm_mon + 1, nowtime->tm_mday, nowtime->tm_hour, nowtime->tm_min, nowtime->tm_sec);
sprintf(aszLogFileName, ".\\Log\\Log_err_%s.log", aszTime);
__fStdOut2 = fopen(aszLogFileName, "w");
//#ifdef _DEBUG
/*
AllocConsole();
SetConsoleTitle("Console Window");
__hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD co = {100, 100};
SetConsoleScreenBufferSize(__hStdOut, co);
CWnd *pwnd = AfxGetMainWnd();
SetForegroundWindow(pwnd->m_hWnd);
*/
//#endif
//得到IVR服务类型号,用于CreateRequestParamList()
m_iIVRServiceType = GetPrivateProfileInt("ServiceID", "IVR", 1, CONFIGFILE);
//得到IVR的所有通道临时文件存放的主目录(各通道在这个主目录下有各自的子目录,以填充字符'0'和通道号共4字节为名)
int iTempLen1 = GetPrivateProfileString("PATH", "USRPATH", ".\\Temp", m_aszTempPath, sizeof(m_aszTempPath), ".\\Setup.ini");
if(stricmp(m_aszTempPath, ".\\Temp") == 0 || iTempLen1 > sizeof(m_aszTempPath) - 2)
{
AfxMessageBox("Get USRPATH for temp file in Setup.ini error");
return -1;
}
//确保所有通道的临时目录被创建
int i = 0;
char aszTempChannelPath[100] = "\0";
for(i = 1; i <= m_iChannelCount; i ++)
{
if(GetFullPath2("", i, aszTempChannelPath) != 0)
{
AfxMessageBox("Initial each channel temp path, getfullpath2() failed");
return -1;
}
CreateDirectoryEn(aszTempChannelPath);
}
return(0);
}
int CVSInterpreter::Initialize()
{
char szRequestQueueName_App[100] = "request queue for voice service";
char szRequestQueueName_Voice[100] = "request queue for app service";
char szRequestQueueName_Db[100] = "request queue for database service";
char szReplyQueueName[100] = "reply queue";
char szEvent_AddReply[100] = "add a reply to reply queue";
//add by lj 2003/05/31
// Ccs_sr_ChannelInit(m_iChannelCount);
//end add
//初始化每个通道上的数据结构
if(InitializeChannelDataStructure() == -1)
{
AfxMessageBox("initializechanneldatastructure() failed");
return(-1);
}
//初始化语音服务请求队列,应用服务队列
if(m_requestQueue_Voice.Create(szRequestQueueName_Voice) == -1)
{
AfxMessageBox("initial requestqueue_voice failed");
return(-1);
}
if(m_requestQueue_App.Create(szRequestQueueName_App) == -1)
{
AfxMessageBox("initial requestqueue_app failed");
return(-1);
}
// add by lj 2003/07
if(m_requestQueue_Db.Create(szRequestQueueName_Db) == -1)
{
AfxMessageBox("initial requestqueue_db failed");
return(-1);
}
// add end
//初始化服务回应队列(语音服务和应用服务共用一个队列)
if(m_replyQueue.Create(szReplyQueueName) == -1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -