external_plugin_init.cpp

来自「ncbi源码」· C++ 代码 · 共 260 行

CPP
260
字号
/* * =========================================================================== * PRODUCTION $Log: external_plugin_init.cpp,v $ * PRODUCTION Revision 1000.6  2004/06/01 20:56:07  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//*  $Id: external_plugin_init.cpp,v 1000.6 2004/06/01 20:56:07 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 *                    "external plugins" * */#include <ncbi_pch.hpp>#include <gui/utils/exec.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/PluginRequest.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 "external_plugin_init.hpp"#include "exec_plugin.hpp"#include <serial/objistr.hpp>#include <serial/objistrasn.hpp>#include <serial/objistrasnb.hpp>#include <serial/objistrxml.hpp>#include <serial/serial.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);void CExternalPluginInit::GetInfo(CPluginInfo& info){    info.Reset();    // version info macro    info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,                 string(__DATE__) + " " + string(__TIME__),                 "CExternalPluginInit", "", "", "");    // command info    info.SetCommands().AddAlgoCommand(eAlgoCommand_run);    info.SetAutorun(true);}void CExternalPluginInit::RunCommand(CPluginMessage& msg){    CPluginReply& reply = msg.SetReply();    reply.SetStatus(eMessageStatus_success);    CNcbiApplication* app = CNcbiApplication::Instance();    _ASSERT(app);    CNcbiRegistry& registry = app->GetConfig();    string dir;    // load 'external' plugins    if ( (dir = registry.Get("app", "external_path")).empty() ) {        registry.Set("app", "external_path", "<std>, <home>",                     CNcbiRegistry::ePersistent, " default external_path");    }    if ( !(dir = registry.Get("app", "external_path")).empty() ) {        x_LoadExternalPlugins(dir);    }}void CExternalPluginInit::x_LoadExternalPlugins(const string& path){    // one instance of algo factory for all external executables    static CAlgoFactory<CExecPlugin> s_AlgoFactory_CExecPlugin;        list<string> paths;    NStr::Split(path, ", \t\n\r", paths);    ITERATE (list<string>, iter, paths) {        string dir_name;        if (*iter == "<std>"  ||  *iter == "<home>") {            dir_name = CSystemPath::ResolvePath(*iter, "executables");        } else {            dir_name = CSystemPath::ResolvePath(*iter, "");        }        if ( dir_name.empty() ) {            continue;        }                //cout << "scanning plugin directory " << dir_name << "..." << endl;        CDir dir(dir_name);        if ( !dir.Exists() ) {            //cout << "  directory " << dir_name << " does not exist" << endl;            continue;        }        CDir::TEntries entries = dir.GetEntries("*");        ITERATE (CDir::TEntries, entry_iter, entries) {            if ( !(*entry_iter)->IsFile() ) {                continue;            }                        string full_path = (*entry_iter)->GetPath();            string path      = (*entry_iter)->GetDir();            string file      = (*entry_iter)->GetName();            //            // get PluginInfo by executing executable            //            string std_in, std_out, std_err;            vector<string> arguments;            std_in = "action=info";   // cgi query string            STimeout timeout = {5, 0};  // 5 sec            CExecute::Exec(full_path, arguments,                           std_in, std_out, std_err, &timeout);                                    CRef<CPluginInfo> info(new CPluginInfo);                        try {                istrstream foo(std_out.c_str());                auto_ptr<CObjectIStream> is                    (CObjectIStream::Open(eSerial_AsnText, foo));                *is >> *info;            }            catch (...) {                LOG_POST(Error << "skipping " << full_path <<                         "; error getting PluginInfo");                continue;            }                        //info->SetClass_name(full_path);            CPluginCommandSet& cmds = info->SetCommands();            if (!cmds.IsAlgo()) {                LOG_POST(Error << "skipping " << full_path <<                         "; invalid PluginInfo (not an algo)");                continue;            }            CPluginCommand& args = *cmds.SetAlgo().front();            CPluginArg& arg = args.SetArgs()                .AddDefaultArgument("__executable_path",                                    "path name to executable",                                    CPluginArg::eString, full_path);            arg.SetHidden(1);  // path name argument should be invisible            // set menu item            info->SetMenu_item(string("Scripts/") + file);            CPluginRegistry::RegisterPlugin(info, &s_AlgoFactory_CExecPlugin);            LOG_POST(Info << "  registered "                     << full_path << " as external plugin");        }    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: external_plugin_init.cpp,v $ * Revision 1000.6  2004/06/01 20:56:07  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * * Revision 1.16  2004/05/21 22:27:47  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.15  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.14  2004/01/27 18:45:23  dicuccio * Added missing header files * * Revision 1.13  2004/01/07 17:39:02  vasilche * Fixed include path to genbank loader. * * Revision 1.12  2003/12/02 14:41:22  dicuccio * Restored autorun * * Revision 1.11  2003/11/26 17:13:08  dicuccio * Lots of code clean-up.  CHanged names of algorithms to CAlgoWebServices{Init} * * Revision 1.10  2003/11/24 15:45:30  dicuccio * Renamed CVersion to CPluginVersion * * Revision 1.9  2003/11/04 21:17:46  dicuccio * Changed calling semantics to match new plugin API * * Revision 1.8  2003/09/25 19:10:30  jcherry * Moved exec.?pp to gui/utils * * Revision 1.7  2003/09/25 17:36:27  jcherry * Renamed CExec to CExecute to avoid name conflict.  Made Exec() * really return the process's exit status. * * Revision 1.6  2003/09/09 22:45:47  jcherry * Added timeout * * Revision 1.5  2003/09/04 14:05:24  dicuccio * Use IDocument instead of CDocument * * Revision 1.4  2003/07/30 17:03:57  jcherry * Changed to put all externals into one menu, "Scripts" * * Revision 1.3  2003/07/30 15:18:05  dicuccio * Cleaned up references to CGBench_System * * Revision 1.2  2003/07/29 18:12:58  jcherry * Eliminated calls to methods of CGBenchApp, which caused missing symbols * problem in gbench_plugin_scan on some platforms * * Revision 1.1  2003/07/28 18:19:42  jcherry * Initial version * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?