summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir
diff options
context:
space:
mode:
Diffstat (limited to 'facetracknoir')
-rw-r--r--facetracknoir/facetracknoir.cpp17
-rw-r--r--facetracknoir/facetracknoir.h18
-rw-r--r--facetracknoir/plugin-support.cpp17
-rw-r--r--facetracknoir/plugin-support.h9
4 files changed, 30 insertions, 31 deletions
diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp
index 73dae199..06777f94 100644
--- a/facetracknoir/facetracknoir.cpp
+++ b/facetracknoir/facetracknoir.cpp
@@ -43,7 +43,7 @@
# define LIB_PREFIX "lib"
#endif
-static bool get_metadata(DynamicLibrary* lib, QString& longName, QIcon& icon)
+static bool get_metadata(ptr<DynamicLibrary> lib, QString& longName, QIcon& icon)
{
Metadata* meta;
if (!lib->Metadata || ((meta = lib->Metadata()), !meta))
@@ -54,7 +54,7 @@ static bool get_metadata(DynamicLibrary* lib, QString& longName, QIcon& icon)
return true;
}
-static void fill_combobox(const QString& filter, QList<DynamicLibrary*>& list, QComboBox& cbx)
+static void fill_combobox(const QString& filter, QList<ptr<DynamicLibrary>>& list, QComboBox& cbx)
{
QDir settingsDir( QCoreApplication::applicationDirPath() );
QStringList filenames = settingsDir.entryList( QStringList() << (LIB_PREFIX + filter + SONAME), QDir::Files, QDir::Name );
@@ -62,14 +62,11 @@ static void fill_combobox(const QString& filter, QList<DynamicLibrary*>& list, Q
QIcon icon;
QString longName;
QString str = filenames.at(i);
- DynamicLibrary* lib = new DynamicLibrary(str);
+ auto lib = std::make_shared<DynamicLibrary>(str);
qDebug() << "Loading" << str;
std::cout.flush();
if (!get_metadata(lib, longName, icon))
- {
- delete lib;
continue;
- }
list.push_back(lib);
cbx.addItem(icon, longName);
}
@@ -116,7 +113,7 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : QMainWindow(parent),
connect(ui.btnShowServerControls, SIGNAL(clicked()), this, SLOT(showServerControls()));
connect(ui.btnShowFilterControls, SIGNAL(clicked()), this, SLOT(showFilterControls()));
- dlopen_filters.push_back((DynamicLibrary*) NULL);
+ dlopen_filters.push_back(nullptr);
ui.iconcomboFilter->addItem(QIcon(), "");
fill_combobox("opentrack-proto-*.", dlopen_protocols, *ui.iconcomboProtocol);
@@ -388,7 +385,7 @@ void FaceTrackNoIR::showTrackerSettings()
pTrackerDialog = NULL;
}
- DynamicLibrary* lib = dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> lib = dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), nullptr);
if (lib) {
pTrackerDialog = (ITrackerDialog*) lib->Dialog();
@@ -408,7 +405,7 @@ void FaceTrackNoIR::showServerControls() {
pProtocolDialog = NULL;
}
- DynamicLibrary* lib = dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> lib = dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), nullptr);
if (lib && lib->Dialog) {
pProtocolDialog = (IProtocolDialog*) lib->Dialog();
@@ -426,7 +423,7 @@ void FaceTrackNoIR::showFilterControls() {
pFilterDialog = NULL;
}
- DynamicLibrary* lib = dlopen_filters.value(ui.iconcomboFilter->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> lib = dlopen_filters.value(ui.iconcomboFilter->currentIndex(), nullptr);
if (lib && lib->Dialog) {
pFilterDialog = (IFilterDialog*) lib->Dialog();
diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h
index 040bb170..b13f73f0 100644
--- a/facetracknoir/facetracknoir.h
+++ b/facetracknoir/facetracknoir.h
@@ -67,14 +67,14 @@ public:
// XXX this shit stinks -sh 20141004
// TODO move to separate class representing running tracker state
- DynamicLibrary* current_tracker1() override {
- return dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> current_tracker1() override {
+ return dlopen_trackers.value(ui.iconcomboTrackerSource->currentIndex(), nullptr);
}
- DynamicLibrary* current_protocol() override {
- return dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> current_protocol() override {
+ return dlopen_protocols.value(ui.iconcomboProtocol->currentIndex(), nullptr);
}
- DynamicLibrary* current_filter() override {
- return dlopen_filters.value(ui.iconcomboFilter->currentIndex(), (DynamicLibrary*) NULL);
+ ptr<DynamicLibrary> current_filter() override {
+ return dlopen_filters.value(ui.iconcomboFilter->currentIndex(), nullptr);
}
#if defined(_WIN32)
@@ -108,9 +108,9 @@ private:
void loadSettings();
void updateButtonState(bool running, bool inertialp);
- QList<DynamicLibrary*> dlopen_filters;
- QList<DynamicLibrary*> dlopen_trackers;
- QList<DynamicLibrary*> dlopen_protocols;
+ QList<ptr<DynamicLibrary>> dlopen_filters;
+ QList<ptr<DynamicLibrary>> dlopen_trackers;
+ QList<ptr<DynamicLibrary>> dlopen_protocols;
QShortcut kbd_quit;
int looping;
diff --git a/facetracknoir/plugin-support.cpp b/facetracknoir/plugin-support.cpp
index e9154bb7..5b65df47 100644
--- a/facetracknoir/plugin-support.cpp
+++ b/facetracknoir/plugin-support.cpp
@@ -29,28 +29,27 @@ SelectedLibraries::SelectedLibraries(IDynamicLibraryProvider* mainApp) :
correct = false;
if (!mainApp)
return;
- CTOR_FUNPTR ptr;
- DynamicLibrary* lib;
+ CTOR_FUNPTR p;
- lib = mainApp->current_tracker1();
+ ptr<DynamicLibrary> lib = mainApp->current_tracker1();
if (lib && lib->Constructor) {
- ptr = (CTOR_FUNPTR) lib->Constructor;
- pTracker = (ITracker*) ptr();
+ p = (CTOR_FUNPTR) lib->Constructor;
+ pTracker = (ITracker*) p();
}
lib = mainApp->current_protocol();
if (lib && lib->Constructor) {
- ptr = (CTOR_FUNPTR) lib->Constructor;
- pProtocol = (IProtocol*) ptr();
+ p = (CTOR_FUNPTR) lib->Constructor;
+ pProtocol = (IProtocol*) p();
}
lib = mainApp->current_filter();
if (lib && lib->Constructor) {
- ptr = (CTOR_FUNPTR) lib->Constructor;
- pFilter = (IFilter*) ptr();
+ p = (CTOR_FUNPTR) lib->Constructor;
+ pFilter = (IFilter*) p();
}
if (pProtocol)
diff --git a/facetracknoir/plugin-support.h b/facetracknoir/plugin-support.h
index b539d152..7f8e3c28 100644
--- a/facetracknoir/plugin-support.h
+++ b/facetracknoir/plugin-support.h
@@ -8,6 +8,9 @@
#include <QLibrary>
#include <QFrame>
+#include <memory>
+template<typename t> using ptr = std::shared_ptr<t>;
+
class IDynamicLibraryProvider;
struct SelectedLibraries {
@@ -48,8 +51,8 @@ private:
// XXX TODO it can die if running tracker state separated into class -sh 20141004
class IDynamicLibraryProvider {
public:
- virtual DynamicLibrary* current_tracker1() = 0;
- virtual DynamicLibrary* current_protocol() = 0;
- virtual DynamicLibrary* current_filter() = 0;
+ virtual ptr<DynamicLibrary> current_tracker1() = 0;
+ virtual ptr<DynamicLibrary> current_protocol() = 0;
+ virtual ptr<DynamicLibrary> current_filter() = 0;
virtual QFrame* get_video_widget() = 0;
};