void WINAPI ServiceMain( DWORD argc, LPSTR *argv ) { std::memset( &SPEPService::serviceStatus, 0, sizeof(SPEPService::serviceStatus) ); SPEPService::serviceStatus.dwServiceType = SERVICE_WIN32; SPEPService::serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; SPEPService::updateStatus( SERVICE_START_PENDING ); std::vector<saml2::Handler*> handlers; std::auto_ptr<spep::daemon::StreamLogHandler> logHandler; std::auto_ptr<std::ostream> stream; std::string logFilename; boost::program_options::variables_map configFileVariableMap; bool readConfig = false; // Open the registry to get the filename RegistryKey rKeySoftware( HKEY_LOCAL_MACHINE, REGISTRY_KEY_SOFTWARE, KEY_ENUMERATE_SUB_KEYS ); if( rKeySoftware.valid() ) { RegistryKey rKeyESOEProject( rKeySoftware, REGISTRY_KEY_ESOEPROJECT, KEY_ENUMERATE_SUB_KEYS ); if( rKeyESOEProject.valid() ) { RegistryKey rKeySPEP( rKeyESOEProject, REGISTRY_KEY_SPEP, KEY_READ ); if( rKeySPEP.valid() ) { std::string configFilename( rKeySPEP.queryValueString( "ConfigFile" ) ); logFilename = ( rKeySPEP.queryValueString( "LogFile" ) ); if( logFilename.length() != 0 ) { stream.reset( new std::ofstream( logFilename.c_str() ) ); logHandler.reset( new spep::daemon::StreamLogHandler( *stream, spep::DEBUG ) ); handlers.push_back( logHandler.get() ); } // Read the file std::ifstream configFileInput( configFilename.c_str() ); if( configFileInput.good() ) { parseConfig( configFileVariableMap, configFileInput, handlers ); readConfig = true; } else { directLog( handlers, "The config file specified in the registry key doesn't exist." ); return; } } else { directLog( handlers, "Couldn't open HKEY_LOCAL_MACHINE\Software\ESOE Project\SPEP" ); return; } }
void parseConfig( boost::program_options::variables_map& configFileVariableMap, std::istream& configFileInput, std::vector<saml2::Handler*>& handlers ) { // Set up the configuration parameters. boost::program_options::options_description configDescription( "spep configuration options" ); spep::ConfigurationReader::addOptions( configDescription ); try { // Parse and store it in the variable map boost::program_options::store( boost::program_options::parse_config_file(configFileInput, configDescription), configFileVariableMap ); } catch( boost::program_options::ambiguous_option& ex ) { std::cerr << "Ambiguous option while reading the configuration. Error was: " << ex.what() << std::endl; directLog( handlers, "Ambiguous option while reading the configuration." ); directLog( handlers, std::string("Error was: ") + ex.what() ); exit(2); } catch( boost::program_options::invalid_syntax& ex ) { std::cerr << "Invalid syntax while reading the configuration. Error was: " << ex.what() << std::endl; directLog( handlers, "Invalid syntax while reading the configuration." ); directLog( handlers, std::string("Error was: ") + ex.what() ); exit(2); } catch( boost::program_options::unknown_option& ex ) { std::cerr << "Unknown option while reading the configuration. Error was: " << ex.what() << std::endl; directLog( handlers, "Unknown option while reading the configuration." ); directLog( handlers, std::string("Error was: ") + ex.what() ); exit(2); } catch( boost::program_options::error& ex ) { std::cerr << "Unexpected error occurred reading the configuration." << std::endl; directLog( handlers, "Unexpected error occurred reading the configuration." ); exit(2); } catch( std::exception& ex ) { std::cerr << "Error occurred reading the configuration. Error was: " << ex.what() << std::endl; directLog( handlers, "Error occurred reading the configuration." ); directLog( handlers, std::string("Error was: ") + ex.what() ); exit(2); } }
int ASNDBConf::init() { const char *conInfo = "HSSTT"; int iRet = GetTTCursor(m_poTTCursor, m_poTTConn, conInfo, oExp); if (0 != iRet) { directLog(V3_FATAL, V3_DB, MBC_PARAM_LOST_ERROR, "get timesTen Cursor failed(result = %d), conifo is %s.", iRet, conInfo); return iRet; } m_poTTCursor->Close(); m_poTTCursor->Prepare(sQuerySql); m_poTTCursor->Commit(); try { m_poTTCursor->Execute(); int lastIndex = -1; long index = -1; long tag = -1; char stag[100]; long type = -1; long flag = -1; long len = -1; long num = -1; long father = -1; long sequence = -1; long minlen = -1; ASNFormatData *pData = NULL; ASNUTree *pUTree = NULL; while(!m_poTTCursor->FetchNext()) { pUTree = new ASNUTree(); m_poTTCursor->getColumn(1, &index); m_poTTCursor->getColumn(2, &tag); m_poTTCursor->getColumn(2, stag); int xxff = m_poTTCursor->getColumnLength(2); m_poTTCursor->getColumn(3, &type); m_poTTCursor->getColumn(4, &flag); m_poTTCursor->getColumn(5, &len); m_poTTCursor->getColumn(6, &num); m_poTTCursor->getColumn(7, &father); m_poTTCursor->getColumn(8, &sequence); m_poTTCursor->getColumn(9, &minlen); pUTree->m_usTag = tag; pUTree->m_usType = type; pUTree->m_usFlag = flag; pUTree->m_uiMaxLen = len; pUTree->m_iNum = num; pUTree->m_usFather = father; pUTree->m_iSequence = sequence; pUTree->m_uiMinLen = minlen; pUTree->m_usValid = 1; if (lastIndex != index ) { pData = new ASNFormatData(); pData->UTree = pUTree; pData->current = pUTree; lastIndex = index; if (m_oFormatMap[index]) { printf("一个重复的配置数据出现,请检查数据库配置 index is %d\n", index); return -1; } else if (index >= 20) { printf("最多配置20组数据,请检查数据库配置 index is %d\n", index); return -1; } m_oFormatMap[index] = pData; } else { if (pData->current->m_usFather == pUTree->m_usFather) { // 如果新节点也current是同一个父节点,则直接根据current进行插入 iRet = pData->current->brotherAdd(pUTree); // 此处需要重新实现ASNUTree的brotherAdd函数 if (iRet) { break; } } else { iRet = pData->UTree->UTreeAdd(pUTree); if (iRet) { break; } } } } } catch(TTStatus st) { m_poTTCursor->Close(); __DEBUG_LOG1_(0, "ErrorCode::ParseErrorTable failed! err_msg=%s", st.err_msg); iRet = -1; } if (iRet) { destory(); } return iRet; }