diff options
Diffstat (limited to 'opentrack/plugin-support.cpp')
-rw-r--r-- | opentrack/plugin-support.cpp | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/opentrack/plugin-support.cpp b/opentrack/plugin-support.cpp index ec56b1e1..2c129906 100644 --- a/opentrack/plugin-support.cpp +++ b/opentrack/plugin-support.cpp @@ -5,6 +5,8 @@ #include <QFile> #include <QDir> +#include <iostream> + #ifndef _WIN32 # include <dlfcn.h> #endif @@ -14,16 +16,19 @@ SelectedLibraries::~SelectedLibraries() } template<typename t> -static ptr<t> make_instance(ptr<dylib> lib) +static mem<t> make_instance(mem<dylib> 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(); + mem<t> ret; + if (lib != nullptr && lib->Constructor) + { + qDebug() << "dylib" << (lib ? lib->filename : "<null>") << "ptr" << (intptr_t) lib->Constructor; + std::cout.flush(); + ret = mem<t>(reinterpret_cast<t*>(reinterpret_cast<CTOR_FUNPTR>(lib->Constructor)())); + } return ret; } -SelectedLibraries::SelectedLibraries(QFrame* frame, dylibtr t, dylibtr p, dylibtr f) : +SelectedLibraries::SelectedLibraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), @@ -32,20 +37,19 @@ SelectedLibraries::SelectedLibraries(QFrame* frame, dylibtr t, dylibtr p, dylibt pTracker = make_instance<ITracker>(t); pProtocol = make_instance<IProtocol>(p); pFilter = make_instance<IFilter>(f); - - if (!pTracker|| !pProtocol) + + if (!pTracker || !pProtocol) { - qDebug() << "load failure tracker" << (intptr_t)pTracker.get() << "protocol" << (intptr_t)pProtocol.get(); + qDebug() << "dylib load failure"; + return; + } + + if(!pProtocol->correct()) + { + qDebug() << "protocol load failure"; return; } - if (pProtocol) - if(!pProtocol->correct()) - { - qDebug() << "protocol load failure"; - return; - } - pTracker->start_tracker(frame); correct = true; @@ -67,7 +71,7 @@ SelectedLibraries::SelectedLibraries(QFrame* frame, dylibtr t, dylibtr p, dylibt # define LIB_PREFIX "lib" #endif -static bool get_metadata(ptr<dylib> lib, QString& name, QIcon& icon) +static bool get_metadata(mem<dylib> lib, QString& name, QIcon& icon) { Metadata* meta; if (!lib->Meta || ((meta = lib->Meta()), !meta)) @@ -78,7 +82,7 @@ static bool get_metadata(ptr<dylib> lib, QString& name, QIcon& icon) return true; } -QList<ptr<dylib>> dylib::enum_libraries() +QList<mem<dylib>> dylib::enum_libraries() { #define BASE "opentrack-" #define SUFF "-*." @@ -86,11 +90,11 @@ QList<ptr<dylib>> dylib::enum_libraries() BASE "tracker" SUFF, BASE "proto" SUFF }; const Type filters_t[] = { Filter, Tracker, Protocol }; - + QDir settingsDir( QCoreApplication::applicationDirPath() ); - - QList<ptr<dylib>> ret; - + + QList<mem<dylib>> ret; + for (int i = 0; i < 3; i++) { QString filter = filters_n[i]; @@ -110,7 +114,7 @@ QList<ptr<dylib>> dylib::enum_libraries() ret.push_back(lib); } } - + return ret; } @@ -123,12 +127,12 @@ dylib::dylib(const QString& filename, Type t) : // otherwise dlopen opens the calling executable if (filename.size() == 0) return; - + this->filename = filename; #if defined(_WIN32) QString fullPath = QCoreApplication::applicationDirPath() + "/" + this->filename; handle = new QLibrary(fullPath); - + struct _foo { static bool die(QLibrary*& l, bool failp) { @@ -141,18 +145,18 @@ dylib::dylib(const QString& filename, Type t) : return failp; } }; - + if (_foo::die(handle, !handle->load())) return; - + Dialog = (CTOR_FUNPTR) handle->resolve("GetDialog"); if (_foo::die(handle, !Dialog)) return; - + Constructor = (CTOR_FUNPTR) handle->resolve("GetConstructor"); if (_foo::die(handle, !Constructor)) return; - + Meta = (METADATA_FUNPTR) handle->resolve("GetMetadata"); if (_foo::die(handle, !Meta)) return; @@ -199,9 +203,9 @@ dylib::dylib(const QString& filename, Type t) : (void) _foo::err(handle); } #endif - - auto m = ptr<Metadata>(Meta()); - + + auto m = mem<Metadata>(Meta()); + icon = m->icon(); name = m->name(); } @@ -209,7 +213,8 @@ dylib::dylib(const QString& filename, Type t) : dylib::~dylib() { #if defined(_WIN32) - handle->unload(); + if (handle) + delete handle; #else if (handle) (void) dlclose(handle); |