plugin_init.cpp
来自「ncbi源码」· C++ 代码 · 共 627 行 · 第 1/2 页
CPP
627 行
/* * =========================================================================== * PRODUCTION $Log: plugin_init.cpp,v $ * PRODUCTION Revision 1000.5 2004/06/01 20:56:32 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.42 * PRODUCTION * =========================================================================== *//* $Id: plugin_init.cpp,v 1000.5 2004/06/01 20:56:32 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio * Anatoliy Kuznetsov * * File Description: * CGBenchPluginInit -- single standard autoloading plugin for Genome * Workbench */#include <ncbi_pch.hpp>#include "plugin_init.hpp"#include <bdb/bdb_blobcache.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbireg.hpp>#include <corelib/ncbitime.hpp> #include <corelib/ncbi_process.hpp>#include <gui/core/data_store.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/plugin_exception.hpp>#include <gui/core/plugin_handle.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/utils/system_path.hpp>#include <gui/core/version.hpp>#include <gui/plugin/PluginCommand.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginValueConstraint.hpp>#include <gui/utils/message_box.hpp>#include <objmgr/object_manager.hpp>#include <objtools/data_loaders/lds/lds_dataloader.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <objtools/data_loaders/genbank/readers/id1/reader_id1_cache.hpp>#include <objtools/lds/admin/lds_admin.hpp>#include <objtools/lds/lds.hpp>#include <objtools/lds/lds_reader.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);void CGBenchPluginInit::GetInfo(CPluginInfo& info){ info.Reset(); // version info macro info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0, string(__DATE__) + " " + string(__TIME__), "CGBenchPluginInit", "", "", ""); // command info info.SetCommands().AddAlgoCommand(eAlgoCommand_run); info.SetAutorun(true);}void CGBenchPluginInit::RunCommand(CPluginMessage& msg){ CPluginReply& reply = msg.SetReply(); // // first, set up our stock data loaders // these must be present for sequence ID resolution to work correctly // // Create GenBank data loader and register it with the OM. // The last argument "eDefault" informs the OM that the loader must // be included in scopes during the CScope::AddDefaults() call. try { x_InitGenBank(); } catch (CException& e) { LOG_POST(Error << "error creating GenBank data loader: " << e.what()); string msg("Error connecting to GenBank:\n"); msg += e.GetMsg(); msg += "\nGenBank will not be available."; NcbiMessageBox(msg); }#ifndef _DEBUG catch (...) { LOG_POST(Error << "unknown error creating GenBank data loader"); NcbiMessageBox("An unknown error has occurred while trying to " "connect to GenBank"); }#endif // // initialize the local data storage // try { x_InitLDS(); } catch(CException& e) { LOG_POST(Error << "error initializing local data storage: " << e.what()); string msg("Error initializing local data storage:\n"); msg += e.GetMsg(); msg += "\nLDS will not be available."; NcbiMessageBox(msg); }#ifndef _DEBUG catch (...) { LOG_POST(Error << "unknown error creating GenBank data loader"); NcbiMessageBox("An unknown error has occurred while trying to " "initialize the local data stores."); }#endif // // PLANNED: // // - establish named pipe for gbench-agent (our mime droid) // - check NCBI to see if there are any gbench updates // - evaluate history to see what the user has looked at recently and see // if there are any recent changes in those sequences / organisms // - check the user's cubby at NCBI to see if there are any updates in any // watched files // reply.SetStatus(eMessageStatus_success);}//// Create our GenBank connection//void CGBenchPluginInit::x_InitGenBank(){ CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); CNcbiRegistry& reg = app->GetConfig(); // general genbank loader options int gc_size = reg.GetInt("GBLOADER", "GcSize", 10000, CNcbiRegistry::eErrPost); int priority = reg.GetInt("GBLOADER", "Priority", 99, CNcbiRegistry::eErrPost); // caching options string cache_path = CSystemPath::ResolvePath("<home>", "cache"); cache_path = reg.GetString("GBLOADER", "CachePath", cache_path, CNcbiRegistry::eErrPost); int cache_age = reg.GetInt("GBLOADER", "CacheAge", 5, CNcbiRegistry::eErrPost); if (cache_age == 0) { cache_age = 5; // keep objects for 5 days (default) } // ID resolution time in hours int id_resolution_time = reg.GetInt("GBLOADER", "IdResolutionTime", 24, CNcbiRegistry::eErrPost); if (id_resolution_time > 24 * 3) id_resolution_time = 24 * 3; // correct the unreasonable value bool disable_cache = reg.GetBool("GBLOADER", "DisableCache", false, CNcbiRegistry::eErrPost); auto_ptr<CCachedId1Reader> id1_reader; if (!cache_path.empty() && !disable_cache) { try { auto_ptr<CBDB_Cache> bc(new CBDB_Cache()); try { ICache::TTimeStampFlags flags = ICache::fTimeStampOnRead | ICache::fExpireLeastFrequentlyUsed | ICache::fPurgeOnStartup; bc->SetTimeStampPolicy(flags, cache_age*24*60*60); bc->Open(cache_path.c_str(), "blobs", CBDB_Cache::ePidLock); // Cache cleaning // Objects age should be assigned in days, negative value // means cleaning is disabled if (cache_age > 0) { CTime time_stamp(CTime::eCurrent); time_t age = time_stamp.GetTimeT(); age -= 60 * 60 * 24 * cache_age; bc->Purge(age); } } catch (CPIDGuardException& ex) { switch (ex.GetErrCode()) { case CPIDGuardException::eStillRunning: // We probably(!) have another program competing for cache, // So this copy is not getting access LOG_POST(Error << "GenBank Cache is in use by another process"); LOG_POST(Error << "Local caching will be disabled."); throw; default: throw; } // switch } auto_ptr<CBDB_Cache> idc(new CBDB_Cache()); try { ICache::TTimeStampFlags flags = ICache::fTimeStampOnCreate| ICache::fCheckExpirationAlways; idc->SetTimeStampPolicy(flags, id_resolution_time * 60 * 60); idc->Open(cache_path.c_str(), "idc", CBDB_Cache::ePidLock); } catch (CPIDGuardException& ex) { switch (ex.GetErrCode()) { case CPIDGuardException::eStillRunning: // We probably(!) have another program competing for cache, // So this copy is not getting access LOG_POST(Error << "GenBank Cache is in use by another process"); LOG_POST(Error << "Local caching will be disabled."); throw; default: throw; } // switch } CRef<CBDB_CacheHolder> cache_holder(new CBDB_CacheHolder(bc.release(), idc.release())); CDataStore::PutObject("BDB_Cache", *cache_holder); id1_reader.reset(new CCachedId1Reader(5, cache_holder->GetBlobCache(), cache_holder->GetIdCache())); LOG_POST(Info << "ID1 cache enabled at " << cache_path); } catch(CException& e) { LOG_POST(Error << "ID1 cache initialization failed in " << cache_path << ": " << e.what()); }#ifndef _DEBUG catch(...) { LOG_POST(Error << "ID1 cache initialization failed in " << cache_path); }#endif } else { LOG_POST(Info << "ID1 cache disabled."); } CRef<CGBDataLoader> loader (new CGBDataLoader("GenBank", id1_reader.release(), gc_size)); if ( !loader ) { NCBI_THROW(CPluginException, eUnknownError, "CGBenchPluginInit(): " "can't create GenBank data loader"); } CDocManager::GetObjectManager() .RegisterDataLoader(*(loader.Release()), CObjectManager::eDefault, priority); LOG_POST(Info << "registered GenBank data loader");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?