コード例 #1
0
ファイル: vdbread.cpp プロジェクト: svn2github/ncbi_tk
void CVDBMgr::x_Init(void)
{
    if ( rc_t rc = VDBManagerMakeRead(x_InitPtr(), 0) ) {
        *x_InitPtr() = 0;
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot open VDBManager", rc);
    }
    uint32_t sdk_ver;
    if ( rc_t rc = VDBManagerVersion(*this, &sdk_ver) ) {
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot get VDBManager version", rc);
    }
    CKNSManager kns_mgr(CVFSManager(*this));
    CNcbiOstrstream str;
    CNcbiApplication* app = CNcbiApplication::Instance();
    if ( app ) {
        str << app->GetAppName() << ": " << app->GetVersion().Print() << "; ";
    }
#if NCBI_PACKAGE
    str << "Package: " << NCBI_PACKAGE_NAME << ' ' <<
        NCBI_PACKAGE_VERSION << "; ";
#endif
    str << "C++ ";
#ifdef NCBI_PRODUCTION_VER
    str << NCBI_PRODUCTION_VER << "/";
#endif
#ifdef NCBI_DEVELOPMENT_VER
    str << NCBI_DEVELOPMENT_VER;
#endif
    string prefix = CNcbiOstrstreamToString(str);
    KNSManagerSetUserAgent(kns_mgr, "%s; SRA Toolkit %V",
                           prefix.c_str(),
                           sdk_ver);

    // redirect VDB log to C++ Toolkit
    if ( s_GetDiagHandler() ) {
        KLogInit();
        KLogLevelSet(klogDebug);
        KLogLibHandlerSet(VDBLogWriter, 0);
    }

    if ( app ) {
        string host = app->GetConfig().GetString("CONN", "HTTP_PROXY_HOST", kEmptyStr);
        int port = app->GetConfig().GetInt("CONN", "HTTP_PROXY_PORT", 0);
        if ( !host.empty() && port != 0 ) {
            if ( rc_t rc = KNSManagerSetHTTPProxyPath(kns_mgr, "%s:%d", host.c_str(), port) ) {
                NCBI_THROW2(CSraException, eInitFailed,
                            "Cannot set KNSManager proxy parameters", rc);
            }
            KNSManagerSetHTTPProxyEnabled(kns_mgr, true);
        }
    }
}
コード例 #2
0
ファイル: ncbi_param.cpp プロジェクト: swuecho/igblast
string NCBI_XNCBI_EXPORT g_GetConfigString(const char* section,
                                           const char* variable,
                                           const char* env_var_name,
                                           const char* default_value)
{
    if ( section  &&  *section ) {
        CNcbiApplication* app = CNcbiApplication::Instance();
        if ( app  &&  app->HasLoadedConfig() ) {
            const string& value = app->GetConfig().Get(section, variable);
            if ( !value.empty() ) {
#ifdef _DEBUG
                if ( s_CanDumpConfig() ) {
                    DUMP_CONFIG(15, "NCBI_CONFIG: str variable"
                                    " [" << section << "]"
                                    " " << variable <<
                                    " = \"" << value << "\""
                                    " from registry");
                }
#endif
                return value;
            }
        }
    }
    const TXChar* value = s_GetEnv(section, variable, env_var_name);
    if ( value ) {
#ifdef _DEBUG
        if ( s_CanDumpConfig() ) {
            if ( section  &&  *section ) {
                DUMP_CONFIG(16, "NCBI_CONFIG: str variable"
                                " [" << section << "]"
                                " " << variable <<
                                " = \"" << value << "\""
                                " from env var " <<
                                s_GetEnvVarName(section, variable, env_var_name));
            }
            else {
                DUMP_CONFIG(17, "NCBI_CONFIG: str variable"
                                " " << variable <<
                                " = \"" << value << "\""
                                " from env var");
            }
        }
#endif
        return _T_STDSTRING(value);
    }
    const char* dvalue = default_value? default_value: "";
#ifdef _DEBUG
    if ( s_CanDumpConfig() ) {
        if ( section  &&  *section ) {
            DUMP_CONFIG(18, "NCBI_CONFIG: str variable"
                            " [" << section << "]"
                            " " << variable <<
                            " = \"" << dvalue << "\""
                            " by default");
        }
        else {
            DUMP_CONFIG(19, "NCBI_CONFIG: str variable"
                            " " << variable <<
                            " = \"" << dvalue << "\""
                            " by default");
        }
    }
#endif
    return dvalue;
}
コード例 #3
0
ファイル: ncbi_param.cpp プロジェクト: swuecho/igblast
int NCBI_XNCBI_EXPORT g_GetConfigInt(const char* section,
                                     const char* variable,
                                     const char* env_var_name,
                                     int default_value)
{
    if ( section  &&  *section ) {
        CNcbiApplication* app = CNcbiApplication::Instance();
        if ( app  &&  app->HasLoadedConfig() ) {
            const string& str = app->GetConfig().Get(section, variable);
            if ( !str.empty() ) {
                try {
                    int value = NStr::StringToInt(str);
#ifdef _DEBUG
                    if ( s_CanDumpConfig() ) {
                        DUMP_CONFIG(10, "NCBI_CONFIG: int variable"
                                        " [" << section << "]"
                                        " " << variable <<
                                        " = " << value <<
                                        " from registry");
                    }
#endif
                    return value;
                }
                catch ( ... ) {
                    // ignored
                }
            }
        }
    }
    const TXChar* str = s_GetEnv(section, variable, env_var_name);
    if ( str && *str ) {
        try {
            int value = NStr::StringToInt(_T_CSTRING(str));
#ifdef _DEBUG
            if ( s_CanDumpConfig() ) {
                if ( section  &&  *section ) {
                    DUMP_CONFIG(11, "NCBI_CONFIG: int variable"
                                    " [" << section << "]"
                                    " " << variable <<
                                    " = " << value <<
                                    " from env var " <<
                                    s_GetEnvVarName(section, variable, env_var_name));
                }
                else {
                    DUMP_CONFIG(12, "NCBI_CONFIG: int variable "
                                    " " << variable <<
                                    " = " << value <<
                                    " from env var");
                }
            }
#endif
            return value;
        }
        catch ( ... ) {
            // ignored
        }
    }
    int value = default_value;
#ifdef _DEBUG
    if ( s_CanDumpConfig() ) {
        if ( section  &&  *section ) {
            DUMP_CONFIG(13, "NCBI_CONFIG: int variable"
                            " [" << section << "]"
                            " " << variable <<
                            " = " << value <<
                            " by default");
        }
        else {
            DUMP_CONFIG(14, "NCBI_CONFIG: int variable"
                            " " << variable <<
                            " = " << value <<
                            " by default");
        }
    }
#endif
    return value;
}
コード例 #4
0
ファイル: ncbi_param.cpp プロジェクト: swuecho/igblast
double NCBI_XNCBI_EXPORT g_GetConfigDouble(const char* section,
                                           const char* variable,
                                           const char* env_var_name,
                                           double default_value)
{
    if ( section  &&  *section ) {
        CNcbiApplication* app = CNcbiApplication::Instance();
        if ( app  &&  app->HasLoadedConfig() ) {
            const string& str = app->GetConfig().Get(section, variable);
            if ( !str.empty() ) {
                try {
                    double value = NStr::StringToDouble(str,
                        NStr::fDecimalPosixOrLocal |
                        NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSpaces);
#ifdef _DEBUG
                    if ( s_CanDumpConfig() ) {
                        DUMP_CONFIG(10, "NCBI_CONFIG: double variable"
                                        " [" << section << "]"
                                        " " << variable <<
                                        " = " << value <<
                                        " from registry");
                    }
#endif
                    return value;
                }
                catch ( ... ) {
                    // ignored
                }
            }
        }
    }
    const TXChar* str = s_GetEnv(section, variable, env_var_name);
    if ( str && *str ) {
        try {
            double value = NStr::StringToDouble(_T_CSTRING(str),
                NStr::fDecimalPosixOrLocal |
                NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSpaces);
#ifdef _DEBUG
            if ( s_CanDumpConfig() ) {
                if ( section  &&  *section ) {
                    DUMP_CONFIG(11, "NCBI_CONFIG: double variable"
                                    " [" << section << "]"
                                    " " << variable <<
                                    " = " << value <<
                                    " from env var " <<
                                    s_GetEnvVarName(section, variable, env_var_name));
                }
                else {
                    DUMP_CONFIG(12, "NCBI_CONFIG: double variable "
                                    " " << variable <<
                                    " = " << value <<
                                    " from env var");
                }
            }
#endif
            return value;
        }
        catch ( ... ) {
            // ignored
        }
    }
    double value = default_value;
#ifdef _DEBUG
    if ( s_CanDumpConfig() ) {
        if ( section  &&  *section ) {
            DUMP_CONFIG(13, "NCBI_CONFIG: double variable"
                            " [" << section << "]"
                            " " << variable <<
                            " = " << value <<
                            " by default");
        }
        else {
            DUMP_CONFIG(14, "NCBI_CONFIG: int variable"
                            " " << variable <<
                            " = " << value <<
                            " by default");
        }
    }
#endif
    return value;
}
コード例 #5
0
ファイル: ncbi_param.cpp プロジェクト: swuecho/igblast
bool NCBI_XNCBI_EXPORT g_GetConfigFlag(const char* section,
                                       const char* variable,
                                       const char* env_var_name,
                                       bool default_value)
{
#ifdef _DEBUG
    bool is_config_dump = NStr::Equal(section, CONFIG_DUMP_SECTION)  &&
        NStr::Equal(variable, CONFIG_DUMP_VARIABLE);
#endif

    if ( section  &&  *section ) {
        CNcbiApplication* app = CNcbiApplication::Instance();
        if ( app  &&  app->HasLoadedConfig() ) {
            const string& str = app->GetConfig().Get(section, variable);
            if ( !str.empty() ) {
                try {
                    bool value = s_StringToBool(str);
#ifdef _DEBUG
                    if ( is_config_dump ) {
                        s_ConfigDump = value;
                    }
                    if ( s_CanDumpConfig() ) {
                        DUMP_CONFIG(5, "NCBI_CONFIG: bool variable"
                                       " [" << section << "]"
                                       " " << variable <<
                                       " = " << value <<
                                       " from registry");
                    }
#endif
                    return value;
                }
                catch ( ... ) {
                    // ignored
                }
            }
        }
    }
    const TXChar* str = s_GetEnv(section, variable, env_var_name);
    if ( str && *str ) {
        try {
            bool value = s_StringToBool(_T_CSTRING(str));
#ifdef _DEBUG
            if ( is_config_dump ) {
                s_ConfigDump = value;
            }
            if ( s_CanDumpConfig() ) {
                if ( section  &&  *section ) {
                    DUMP_CONFIG(6, "NCBI_CONFIG: bool variable"
                                   " [" << section << "]"
                                   " " << variable <<
                                   " = " << value <<
                                   " from env var " <<
                                   s_GetEnvVarName(section, variable, env_var_name));
                }
                else {
                    DUMP_CONFIG(7, "NCBI_CONFIG: bool variable "
                                   " " << variable <<
                                   " = " << value <<
                                   " from env var");
                }
            }
#endif
            return value;
        }
        catch ( ... ) {
            // ignored
        }
    }
    bool value = default_value;
#ifdef _DEBUG
    if ( is_config_dump ) {
        s_ConfigDump = value;
    }
    if ( s_CanDumpConfig() ) {
        if ( section  &&  *section ) {
            DUMP_CONFIG(8, "NCBI_CONFIG: bool variable"
                           " [" << section << "]"
                           " " << variable <<
                           " = " << value <<
                           " by default");
        }
        else {
            DUMP_CONFIG(9, "NCBI_CONFIG: bool variable"
                           " " << variable <<
                           " = " << value <<
                           " by default");
        }
    }
#endif
    return value;
}