main.cpp 3.55 KB
Newer Older
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
1
2
#include <ElementaryUtils/logger/CustomException.h>
#include <ElementaryUtils/logger/LoggerManager.h>
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
3
4
5
#include <partons/Partons.h>
#include <partons/services/automation/AutomationService.h>
#include <partons/ServiceObjectRegistry.h>
6
#include <QtCore/qcoreapplication.h>
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
7
8
9
#include <string>
#include <vector>

10
#include "../include/examples.h"
11

Pawel Sznajder's avatar
Pawel Sznajder committed
12
13
14
/*
 * Parse XML scenarios.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
15
std::vector<std::string> parseArguments(int argc, char** argv) {
16
    std::vector<std::string> xmlScenarios(argc - 1);
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
17

18
    for (unsigned int i = 1; i < argc; i++) {
19
        xmlScenarios[i - 1] = argv[i];
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
20
21
22
23
24
    }

    return xmlScenarios;
}

Pawel Sznajder's avatar
Pawel Sznajder committed
25
26
27
/*
 * Main function.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
28
29
int main(int argc, char** argv) {

30
    // Init Qt4
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
31
    QCoreApplication a(argc, argv);
32
    PARTONS::Partons* pPartons = 0;
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
33
34

    try {
Pawel Sznajder's avatar
Pawel Sznajder committed
35

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
36
        // Init PARTONS application
37
        pPartons = PARTONS::Partons::getInstance();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
38
39
        pPartons->init(argc, argv);

40
41
42
43
44
        // ******************************************************
        // RUN XML SCENARIO *************************************
        // ******************************************************

        // You need to provide at least one scenario via executable argument
45
        if (argc <= 1) {
46

47
48
            throw ElemUtils::CustomException("main", __func__,
                    "Missing argument, please provide one or more than one XML scenario file.");
49
        }
Pawel Sznajder's avatar
Pawel Sznajder committed
50

51
52
53
        // Parse arguments to retrieve xml file path list.
        std::vector<std::string> xmlScenarioFilePathList = parseArguments(argc,
                argv);
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
54

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

59
60
61
62
63
        for (unsigned int i = 0; i < xmlScenarioFilePathList.size(); i++) {
            PARTONS::Scenario* pScenario = pAutomationService->parseXMLFile(
                    xmlScenarioFilePathList[i]);
            pAutomationService->playScenario(pScenario);
        }
Pawel Sznajder's avatar
Pawel Sznajder committed
64

65
66
67
        // ******************************************************
        // RUN CPP CODE *****************************************
        // ******************************************************
Pawel Sznajder's avatar
Pawel Sznajder committed
68

69
70
71
72
        // You can put your own code here and build a stand-alone program based on PARTONS library.
        // To learn how you can use PARTONS library study provided examples of functions to be found in
        // include/examples.h (header) and src/examples.cpp (source) files.
        // To run these examples just call them here, e.g.:
73

74
        // computeSingleKinematicsForGPD();
Pawel Sznajder's avatar
Pawel Sznajder committed
75

76
77
78
79
80
81
82
83
84
        // Note, that you may need to comment out the part responsible for the running of XML scenarios.

    }
    // Appropriate catching of exceptions is crucial for working of PARTONS.
    // PARTONS defines its own type of exception, which allows to display class name and function name
    // where the exception has occurred, but also a human readable explanation.
    catch (const ElemUtils::CustomException &e) {

        // Display what happened
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
85
        pPartons->getLoggerManager()->error(e);
86

Nabil Chouika's avatar
typo    
Nabil Chouika committed
87
        // Close PARTONS application properly
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
88
89
90
        if (pPartons) {
            pPartons->close();
        }
91
92
93
94
95
    }
    // In a case of standard exception.
    catch (const std::exception &e) {

        // Display what happened
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
96
        pPartons->getLoggerManager()->error("main", __func__, e.what());
97

Nabil Chouika's avatar
typo    
Nabil Chouika committed
98
        // Close PARTONS application properly
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
99
100
101
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
102
    }
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
103

Nabil Chouika's avatar
typo    
Nabil Chouika committed
104
    // Close PARTONS application properly
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
105
106
    if (pPartons) {
        pPartons->close();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
107
108
109
110
    }

    return 0;
}