|
楼主 |
发表于 2009-8-6 11:14:41
|
显示全部楼层
CCriticalSection g_WriteLogLock;
//用于调用信息的线程函数
UINT ModuleFunc(LPVOID a_pThreadInfo)
{
char* pDataRcvBuffer=NULL;
try
{
STThreadInfo* pThreadInfo = (STThreadInfo*)a_pThreadInfo;
ACE_Barrier* pDataCopyBarrier = pThreadInfo->m_pBarrier;
CString sModuleName = pThreadInfo->m_sModuleName;
UINT nMsgUserDefined = pThreadInfo->m_nMsgDefined;
UINT nClientID = pThreadInfo->m_nClientID;
LPVOID pClientStream = pThreadInfo->m_pStream;
_bstr_t strCon = pThreadInfo->m_strCon;
LPVOID SendDataFunc = pThreadInfo->m_pFunc;
LPCSTR sDataSeries = pThreadInfo->m_pData;
UINT nDataSeriesAmount = pThreadInfo->m_nDataLen;
pDataRcvBuffer = new char[nDataSeriesAmount];
memcpy(pDataRcvBuffer, sDataSeries, nDataSeriesAmount);
pDataCopyBarrier->wait();
//载入模块
HINSTANCE hInst;
hInst = LoadLibrary(sModuleName);
typedef (*ACCEPTDATAPROC) (UINT a_nCmdID, LPCSTR a_sDataSeries, UINT a_nDataSeriesAmount, UINT a_nClientID, LPVOID a_cClientAddr,_bstr_t a_strCon, LPVOID a_SendDataFunc);
ACCEPTDATAPROC AcceptData = (ACCEPTDATAPROC)GetProcAddress(hInst,"AcceptData");
//调用模块函数
if (AcceptData)
{
AcceptData(nMsgUserDefined, (LPCSTR)pDataRcvBuffer, nDataSeriesAmount, nClientID, pClientStream, strCon, SendDataFunc);
}
FreeLibrary(hInst);
}
catch(...)
{
g_WriteLogLock.Lock();
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("ModuleFunc"),_T(""),_T("线程同步异常或载入模块异常"));
g_WriteLogLock.Unlock();
if(pDataRcvBuffer != NULL)
{
delete[] pDataRcvBuffer;
}
return 1;
}
if(pDataRcvBuffer != NULL)
{
delete[] pDataRcvBuffer;
}
return 0;
}
// 数据处理回调函数的执行部分
int WINAPI CDataHandler::DataHandleFunc(UINT a_nClientID,
UINT a_nMsgUserDefined, LPCSTR a_sDataSeries,
UINT a_nDataSeriesAmount, LPVOID a_pClientStream)
{
ACE_Barrier DataCopyBarrier(2);
CString sModuleName;
try
{
std::map<int, CString>::iterator iter;
iter = m_pDataHandler->m_mapModule.find(a_nMsgUserDefined);
sModuleName.Format("%s",iter->second);
}
catch(...)
{
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("DataHandleFun"),_T(""),_T("在map中寻找模块异常"));
}
try
{
STThreadInfo* pThreadInfo = new STThreadInfo;
pThreadInfo->m_pBarrier = &DataCopyBarrier;
pThreadInfo->m_sModuleName = sModuleName;
pThreadInfo->m_nMsgDefined = a_nMsgUserDefined;
pThreadInfo->m_nClientID = a_nClientID;
pThreadInfo->m_pStream = a_pClientStream;
pThreadInfo->m_strCon = (m_pDataHandler->m_DataProcess).m_strCon;
pThreadInfo->m_pFunc = SendDataFunc;
pThreadInfo->m_pData = a_sDataSeries;
pThreadInfo->m_nDataLen = a_nDataSeriesAmount;
// ACEProxy开始工作
CWinThread* pThreadStartUp;
pThreadStartUp = AfxBeginThread(ModuleFunc, (LPVOID)pThreadInfo,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThreadStartUp->ResumeThread();
// CloseHandle(pThreadStartUp->m_hThread);
DataCopyBarrier.wait();
}
catch(...)
{
g_WriteLogLock.Lock();
g_pExceptionLog.WriteExceptionLog(-1,_T("CMFD_Svr_MainFrame"),_T("DataHandleFun"),_T(""),_T("载入DLL模块异常"));
g_WriteLogLock.Unlock();
}
return 0;
} |
|