summaryrefslogtreecommitdiffhomepage
path: root/logic/runtime-libraries.cpp
blob: 478b9e0e5e035ca26c2812a03ffcc42a2599187b (plain)
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
#include "runtime-libraries.hpp"
#include "options/scoped.hpp"
#include <QMessageBox>
#include <QDebug>

runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f)
{
    module_status status =
            module_status_mixin::error(tr("Library load failure"));

    using namespace options;

    with_tracker_teardown sentinel;

    pProtocol = make_dylib_instance<IProtocol>(p);

    if (!pProtocol)
        goto end;

    if(status = pProtocol->initialize(), !status.is_ok())
    {
        status = tr("Error occurred while loading protocol %1\n\n%2\n")
                 .arg(p->name, status.error);
        goto end;
    }

    pTracker = make_dylib_instance<ITracker>(t);
    pFilter = make_dylib_instance<IFilter>(f);

    if (!pTracker)
    {
        qDebug() << "tracker dylib load failure";
        goto end;
    }

    if (pFilter)
        if(status = pFilter->initialize(), !status.is_ok())
        {
            status = tr("Error occurred while loading filter %1\n\n%2\n")
                     .arg(f->name, status.error);
            goto end;
        }

    if (status = pTracker->start_tracker(frame), !status.is_ok())
    {
        status = tr("Error occurred while loading tracker %1\n\n%2\n")
                 .arg(t->name, status.error);
        goto end;
    }

    correct = true;
    return;

end:
    pTracker = nullptr;
    pFilter = nullptr;
    pProtocol = nullptr;

    if (!status.is_ok())
        QMessageBox::critical(nullptr, tr("Startup failure"), status.error, QMessageBox::Cancel, QMessageBox::NoButton);
}