summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/plugin-support.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-10-19 12:42:48 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-10-19 13:39:03 +0200
commit0f0d663c6263a59e2cb14f555a00b39b19c134e7 (patch)
treed0dbcb75089b601204c92228e1577077e903ef55 /facetracknoir/plugin-support.cpp
parent9dc864f019d66d1b3ef9f46a824b72e416bdd4fc (diff)
main: refactor interlocked parts
Diffstat (limited to 'facetracknoir/plugin-support.cpp')
-rw-r--r--facetracknoir/plugin-support.cpp72
1 files changed, 30 insertions, 42 deletions
diff --git a/facetracknoir/plugin-support.cpp b/facetracknoir/plugin-support.cpp
index 5b65df47..b202fc74 100644
--- a/facetracknoir/plugin-support.cpp
+++ b/facetracknoir/plugin-support.cpp
@@ -1,4 +1,5 @@
#include <cstdio>
+#include <cinttypes>
#include "plugin-support.h"
#include <QCoreApplication>
#include <QFile>
@@ -7,57 +8,44 @@
# include <dlfcn.h>
#endif
-SelectedLibraries* Libraries = NULL;
-
SelectedLibraries::~SelectedLibraries()
{
- if (pTracker) {
- delete pTracker;
- pTracker = NULL;
- }
-
- if (pFilter)
- delete pFilter;
+}
- if (pProtocol)
- delete pProtocol;
+template<typename t>
+static ptr<t> make_instance(ptr<DynamicLibrary> lib)
+{
+ ptr<t> ret = nullptr;
+ if (lib && lib->Constructor)
+ ret = ptr<t>(reinterpret_cast<t*>(reinterpret_cast<CTOR_FUNPTR>(lib->Constructor)()));
+ qDebug() << "lib" << (lib ? lib->filename : "<null>") << "ptr" << (intptr_t)ret.get();
+ return ret;
}
-SelectedLibraries::SelectedLibraries(IDynamicLibraryProvider* mainApp) :
- pTracker(NULL), pFilter(NULL), pProtocol(NULL)
+SelectedLibraries::SelectedLibraries(QFrame* frame, dylib t, dylib p, dylib f) :
+ pTracker(nullptr),
+ pFilter(nullptr),
+ pProtocol(nullptr),
+ correct(false)
{
- correct = false;
- if (!mainApp)
+ pTracker = make_instance<ITracker>(t);
+ pProtocol = make_instance<IProtocol>(p);
+ pFilter = make_instance<IFilter>(f);
+
+ if (!pTracker|| !pProtocol)
+ {
+ qDebug() << "load failure tracker" << (intptr_t)pTracker.get() << "protocol" << (intptr_t)pProtocol.get();
return;
- CTOR_FUNPTR p;
-
- ptr<DynamicLibrary> lib = mainApp->current_tracker1();
-
- if (lib && lib->Constructor) {
- p = (CTOR_FUNPTR) lib->Constructor;
- pTracker = (ITracker*) p();
- }
-
- lib = mainApp->current_protocol();
-
- if (lib && lib->Constructor) {
- p = (CTOR_FUNPTR) lib->Constructor;
- pProtocol = (IProtocol*) p();
- }
-
- lib = mainApp->current_filter();
-
- if (lib && lib->Constructor) {
- p = (CTOR_FUNPTR) lib->Constructor;
- pFilter = (IFilter*) p();
}
if (pProtocol)
- if(!pProtocol->checkServerInstallationOK())
+ if(!pProtocol->correct())
+ {
+ qDebug() << "protocol load failure";
return;
- if (pTracker) {
- pTracker->StartTracker( mainApp->get_video_widget() );
- }
+ }
+
+ pTracker->start_tracker(frame);
correct = true;
}
@@ -88,7 +76,7 @@ DynamicLibrary::DynamicLibrary(const QString& filename) :
if (_foo::die(handle, !handle->load()))
return;
- Dialog = (DIALOG_FUNPTR) handle->resolve("GetDialog");
+ Dialog = (CTOR_FUNPTR) handle->resolve("GetDialog");
if (_foo::die(handle, !Dialog))
return;
@@ -131,7 +119,7 @@ DynamicLibrary::DynamicLibrary(const QString& filename) :
{
if (_foo::err(handle))
return;
- Dialog = (DIALOG_FUNPTR) dlsym(handle, "GetDialog");
+ Dialog = (CTOR_FUNPTR) dlsym(handle, "GetDialog");
if (_foo::err(handle))
return;
Constructor = (CTOR_FUNPTR) dlsym(handle, "GetConstructor");