//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- uint CVstSmdIOCmd::GetExportType( const MArgDatabase &mArgDatabase ) { uint retVal( 0 ); if ( mArgDatabase.isFlagSet( kOptExportType ) ) { MString optExportType; MArgList tmpArgList; const uint etEnd( mArgDatabase.numberOfFlagUses( kOptExportType ) ); for ( uint eti( 0 ); eti != etEnd; ++eti ) { mArgDatabase.getFlagArgumentList( kOptExportType, eti, tmpArgList ); optExportType = tmpArgList.asString( 0 ); if ( strnicmp( optExportType.asChar(), "r", 1 ) == 0 || strnicmp( optExportType.asChar(), "m", 1 ) == 0 ) { retVal |= CSmdExport::kReference; } else if ( strnicmp( optExportType.asChar(), "p", 1 ) == 0 ) { retVal |= CSmdExport::kPhysModel; } else if ( strnicmp( optExportType.asChar(), "a", 1 ) == 0 || strnicmp( optExportType.asChar(), "s", 1 ) == 0 ) { retVal |= CSmdExport::kAnimation; } else if ( strnicmp( optExportType.asChar(), "v", 1 ) == 0 ) { retVal |= CSmdExport::kVTA; } else { MGlobal::displayWarning( MString( "Cannot determine the type of export from -et " ) + optExportType + ", assume reference/model" ); } } } if ( retVal == 0 ) { retVal = CSmdExport::kReference; } return retVal; }
UINT CHFServer::Run() { EgStd::CEgTracingClass::TraceStatic(enlogDebug, __FUNCTION__, _T("HFServer Run Enter") ); m_nStatus = eti(m_etiPblk, ETI_ATTACH, &m_etiPtr); ::SetEvent(m_hThread); if (m_nStatus != DBA_ERR_NO_ERROR) return 0; EgStd::CEgTracingClass::TraceStatic(enlogDebug, __FUNCTION__, _T("HFServer ETI_ATTACH Succeed") ); while (!m_bTerminate) { const short status = eti(m_etiPblk, ETI_READ, &m_etiPtr); if(EgLib::CThread::IsStoping() || !EgLib::CThread::IsRunning()) m_bTerminate = true; if(m_bTerminate) break; else if(status == RC_ETI_PERIODIC) { continue; } else if (status != RC_ETI_NOERROR) { m_nStatus = status; EgLib::CAutoLock lock(m_csQueue); std::for_each(m_setSubs.begin(), m_setSubs.end(), boost::bind(&CPrice::RealtimeMessage, _1, (ETI_TABLE*)NULL)); if (status == RC_ETI_UNLOAD) break; } else { switch(m_etiPtr->packetPtr->undefined.header.type) { case MT_FILE_TRANSFER: if(FILE_CONTROL == m_etiPtr->packetPtr->fileTransfer.transferMask[0]) { switch(m_etiPtr->packetPtr->fileTransfer.data.control.command) { case FT_CTRL_HEART_BEAT: // 32 - heart beat { }break; case FT_CTRL_NONE: // 0 - no state implied (Sharky: simple message while reconnecting) { std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); EgLib::CAutoLock lock(m_csQueue); std::for_each( m_setSubs.begin(), m_setSubs.end(), boost::bind(&CPrice::NotificationMessage, _1, enProviderConnecting, strText)); }break; case FT_CTRL_ETI_SESS_RESET: // 8 - Eti Session reset or restored { std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); EgLib::CAutoLock lock(m_csQueue); std::for_each( m_setSubs.begin(), m_setSubs.end(), boost::bind(&CPrice::NotificationMessage, _1, enProviderConnected, strText)); }break; case FT_CTRL_ETI_SESS_DOWN: // 4 - Eti Session down { std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); EgLib::CAutoLock lock(m_csQueue); std::for_each( m_setSubs.begin(), m_setSubs.end(), boost::bind(&CPrice::NotificationMessage, _1, enConnectionWasDisconnected, strText)); int i = 0; }break; } }break; case MT_TRADE: case MT_QUOTE: { EgLib::CAutoLock lock(m_csQueue); std::for_each( m_setSubs.begin(), m_setSubs.end(), boost::bind(&CPrice::RealtimeMessage, _1, m_etiPtr)); }break; } } } _ASSERTE(m_setSubs.size() == 0); m_nStatus = eti(m_etiPblk, ETI_DETACH, &m_etiPtr); EgStd::CEgTracingClass::TraceStatic(enlogDebug, __FUNCTION__, _T("HFServer Run Exit") ); return 0; }
UINT CHFServer::Run() { EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__ , _T("HF Server Run Enter")); try { CoInitializeEx(NULL, COINIT_MULTITHREADED); m_nStatus = eti(m_etiPblk, ETI_ATTACH_ASYNC, &m_etiPtr); ::SetEvent(m_hThread); if (m_nStatus != DBA_ERR_NO_ERROR) { EgLib::CEgLibTraceManager::Trace(LogSubs, __FUNCTION__ , _T("HF Server Exit Run func with an error")); return 0; } long lCountError = 0; while (!m_bTerminate) { short status = 0; try { status = eti(m_etiPblk, ETI_READ, &m_etiPtr); } catch(...) { EgLib::CEgLibTraceManager::Trace(LogFaults, __FUNCTION__ , _T("ETI read unknown error")); } try { if(EgLib::CThread::IsStopping() || !EgLib::CThread::IsRunning()) { EgLib::CEgLibTraceManager::Trace(LogWarning, __FUNCTION__ , _T("HF Server Stopping")); m_bTerminate = true; break; } else if(status == RC_ETI_PERIODIC) { m_bConnected = true; InterlockedIncrement(&m_lPeriodic); continue; } else if (status != RC_ETI_NOERROR) { EgLib::CEgLibTraceManager::Trace(LogFaults, __FUNCTION__ , _T("Messaging - Error")); m_nStatus = status; m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineError(this, status)))); if (status == RC_ETI_UNLOAD) { EgLib::CEgLibTraceManager::Trace(LogFaults, __FUNCTION__ , _T("Messaging - UNLOAD message received")); SwitchToThread(); OnIdle(true); break; } } else { switch(m_etiPtr->packetPtr->undefined.header.type) { case MT_FILE_TRANSFER: if(FILE_CONTROL == m_etiPtr->packetPtr->fileTransfer.transferMask[0]) { switch(m_etiPtr->packetPtr->fileTransfer.data.control.command) { case FT_CTRL_HEART_BEAT: // 32 - heart beat { InterlockedIncrement(&m_lHeartbeat); m_bConnected = true; }break; case FT_CTRL_NONE: // 0 - no state implied (Sharky: simple message while reconnecting) { EgLib::CEgLibTraceManager::Trace(LogInfoExt, __FUNCTION__ , _T("Messaging - Reconnecting")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineNotificationMessage(this, enProviderConnecting, strText)))); m_bConnected = false; }break; case FT_CTRL_ETI_SESS_RESET: // 8 - Eti Session reset or restored { EgLib::CEgLibTraceManager::Trace(LogInfoExt, __FUNCTION__ , _T("Messaging - Session restored")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineNotificationMessage(this, enProviderConnected, strText)))); m_bConnected = true; }break; case FT_CTRL_ETI_SESS_DOWN: // 4 - Eti Session down { EgLib::CEgLibTraceManager::Trace(LogWarning, __FUNCTION__ , _T("Messaging - Session is down")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineNotificationMessage(this, enConnectionWasDisconnected, strText)))); m_bConnected = false; }break; } }break; case MT_TRADE: case MT_QUOTE: { m_bConnected = true; try { #ifdef __PERFMON if(m_spBatchPerfMon) m_spBatchPerfMon->AddRealTimeUpdate(); #endif // __PERFMON if (m_etiPtr->regionalPtr != 0 && m_etiPtr->regionalPtr->extended.item.type != 0xffff) { CHahedKeyStringPtr pKey = CHahedKeyStringPtr(new CHahedKeyString(&m_etiPtr->regionalPtr->extended.item)); if(m_sFilter.length()) { if(*m_sFilter.c_str() == '*' || std::string::npos != pKey->GetKeyString().find(m_sFilter)) { int iHourBid = (int)m_etiPtr->regionalPtr->extended.bid.hour; int iMinuteBid = (int)m_etiPtr->regionalPtr->extended.bid.minute; int iHourAsk = (int)m_etiPtr->regionalPtr->extended.ask.hour; int iMinuteAsk = (int)m_etiPtr->regionalPtr->extended.ask.minute; long lTick = (long)m_etiPtr->regionalPtr->extended.tick; EgLib::CEgLibTraceManager::Trace(LogSubs, __FUNCTION__ , _T("R %-8s\t |Bid %02d:%02d %s|Ask %02d:%02d %s|%s|\t"), pKey->GetKeyString().c_str(), iHourBid, iMinuteBid, DNTICK_BID&lTick?"Dn":(UPTICK_BID&lTick?"Up":" "), iHourAsk, iMinuteAsk, DNTICK_ASK&lTick?"Dn":(UPTICK_ASK&lTick?"Up":" "), DNTICK_LASTSALE&lTick?"Dn":(UPTICK_LASTSALE&lTick?"Up":" ")); } } InterlockedIncrement(&m_lRegionalUpdates); m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineQuoteMessage(this, pKey, &m_etiPtr->regionalPtr->extended)))); } if (m_etiPtr->compositePtr != 0 && m_etiPtr->compositePtr->extended.item.type != 0xffff) { CHahedKeyStringPtr pKey = CHahedKeyStringPtr(new CHahedKeyString(&m_etiPtr->compositePtr->extended.item)); if(m_sFilter.length()) { if(*m_sFilter.c_str() == '*' || std::string::npos != pKey->GetKeyString().find(m_sFilter)) { int iHourBid = (int)m_etiPtr->compositePtr->extended.bid.hour; int iMinuteBid = (int)m_etiPtr->compositePtr->extended.bid.minute; int iHourAsk = (int)m_etiPtr->compositePtr->extended.ask.hour; int iMinuteAsk = (int)m_etiPtr->compositePtr->extended.ask.minute; long lTick = (long)m_etiPtr->regionalPtr->extended.tick; EgLib::CEgLibTraceManager::Trace(LogSubs, __FUNCTION__ , _T("C %-8s\t |Bid %02d:%02d %s|Ask %02d:%02d %s|%s|\t"), pKey->GetKeyString().c_str(), iHourBid, iMinuteBid, DNTICK_BID&lTick?"Dn":(UPTICK_BID&lTick?"Up":" "), iHourAsk, iMinuteAsk, DNTICK_ASK&lTick?"Dn":(UPTICK_ASK&lTick?"Up":" "), DNTICK_LASTSALE&lTick?"Dn":(UPTICK_LASTSALE&lTick?"Up":" ")); } } InterlockedIncrement(&m_lCompositeUpdates); m_Pool.PushBack(CHFServerThreadPool::CStrategyThread::PoolDataTypePtr(static_cast<CHFServerThreadPool::CStrategyThread::PoolDataType*>(new CEngineQuoteMessage(this, pKey, &m_etiPtr->compositePtr->extended)))); } lCountError = 0; } catch (...) { EgLib::CEgLibTraceManager::Trace(LogSystem, __FUNCTION__ , _T("Unknown error")); ++lCountError; } }break; default: { continue; } } } } catch(...) { EgLib::CEgLibTraceManager::Trace(LogFaults, __FUNCTION__ , _T("ETI message processing Unknown error")); } if( lCountError > 3 ) { EgLib::CEgLibTraceManager::Trace(LogSystem, __FUNCTION__ , _T("Too many Errors")); OnIdle(true); break; } } _ASSERTE(m_setSubs.size() == 0); m_nStatus = eti(m_etiPblk, ETI_DETACH, &m_etiPtr); EgLib::CEgLibTraceManager::Trace(LogWarning , __FUNCTION__ , _T("HF Server Run Exit")); } catch(...) { try { EgLib::CEgLibTraceManager::Trace(LogFaults, __FUNCTION__ , _T("HF Server got exception, exiting")); } catch(...){} } m_hThread.Close(); CoUninitialize(); return 0; }
UINT CHFServer::Run() { EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("HF Server Run Enter")); try { CoInitializeEx(NULL, COINIT_MULTITHREADED); m_nStatus = eti(m_etiPblk, ETI_ATTACH_ASYNC, &m_etiPtr); ::SetEvent(m_hThread); if (m_nStatus != DBA_ERR_NO_ERROR) { EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("HF Server Exit Run func with an error")); return 0; } DWORD dwCounter = GetTickCount(); long lCompositeUpdates = 0; long lRegionalUpdates = 0; long lHeartbeat = 0; while (!m_bTerminate) { short status = 0; try { status = eti(m_etiPblk, ETI_READ, &m_etiPtr); } catch(...) { EgStd::CEgTracingClass::TraceStatic(enlogFaults, __FUNCTION__ , _T("ETI read unknown error")); } if((GetTickCount() - dwCounter) > 20000) { long lProcessed = ::InterlockedExchange(&m_lProcessedQuotes, 0); EgStd::CEgTracingClass::TraceStatic(enlogInfoExt, __FUNCTION__ , _T("ETI Updates\t Composite %d\t Regional %d\t Processed %d\t HeartBeat %d"),lCompositeUpdates, lRegionalUpdates, lProcessed, lHeartbeat); dwCounter = GetTickCount(); lCompositeUpdates = 0; lRegionalUpdates = 0; lHeartbeat = 0; } if(EgLib::CThread::IsStopping() || !EgLib::CThread::IsRunning()) { EgStd::CEgTracingClass::TraceStatic(enlogWarning, __FUNCTION__ , _T("HF Server Stopping")); m_bTerminate = true; break; } else if(status == RC_ETI_PERIODIC) { continue; } else if (status != RC_ETI_NOERROR) { EgStd::CEgTracingClass::TraceStatic(enlogFaults, __FUNCTION__ , _T("Messaging - Error")); m_nStatus = status; m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineError(this, status))); if (status == RC_ETI_UNLOAD) { EgStd::CEgTracingClass::TraceStatic(enlogFaults, __FUNCTION__ , _T("Messaging - UNLOAD message is received")); break; } } else { switch(m_etiPtr->packetPtr->undefined.header.type) { case MT_FILE_TRANSFER: if(FILE_CONTROL == m_etiPtr->packetPtr->fileTransfer.transferMask[0]) { switch(m_etiPtr->packetPtr->fileTransfer.data.control.command) { case FT_CTRL_HEART_BEAT: // 32 - heart beat { ++lHeartbeat; }break; case FT_CTRL_NONE: // 0 - no state implied (Sharky: simple message while reconnecting) { EgStd::CEgTracingClass::TraceStatic(enlogInfoExt, __FUNCTION__ , _T("Messaging - Reconnecting")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineNotificationMessage(this, enProviderConnecting, strText))); }break; case FT_CTRL_ETI_SESS_RESET: // 8 - Eti Session reset or restored { EgStd::CEgTracingClass::TraceStatic(enlogInfoExt, __FUNCTION__ , _T("Messaging - Session restored")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineNotificationMessage(this, enProviderConnected, strText))); }break; case FT_CTRL_ETI_SESS_DOWN: // 4 - Eti Session down { EgStd::CEgTracingClass::TraceStatic(enlogWarning, __FUNCTION__ , _T("Messaging - Session is down")); std::string strText; strText.insert(strText.end(), m_etiPtr->packetPtr->fileTransfer.data.control.text, m_etiPtr->packetPtr->fileTransfer.data.control.text+sizeof(m_etiPtr->packetPtr->fileTransfer.data.control.text)); strText.insert(strText.end(),(CHAR)0); m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineNotificationMessage(this, enConnectionWasDisconnected, strText))); }break; } }break; case MT_TRADE: case MT_QUOTE: { try { if(m_spBatchPerfMon) m_spBatchPerfMon->AddRealTimeUpdate(); DWORD dwCounter = GetTickCount(); if (m_etiPtr->regionalPtr != 0 && m_etiPtr->regionalPtr->standard.item.type != 0xffff) { CHahedKeyStringPtr pKey = CHahedKeyStringPtr(new CHahedKeyString(&m_etiPtr->regionalPtr->standard.item)); if(m_sFilter.length()) { if(*m_sFilter.c_str() == '*' || std::string::npos != pKey->GetKeyString().find(m_sFilter)) { int iHourBid = (int)m_etiPtr->regionalPtr->standard.bid.hour; int iMinuteBid = (int)m_etiPtr->regionalPtr->standard.bid.minute; int iHourAsk = (int)m_etiPtr->regionalPtr->standard.ask.hour; int iMinuteAsk = (int)m_etiPtr->regionalPtr->standard.ask.minute; int iHourLast = (int)m_etiPtr->regionalPtr->standard.lastSale.hour; int iMinuteLast = (int)m_etiPtr->regionalPtr->standard.lastSale.minute; long lTick = (long)m_etiPtr->regionalPtr->standard.tick; EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("R %-8s\t |Bid %02d:%02d %s|Ask %02d:%02d %s|%s|\t"), pKey->GetKeyString().c_str(), iHourBid, iMinuteBid, DNTICK_BID&lTick?"Dn":(UPTICK_BID&lTick?"Up":" "), iHourAsk, iMinuteAsk, DNTICK_ASK&lTick?"Dn":(UPTICK_ASK&lTick?"Up":" "), DNTICK_LASTSALE&lTick?"Dn":(UPTICK_LASTSALE&lTick?"Up":" ")); } } ++lRegionalUpdates; m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineQuoteMessage(this, pKey, &m_etiPtr->regionalPtr->standard))); } if (m_etiPtr->compositePtr != 0 && m_etiPtr->compositePtr->standard.item.type != 0xffff) { CHahedKeyStringPtr pKey = CHahedKeyStringPtr(new CHahedKeyString(&m_etiPtr->compositePtr->standard.item)); if(m_sFilter.length()) { if(*m_sFilter.c_str() == '*' || std::string::npos != pKey->GetKeyString().find(m_sFilter)) { int iHourBid = (int)m_etiPtr->compositePtr->standard.bid.hour; int iMinuteBid = (int)m_etiPtr->compositePtr->standard.bid.minute; int iHourAsk = (int)m_etiPtr->compositePtr->standard.ask.hour; int iMinuteAsk = (int)m_etiPtr->compositePtr->standard.ask.minute; int iHourLast = (int)m_etiPtr->compositePtr->standard.lastSale.hour; int iMinuteLast = (int)m_etiPtr->compositePtr->standard.lastSale.minute; long lTick = (long)m_etiPtr->regionalPtr->standard.tick; EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("C %-8s\t |Bid %02d:%02d %s|Ask %02d:%02d %s|%s|\t"), pKey->GetKeyString().c_str(), iHourBid, iMinuteBid, DNTICK_BID&lTick?"Dn":(UPTICK_BID&lTick?"Up":" "), iHourAsk, iMinuteAsk, DNTICK_ASK&lTick?"Dn":(UPTICK_ASK&lTick?"Up":" "), DNTICK_LASTSALE&lTick?"Dn":(UPTICK_LASTSALE&lTick?"Up":" ")); } } ++lCompositeUpdates; m_Pool.QueueRequest(reinterpret_cast<CHFServerThreadPool::RequestType>(new CEngineQuoteMessage(this, pKey, &m_etiPtr->compositePtr->standard))); } } catch (...) { EgStd::CEgTracingClass::TraceStatic(enlogSystem, __FUNCTION__ , _T("Unknown error")); } }break; } } } _ASSERTE(m_setSubs.size() == 0); m_nStatus = eti(m_etiPblk, ETI_DETACH, &m_etiPtr); EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("HF Server Run Exit")); } catch(...) { EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("HF Server got exception, exiting")); } CoUninitialize(); return 0; }