main.cpp 3.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* main.cpp ---
 *
 * Author: Nicolas Niclausse
 * Copyright (C) 2014 - Nicolas Niclausse, Inria.
 * Created: 2014/10/28 12:45:34
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */



18 19 20

#include <dtkDistributed>
#include <dtkComposer>
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
21 22 23 24
#include <dtkCore>

#include <dtkCoreSupport/dtkPluginManager.h>
#include <dtkCoreSupport/dtkAbstractProcessFactory.h>
25 26 27 28 29

#include <QtConcurrent>

int main(int argc, char **argv)
{
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
30
    dtkDistributedApplication *application = dtkDistributed::create(argc, argv);
31

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
32 33 34 35 36
    application->setApplicationName("dtkComposerEvaluator");
    application->setApplicationVersion("1.0.0");
    application->setOrganizationName("inria");
    application->setOrganizationDomain("fr");
    bool no_gui = dtkDistributed::app()->noGui();
37

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
38 39 40 41 42
    QCommandLineParser *parser = application->parser();
    parser->setApplicationDescription("DTK composer evaluator. Run the given compostion (XML file).");
    QCommandLineOption pgOption("pg", "enable profiling");
    parser->addOption(pgOption);
    application->initialize();
43

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
44
    QStringList args = parser->positionalArguments();
45

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
46
    if (args.isEmpty()) {
47
        qDebug() << "Usage: " << argv[0] << "--spawn | [-pg] <composition> ";
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
48
        return 1;
49 50
    }

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
51 52 53
    // /////////////////////////////////////////////////////////////////
    // Old Plugin manager initialization
    // /////////////////////////////////////////////////////////////////
54

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
55 56
    QSettings *main_settings = application->settings();
    main_settings->beginGroup("plugins");
57

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
58 59 60
    if (main_settings->contains("path")) {
        dtkPluginManager::instance()->setPath(main_settings->value("path").toString());
    }
61

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
62 63 64
    if (parser->isSet("verbose")) {
        dtkPluginManager::instance()->setVerboseLoading(true);
    }
65

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
66 67
    main_settings->endGroup();
    dtkPluginManager::instance()->initialize();
68

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
69
    dtkComposerFactory *factory = new dtkComposerFactory;
70

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
71
//     if (args[1] == "--spawn") {
72

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
73 74 75 76 77 78 79 80 81 82 83
//         dtkComposerEvaluatorProcess p;
// //        p.setInternalCommunicator(comm);
//         p.setParentCommunicator(policy.communicator());
//         p.setFactory(factory);
//         p.setApplication("dtkComposerEvaluator");

//         int value;
//         do  { value = p.exec(); } while (value  == 0);

//         return value;
//     }
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

    dtkComposerScene *scene = new dtkComposerScene;
    dtkComposerStack *stack = new dtkComposerStack;
    dtkComposerGraph *graph = new dtkComposerGraph;
    dtkComposerEvaluator *evaluator = new dtkComposerEvaluator;;

    scene->setFactory(factory);
    scene->setStack(stack);
    scene->setGraph(graph);

    evaluator->setGraph(graph);

    dtkComposerReader *reader;
    reader = new dtkComposerReader;
    reader->setFactory(factory);
    reader->setScene(scene);
    reader->setGraph(graph);

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
102
    if (parser->isSet(pgOption)) {
103 104
        evaluator->setProfiling(true);
    }
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
105 106
    if (!reader->read(args.first())) {
        dtkError() << "read failure for " << args.first();
107
        return 1;
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
108 109 110
    }
    if (no_gui) {
        evaluator->run_static();
111
    } else {
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
112
        QObject::connect(evaluator,SIGNAL(evaluationStopped()),qApp, SLOT(quit()));
113
        QtConcurrent::run(evaluator, &dtkComposerEvaluator::run_static, false);
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
114
        qApp->exec();
115
    }
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
116
    dtkPluginManager::instance()->uninitialize();
117 118
}