main.cpp 2.14 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
10
11
#include <string>
#include <vector>

std::vector<std::string> parseArguments(int argc, char** argv) {
    if (argc <= 1) {
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
12
        throw ElemUtils::CustomException("main", __func__,
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
                "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);
32
    PARTONS::Partons* pPartons = 0;
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
33
34
35

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

        // Retrieve automation service parse scenario xml file and play it.
40
        PARTONS::AutomationService* pAutomationService =
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
41
42
43
                pPartons->getServiceObjectRegistry()->getAutomationService();

        for (unsigned int i = 0; i != xmlScenarioFilePathList.size(); i++) {
44
            PARTONS::Scenario* pScenario = pAutomationService->parseXMLFile(
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
45
46
47
48
                    xmlScenarioFilePathList[i]);
            pAutomationService->playScenario(pScenario);
        }
        // If there is an exception
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
49
50
    } catch (const ElemUtils::CustomException &e) {
        pPartons->getLoggerManager()->error(e);
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
51
52
53
54
        // Close PARTONS application propertly
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
55
56
    } catch (const std::exception &e) {
        pPartons->getLoggerManager()->error("main", __func__, e.what());
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
57
58
59
60
        // Close PARTONS application propertly
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
61
    }
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
62

Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
63
64
65
    // Close PARTONS application propertly
    if (pPartons) {
        pPartons->close();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
66
67
68
69
    }

    return 0;
}