File size: 4,028 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */

/*
  Author(s):  Anton Deguet, Ali Uneri
  Created on: 2009-10-22

  (C) Copyright 2009-2026 Johns Hopkins University (JHU), All Rights Reserved.

--- begin cisst license - do not edit ---

This software is provided "as is" under an open source license, with
no warranty.  The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.

--- end cisst license ---
*/

#include <cisstCommon/cmnPath.h>
#include <cisstMultiTask/mtsManagerLocal.h>

#include <cisstMultiTask/mtsCollectorFactory.h>
#include <cisstMultiTask/mtsCollectorFactoryQtWidget.h>
#include <cisstMultiTask/mtsCommandLineOptionsQt.h>

#include <QApplication>

#include "mainQtComponent.h"
#include <components/sineTask.h>
#include <components/sineTaskWithDelay.h>

int main(int argc, char *argv[]) {
    // log configuration
    cmnLogger::SetMask(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskDefaultLog(CMN_LOG_ALLOW_DEBUG);
    cmnLogger::AddChannel(std::cout, CMN_LOG_ALLOW_ERRORS_AND_WARNINGS);

    // set the log level of detail on select tasks
    cmnLogger::SetMaskClass("sineTask", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsManagerLocal", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsManagerGlobal", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsCollectorQtComponent", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsCollectorState", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsCollectorEvent", CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskClass("mtsStateTable", CMN_LOG_ALLOW_ALL);

    // create Qt application
    QApplication application(argc, argv);

    // command line options
    mtsCommandLineOptionsQt options;
    if (!options.Parse(argc, argv, std::cerr)) {
        return -1;
    }

    // get the component manager to add multiple sine generator tasks
    mtsManagerLocal *componentManager = mtsManagerLocal::GetInstance();

    mainQtComponent *mainQt = new mainQtComponent("mainQt");
    componentManager->AddComponent(mainQt);

    sineTask *sine;
    sineTaskWithDelay *sineWithDelay;

    // create multiple sine generators along with their widget and
    // state collectors
    for (unsigned int i = 0; i < NumSineTasks; i++) {
        std::ostringstream index;
        index << i;

        // create the generator andconnect to its display widget
        sine = new sineTask("SIN" + index.str(), 5.0 * cmn_ms);
        sine->UseSeparateLogFileDefault();
        componentManager->AddComponent(sine);
        std::string displayName("DISP" + index.str());
        // add delay, just for the second graph
        if (i == 1) {
            sineWithDelay =
                new sineTaskWithDelay("SIN-DELAY" + index.str(), 5.0 * cmn_ms);
            sineWithDelay->SetLatency(2.0 * cmn_s);
            componentManager->AddComponent(sineWithDelay);
            componentManager->Connect(sineWithDelay->GetName(), "MainInterface",
                                      sine->GetName(), "MainInterface");
            componentManager->Connect(mainQt->GetName(), displayName,
                                      sineWithDelay->GetName(), "MainInterface");
        } else {
            componentManager->Connect(mainQt->GetName(), displayName, sine->GetName(),
                                      "MainInterface");
        }
    }

    options.Apply();

    // create and start all tasks
    componentManager->CreateAll();
    componentManager->WaitForStateAll(mtsComponentState::READY);
    componentManager->StartAll();
    componentManager->WaitForStateAll(mtsComponentState::ACTIVE);

    // run Qt event loop
    application.exec();

    // kill all tasks and perform cleanup
    componentManager->KillAll();
    componentManager->WaitForStateAll(mtsComponentState::FINISHED, 2.0 * cmn_s);

    componentManager->Cleanup();

    // stop all logs
    cmnLogger::SetMask(CMN_LOG_ALLOW_NONE);

    return 0;
}