main.cpp 3.97 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
#include <dtkCore>
22
#include <dtkWidgets>
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
23

24 25 26 27
#include <QtConcurrent>

int main(int argc, char **argv)
{
28
    dtkDistributedGuiApplication *application = dtkDistributedGuiApplication::create(argc, argv);
29

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

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
36 37
    QCommandLineParser *parser = application->parser();
    parser->setApplicationDescription("DTK composer evaluator. Run the given compostion (XML file).");
38 39 40 41 42

    // /////////////////////////////////////////////////////////////////
    // Arguments & Options
    // /////////////////////////////////////////////////////////////////

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
43 44
    QCommandLineOption pgOption("pg", "enable profiling");
    parser->addOption(pgOption);
45 46 47 48 49 50 51

    QCommandLineOption slaveOption("slave", "run as a dtk distributed slave instance");
    parser->addOption(slaveOption);

    QCommandLineOption serverOption("server", "DTK distributed server URL", "URL");
    parser->addOption(serverOption);

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
52
    application->initialize();
53

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

56
    if (args.isEmpty() && !parser->isSet(slaveOption)) {
57
        qDebug() << "Usage: " << argv[0] << "--spawn | [-pg] <composition> ";
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
58
        return 1;
59 60
    }

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
61 62 63
    // /////////////////////////////////////////////////////////////////
    // Old Plugin manager initialization
    // /////////////////////////////////////////////////////////////////
64

65 66
    // QSettings *main_settings = application->settings();
    // main_settings->beginGroup("plugins");
67

68 69 70
    // if (main_settings->contains("path")) {
    //     dtkPluginManager::instance()->setPath(main_settings->value("path").toString());
    // }
71

72 73 74
    // if (parser->isSet("verbose")) {
    //     dtkPluginManager::instance()->setVerboseLoading(true);
    // }
75

76 77
    // main_settings->endGroup();
    // dtkPluginManager::instance()->initialize();
78

79
    dtkComposerNodeFactory *factory = dtkComposer::node::factory();
80

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

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
83 84 85 86 87 88 89 90 91 92 93
//         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;
//     }
94

95 96 97 98 99 100 101 102
    if (parser->isSet(slaveOption)) {
        dtkComposerEvaluatorSlave *slave = new dtkComposerEvaluatorSlave;
        if (!parser->isSet(serverOption)) {
            qCritical() << "Error: no server set when running as slave! Use --server <url> " ;
            return 1;
        }
        slave->setServer(parser->value(serverOption));
        slave->setFactory(factory);
103

104 105 106
        application->spawn();
        do  { application->exec(slave); } while (slave->status()  == 0);
        application->unspawn();
107 108

    } else {
109 110 111 112 113
        dtkComposerGraph *graph = new dtkComposerGraph;
        dtkComposerEvaluator *evaluator = new dtkComposerEvaluator;;

        evaluator->setGraph(graph);

114 115
        dtkComposerReaderNoScene *reader;
        reader = new dtkComposerReaderNoScene;
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        reader->setFactory(factory);
        reader->setGraph(graph);

        if (parser->isSet(pgOption)) {
            evaluator->setProfiling(true);
        }
        if (!reader->read(args.first())) {
            dtkError() << "read failure for " << args.first();
            return 1;
        }
        if (no_gui) {
            evaluator->run_static();
        } else {
            QObject::connect(evaluator,SIGNAL(evaluationStopped()),qApp, SLOT(quit()));
            QtConcurrent::run(evaluator, &dtkComposerEvaluator::run_static, false);
            qApp->exec();
        }
133 134 135
    }
}