void MySQLConnection::connect() { bool reconnecting = false; if (_myConn != nullptr) //reconnection attempt { if (!mysql_ping(_myConn)) //ping ok return; else reconnecting = true; } //remove any state from previous session this->clear(); Poco::Logger& logger = _dbEngine->getLogger(); for(;;) { const char* unix_socket = nullptr; if (_unix_socket.length() > 0) unix_socket = _unix_socket.c_str(); _myConn = mysql_real_connect(_myHandle, _host.c_str(), _user.c_str(), _password.c_str(), _database.c_str(), _port, unix_socket, CLIENT_REMEMBER_OPTIONS); if (!_myConn) { const char* actionToDo = "connect"; if (reconnecting) actionToDo = "reconnect"; unsigned int errNo = mysql_errno(_myHandle); if (IsConnectionErrFatal(errNo)) throw SqlException(errNo,mysql_error(_myHandle),actionToDo); static const long sleepTime = 1000; logger.warning(Poco::format("Could not %s to MySQL database at %s: %s, retrying in %d seconds", string(actionToDo),_host,string(mysql_error(_myHandle)),static_cast<int>(sleepTime/1000))); Poco::Thread::sleep(sleepTime); continue; } break; } string actionDone = (reconnecting)?string("Reconnected"):string("Connected"); poco_information(logger,Poco::format( actionDone + " to MySQL database %s:%d/%s client ver: %s server ver: %s", _host, _port,_database,string(mysql_get_client_info()),string(mysql_get_server_info(_myConn)) )); //Autocommit should be ON because without it, MySQL would require everything to be wrapped into a transaction if (!mysql_autocommit(_myConn, 1)) poco_trace(logger,"Set autocommit to true"); else poco_error(logger,"Failed to set autocommit to true"); //set connection properties to UTF8 to properly handle locales for different server configs //core sends data in UTF8, so MySQL must expect UTF8 too if (!mysql_set_character_set(_myConn,"utf8")) poco_trace(logger,Poco::format("Character set changed to %s",string(mysql_character_set_name(_myConn)))); else poco_error(logger,Poco::format("Failed to change charset, remains at %s",string(mysql_character_set_name(_myConn)))); }
Pothos::PluginModule::~PluginModule(void) { if (not _impl) return; //no private data if (not _impl.unique()) return; //this is not the last copy if (not _impl->sharedLibrary.isLoaded()) return; //module not loaded poco_information(Poco::Logger::get("Pothos.PluginModule.unload"), _impl->sharedLibrary.getPath()); for (const auto &pluginPath : this->getPluginPaths()) { PluginRegistry::remove(pluginPath); } _impl->sharedLibrary.unload(); }
void PostgreSQLConnection::connect() { bool reconnecting = false; if (_pgConn != nullptr) //reconnection attempt { if (!_ConnectionLost()) return; else reconnecting = true; } //remove any state from previous session this->clear(); Poco::Logger& logger = _dbEngine->getLogger(); for(;;) { if (reconnecting) PQreset(_pgConn); else { if (_host == ".") _pgConn = PQsetdbLogin(nullptr, _port == "." ? nullptr : _port.c_str(), nullptr, nullptr, _database.c_str(), _user.c_str(), _password.c_str()); else _pgConn = PQsetdbLogin(_host.c_str(), _port.c_str(), nullptr, nullptr, _database.c_str(), _user.c_str(), _password.c_str()); } //check to see that the backend connection was successfully made if (_ConnectionLost()) { const char* actionToDo = "connect"; if (reconnecting) actionToDo = "reconnect"; static const long sleepTime = 1000; logger.warning(Poco::format("Could not %s to Postgre database at %s: %s, retrying in %d seconds", string(actionToDo),_host,lastErrorDescr(),static_cast<int>(sleepTime/1000))); Poco::Thread::sleep(sleepTime); continue; } break; } string actionDone = (reconnecting)?string("Reconnected"):string("Connected"); poco_information(logger,Poco::format("%s to Postgre database %s:%s/%s server ver: %d",actionDone,_host,_port,_database,PQserverVersion(_pgConn))); }
Pothos::PluginModule::PluginModule(const std::string &path): _impl(new Impl()) { _impl->path = path; poco_information(Poco::Logger::get("Pothos.PluginModule.load"), path); try { std::lock_guard<std::mutex> lock(getModuleMutex()); registrySetActiveModuleLoading(*this); ErrorMessageDisableGuard emdg; _impl->sharedLibrary.load(path); registrySetActiveModuleLoading(PluginModule()); _impl->pluginPaths = ::getPluginPaths(*this); } catch(const Poco::LibraryLoadException &ex) { throw PluginModuleError("Pothos::PluginModule("+path+")", ex.displayText()); } }
std::vector<Poco::Path> getModulePaths(const Poco::Path &path) { poco_information(Poco::Logger::get("Pothos.PluginLoader.load"), path.toString()); std::vector<Poco::Path> paths; const Poco::File file(path); if (not file.exists()) return paths; else if (file.isFile() and (path.getExtension() == "@MODULE_EXT@")) { paths.push_back(path); } else if (file.isDirectory()) { std::vector<std::string> files; file.list(files); for (size_t i = 0; i < files.size(); i++) { auto subpaths = getModulePaths(Poco::Path(path, files[i]).absolute()); paths.insert(paths.end(), subpaths.begin(), subpaths.end()); } } return paths; }
std::string MsvcCompilerSupport::compileCppModule(const Pothos::Util::CompilerArgs &compilerArgs) { std::vector<std::string> tempFilesToCleanup; //create compiler bat script const auto clBatPath = Poco::TemporaryFile::tempName() + ".bat"; tempFilesToCleanup.push_back(clBatPath); std::ofstream clBatFile(clBatPath.c_str()); clBatFile << "call \"" << _vcvars_path << "\"" << std::endl; clBatFile << "cl.exe %*" << std::endl; clBatFile << "exit /b %ERRORLEVEL%" << std::endl; clBatFile.close(); //create args Poco::Process::Args args; args.push_back("/LD"); //Creates a dynamic-link library args.push_back("/MD"); //Creates a multithreaded DLL //add libraries for (const auto &library : compilerArgs.libraries) { args.push_back("\""+library+"\""); } //add compiler flags for (const auto &flag : compilerArgs.flags) { args.push_back(flag); } //add include paths for (const auto &include : compilerArgs.includes) { args.push_back("/I"); args.push_back("\""+include+"\""); } //add compiler sources for (const auto &source : compilerArgs.sources) { const auto filePath = Poco::TemporaryFile::tempName() + ".cpp"; tempFilesToCleanup.push_back(filePath); std::ofstream(filePath.c_str()).write(source.data(), source.size()); args.push_back("/Tp"); //Specifies a C++ source file args.push_back(filePath); } //create temp out file const auto outPath = Poco::TemporaryFile::tempName() + Poco::SharedLibrary::suffix(); tempFilesToCleanup.push_back(outPath); args.push_back("/link"); args.push_back("/out:"+outPath); //log the command std::string cmdToLog = "cl.exe "; for (const auto &a : args) cmdToLog += a + " "; poco_information(Poco::Logger::get("Pothos.MsvcCompilerSupport.compileCppModule"), cmdToLog); //launch Poco::Pipe outPipe; Poco::Process::Env env; Poco::ProcessHandle ph(Poco::Process::launch( clBatPath, args, nullptr, &outPipe, &outPipe, env)); //handle error case if (ph.wait() != 0 or not Poco::File(outPath.c_str()).exists()) { Poco::PipeInputStream errStream(outPipe); const std::string errMsgBuff = std::string( std::istreambuf_iterator<char>(errStream), std::istreambuf_iterator<char>()); cleanupTempFiles(tempFilesToCleanup); throw Pothos::Exception("MsvcCompilerSupport::compileCppModule", errMsgBuff); } //output file to string std::ifstream outFile(outPath.c_str(), std::ios::binary); const std::string outBuff = std::string( std::istreambuf_iterator<char>(outFile), std::istreambuf_iterator<char>()); cleanupTempFiles(tempFilesToCleanup); return outBuff; }
/** * Stop ItemDB. */ void ItemDB::stopItemDB() { DBUtils::closeBasicDB(hashDB); DBUtils::closeBasicDB(grassDB); poco_information(*logger, "Stop ItemDB"); }
void TagDB::stopTagDB() { DBUtils::closeBasicDB(hashDB); DBUtils::closeBasicDB(grassDB); poco_information(*logger, "stopTagDB: Stop TagDB"); return; }
void LLVMModelDataSymbols::initFloatingSpecies(const libsbml::Model* model, bool computeAndAssignConsevationLaws) { const ListOfSpecies *species = model->getListOfSpecies(); list<string> indFltSpecies; list<string> depFltSpecies; // get the floating species and set thier compartments ls::LibStructural structural(model); poco_information(getLogger(), "performed structural analysis on model: " + structural.getAnalysisMsg()); // reorder by linearly independent first, then linearly dependent vector<string> reorderedList = computeAndAssignConsevationLaws ? structural.getReorderedSpecies() : structural.getSpecies(); linearlyIndependentFloatingSpeciesSize = structural.getNumIndSpecies(); // figure out 'fully' indendent flt species -- those without rules. for (uint i = 0; i < reorderedList.size(); ++i) { // just make sure its a valid species const string& sid = reorderedList[i]; const Species *s = 0; assert((s = species->get(sid)) && !s->getBoundaryCondition()); if (computeAndAssignConsevationLaws && i <= linearlyIndependentFloatingSpeciesSize && !isIndependentElement(sid)) { string msg = "structural analysis determined that " + sid + " is linearly independent, but it has has rules " "(assignment or rate) determining its dynamics."; throw_llvm_exception(msg); } if (isIndependentElement(sid)) { indFltSpecies.push_back(sid); } else { depFltSpecies.push_back(sid); } } // stuff the species in the map for (list<string>::const_iterator i = indFltSpecies.begin(); i != indFltSpecies.end(); ++i) { uint si = floatingSpeciesMap.size(); floatingSpeciesMap[*i] = si; } for (list<string>::const_iterator i = depFltSpecies.begin(); i != depFltSpecies.end(); ++i) { uint si = floatingSpeciesMap.size(); floatingSpeciesMap[*i] = si; } // finally set how many ind species we've found independentFloatingSpeciesSize = indFltSpecies.size(); if (Logger::PRIO_INFORMATION <= getLogger().getLevel()) { LoggingBuffer log(Logger::PRIO_INFORMATION, __FILE__, __LINE__); log.stream() << "found " << indFltSpecies.size() << " independent and " << depFltSpecies.size() << " dependent floating species." << endl; log.stream() << "linearly independent species: " << linearlyIndependentFloatingSpeciesSize << endl; vector<string> ids = getFloatingSpeciesIds(); for (uint i = 0; i < ids.size(); ++i) { log.stream() << "floating species [" << i << "] = \'" << ids[i] << "\'" << endl; } } }