web_algo_init.cpp
来自「ncbi源码」· C++ 代码 · 共 258 行
CPP
258 行
/* * =========================================================================== * PRODUCTION $Log: web_algo_init.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 20:56:16 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * PRODUCTION * =========================================================================== *//* $Id: web_algo_init.cpp,v 1000.3 2004/06/01 20:56:16 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: Josh Cherry * * File Description: Auto-run plugin to initialize * "web algorithms" * */#include <ncbi_pch.hpp>#include <objmgr/object_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/version.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginCommand.hpp>#include <corelib/ncbifile.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbireg.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/core/algo_factory.hpp>#include <gui/utils/system_path.hpp>#include "web_algo_init.hpp"#include "web_algo.hpp"#include <serial/objistr.hpp>#include <serial/objistrasn.hpp>#include <serial/objistrasnb.hpp>#include <serial/objistrxml.hpp>#include <serial/serial.hpp>#include <gui/utils/fetch_url.hpp>#include "plugin_info_from_reg.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);void CAlgoWebServiceInit::GetInfo(CPluginInfo& info){ info.Reset(); // version info macro info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0, string(__DATE__) + " " + string(__TIME__), "CAlgoWebServiceInit", "", "", ""); // command info info.SetCommands().AddAlgoCommand(eAlgoCommand_run); info.SetAutorun(true);}// one instance of algo factory for all web algosstatic CAlgoFactory<CAlgoWebService> s_AlgoFactory_CAlgoWebService;void CAlgoWebServiceInit::RunCommand(CPluginMessage& msg){ CPluginReply& reply = msg.SetReply(); string dir; // load web algo plugins x_LoadWebPlugins("<std>, <home>"); reply.SetStatus(eMessageStatus_success);}void CAlgoWebServiceInit::x_LoadWebPlugins(const string& path){ list<string> paths; NStr::Split(path, ", \t\n\r", paths); ITERATE (list<string>, iter, paths) { string fname; if (*iter == "<std>") { fname = CSystemPath::ResolvePath(*iter, "etc/algo_urls"); } else if (*iter == "<home>") { fname = CSystemPath::ResolvePath(*iter, "algo_urls"); } else { fname = CSystemPath::ResolvePath(*iter, ""); } if (fname.empty()) { continue; } CFile file(fname); if (!file.Exists()) { _TRACE("File " << fname << " does not exist"); continue; } CNcbiIfstream is(fname.c_str()); vector<string> urls; string line; while(getline(is, line)) { line = NStr::TruncateSpaces(line); if (line.empty() || line[0] == '#') { // skip blank lines and lines starting with '#' continue; } urls.push_back(line); } ITERATE (vector<string>, url, urls) { // // get PluginInfo by retrieving url // string std_in, std_out, std_err; vector<string> arguments; CFetchURL::Fetch(*url + "?action=info", std_out); CNcbiIstrstream istr(std_out.c_str()); vector<CRef<CPluginInfo> > plugins; // see if it's in registry format try { PluginInfoFromRegistry(istr, plugins); } catch (...) { _TRACE(*url << " not valid as .ini format; " "trying asn1 text"); // read as many PluginInfos as are present istr.seekg(0); auto_ptr<CObjectIStream> is (CObjectIStream::Open(eSerial_AsnText, istr)); while (1) { CRef<CPluginInfo> info(new CPluginInfo); try { *is >> *info; } catch (...) { break; } plugins.push_back(info); } } int count = 0; NON_CONST_ITERATE (vector<CRef<CPluginInfo> >, iter, plugins) { CRef<CPluginInfo>& info = *iter; CPluginCommandSet& cmds = info->SetCommands(); if (!cmds.IsAlgo()) { LOG_POST(Error << "skipping " << *url << "; invalid PluginInfo (not an algo)"); continue; } CPluginCommand& args = *cmds.SetAlgo().front(); // if __url not set, take this to signify // the url we just hit if (!args.HasArgument("__url")) { CPluginArg& arg = args.SetArgs() .AddDefaultArgument("__url", "url", CPluginArg::eString, *url); arg.SetHidden(1); // url argument should be invisible } // for security, make sure no path name slips in from the net! if (args.HasArgument("__executable_path")) { LOG_POST(Info << "rejecting path " << args["__executable_path"].AsString() << " from url " << *url); args["__executable_path"].SetString(""); } CPluginRegistry::RegisterPlugin (info, &s_AlgoFactory_CAlgoWebService); count++; LOG_POST(Info << " registered " << args["__url"].AsString() << " as web algorithm"); } LOG_POST(Info << "configured " << count << " plugins from url " << *url); } }} END_NCBI_SCOPE/* * =========================================================================== * $Log: web_algo_init.cpp,v $ * Revision 1000.3 2004/06/01 20:56:16 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * * Revision 1.8 2004/05/21 22:27:47 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.7 2004/02/17 20:35:26 rsmith * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively. * * Revision 1.6 2004/01/07 17:39:03 vasilche * Fixed include path to genbank loader. * * Revision 1.5 2003/12/04 00:36:54 jcherry * Preserve order of plugin parameters specified in registry format * * Revision 1.4 2003/12/02 14:41:23 dicuccio * Restored autorun * * Revision 1.3 2003/12/01 23:22:02 jcherry * Added registry file format for plugin info * * Revision 1.2 2003/11/26 17:13:08 dicuccio * Lots of code clean-up. CHanged names of algorithms to CAlgoWebServices{Init} * * Revision 1.1 2003/11/25 19:08:51 jcherry * Initial version * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?