コード例 #1
0
bool sctpServer::start(const QString &config)
{
    parseConfig(config);

    if (!listen(QHostAddress::Any, mPort))
    {
        qCritical() << QObject::tr("Unable to start the server: %1").arg(errorString());
        return false;
    }

    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
                ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }

    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    QString message = QObject::tr("The server is running on\nIP: %1\tport: %2\n")
                                  .arg(ipAddress).arg(serverPort());
    qDebug() << message.toUtf8().constData();

    // initialize sc-memory
    qDebug() << "Initialize sc-memory\n";
    sc_memory_params params;
    sc_memory_params_clear(&params);

    std::string config_path = config.toStdString();
    std::string repo_path = mRepoPath.toStdString();
    std::string ext_path = mExtPath.toStdString();

    params.clear = SC_FALSE;
    params.config_file = config_path.c_str();
    params.repo_path = repo_path.c_str();
    params.ext_path = ext_path.c_str();

    mContext = sc_memory_initialize(&params);
    if (mContext == 0)
        return false;

    mEventManager = new sctpEventManager();
    mEventManager->initialize();

    if (mStatUpdatePeriod > 0)
    {
        mStatistic = new sctpStatistic(this);
        mStatistic->initialize(mStatPath, mStatUpdatePeriod, mContext);
    }

    QTimer::singleShot(mSavePeriod * 1000, this, SLOT(onSave()));

    return true;
}
コード例 #2
0
ファイル: test_threading.cpp プロジェクト: msifd/sc-machine
// ---------------------------
int main(int argc, char *argv[])
{
    sc_memory_params_clear(&params);

    params.clear = SC_TRUE;
    params.repo_path = "repo";
    params.config_file = "sc-memory.ini";
    params.ext_path = 0;

    printf("sc_element: %zd, sc_addr: %zd, sc_arc: %zd, sc_content: %zd\n", sizeof(sc_element), sizeof(sc_addr), sizeof(sc_arc_info), sizeof(sc_content));

    g_test_init(&argc, &argv, NULL);
    g_test_add_func("/threading/create_save", test_save);
    g_test_add_func("/threading/create_nodes", test_node_creation);
    g_test_add_func("/threading/create_arcs", test_arc_creation);
    g_test_add_func("/threading/create_links", test_link_creation);
    g_test_add_func("/threading/create_combined", test_combined_creation);
    g_test_run();


    return 0;
}
コード例 #3
0
ファイル: builder.cpp プロジェクト: msifd/sc-machine
bool Builder::run(const BuilderParams &params)
{

    mParams = params;

    collectFiles();

    // initialize sc-memory
    sc_memory_params p;
    sc_memory_params_clear(&p);
    p.clear = mParams.clearOutput ? SC_TRUE : SC_FALSE;
    p.config_file = mParams.configFile.empty() ? 0 : mParams.configFile.c_str();
    p.repo_path = mParams.outputPath.c_str();
    p.ext_path = mParams.extensionsPath.size() > 0 ? mParams.extensionsPath.c_str() : 0;

    sc_memory_initialize(&p);

    mContext = sc_memory_context_new(sc_access_lvl_make_min);

    std::cout << "Build knowledge base from sources... " << std::endl;

    // process founded files
    uint32 done = 0, last_progress = -1;
    tFileSet::iterator it, itEnd = mFileSet.end();
    for (it = mFileSet.begin(); it != itEnd; ++it)
    {
        uint32 progress = (uint32)(((float)++done / (float)mFileSet.size()) * 100);
        if (mParams.showFileNames)
        {
            std::cout << "[ " << progress << "% ] " << *it << std::endl;
        }
        else
        {
            if (last_progress != progress)
            {
                if (progress % 10 == 0)
                {
                    std::cout << "[" << progress << "%]";
                    std::cout.flush();
                }
                else
                {
                    std::cout << ".";
                    std::cout.flush();
                }
                last_progress = progress;
            }
        }

        try
        {
            processFile(*it);
        } catch(const Exception &e)
        {
            StringStream ss;
            ss << e.getDescription() << " in " << e.getFileName() << " at line " << e.getLineNumber();
            mErrors.push_back(ss.str());
        }
    }
    std::cout << std::endl << "done" << std::endl;

    // print errors
    std::cout << std::endl << "-------" << std::endl << "Errors:" << std::endl;
    int idx = 1;
    tStringList::iterator itErr, itErrEnd = mErrors.end();
    for (itErr = mErrors.begin(); itErr != itErrEnd; ++itErr)
        std::cout << "[" << idx++ << "]\t" << *itErr << std::endl;

    // print statistics
    sc_stat stat;
    sc_memory_stat(mContext, &stat);

    unsigned int all_count = stat.arc_count + stat.node_count + stat.link_count;

    std::cout << std::endl << "Statistics" << std::endl;
    std::cout << "Nodes: " << stat.node_count << "(" << ((float)stat.node_count / (float)all_count) * 100 << "%)" << std::endl;
    std::cout << "Arcs: " << stat.arc_count << "(" << ((float)stat.arc_count / (float)all_count) * 100 << "%)"  << std::endl;
    std::cout << "Links: " << stat.link_count << "(" << ((float)stat.link_count / (float)all_count) * 100 << "%)"  << std::endl;
    std::cout << "Total: " << all_count << std::endl;

    sc_memory_context_free(mContext);
    sc_memory_shutdown(SC_TRUE);

    return true;
}