main.cpp 1.89 KB
Newer Older
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <partons/Partons.h>
#include <partons/services/automation/AutomationService.h>
#include <partons/ServiceObjectRegistry.h>
#include <QtCore/qcoreapplication.h>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

std::vector<std::string> parseArguments(int argc, char** argv) {
    if (argc <= 1) {
        throw std::runtime_error(
                "Missing argument, please provide one or more than one XML scenario file.");
    }

    std::vector<std::string> xmlScenarios;

    for (unsigned int i = 1; i != argc; i++) {
        xmlScenarios.push_back(argv[i]);
    }

    return xmlScenarios;
}

int main(int argc, char** argv) {

    // Parse arguments to retrieve xml file path list.
    std::vector<std::string> xmlScenarioFilePathList = parseArguments(argc,
            argv);

    QCoreApplication a(argc, argv);
    Partons* pPartons = 0;

    try {
        // Init PARTONS application
        pPartons = Partons::getInstance();
        pPartons->init(argc, argv);

        // Retrieve automation service parse scenario xml file and play it.
        AutomationService* pAutomationService =
                pPartons->getServiceObjectRegistry()->getAutomationService();

        for (unsigned int i = 0; i != xmlScenarioFilePathList.size(); i++) {
            Scenario* pScenario = pAutomationService->parseXMLFile(
                    xmlScenarioFilePathList[i]);
            pAutomationService->playScenario(pScenario);
        }

        // Stop PARTONS application
        if (pPartons) {
            pPartons->close();
            delete pPartons;
            pPartons = 0;
        }

        // If there is an exception
    } catch (std::exception &e) {
        std::cerr << e.what() << std::endl;

        // Close PARTONS application propertly
        if (pPartons) {
            pPartons->close();
            delete pPartons;
            pPartons = 0;
        }
    }

    return 0;
}