summaryrefslogtreecommitdiffhomepage
path: root/logic/runtime-libraries.cpp
blob: 754f52cdc5736fd545107886271cfafc22a44818 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "runtime-libraries.hpp"
#include "options/scoped.hpp"
#include <QMessageBox>
#include <QDebug>

#ifdef __clang__
#   pragma clang diagnostic ignored "-Wcomma"
#endif

runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f)
{
    auto error = [](const QString& msg) { return module_status_mixin::error(msg); };

    module_status status =
        error(tr("Library load failure"));

    using namespace options;

    with_tracker_teardown sentinel;

    pProtocol = make_dylib_instance<IProtocol>(p);

    if (!pProtocol)
    {
        qDebug() << "protocol dylib load failure";
        goto end;
    }

    if(status = pProtocol->initialize(), !status.is_ok())
    {
        status = error(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 (f && f->Constructor && !pFilter)
    {
        qDebug() << "filter load failure";
        goto end;
    }

    if (pFilter)
        if(status = pFilter->initialize(), !status.is_ok())
        {
            status = error(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 = error(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);
}