diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-30 23:09:36 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-30 23:09:36 +0100 |
commit | 657cf32cb57257556c26f702e9e09b0edb15f350 (patch) | |
tree | 7ce5f6642a3be972c37da9822c123dd61093c9b0 | |
parent | fde903fda58eb715147150c8dbc2e16970ab1761 (diff) |
make standalone libopentrack-api.so work
-rw-r--r-- | opentrack-api/context.cpp | 20 | ||||
-rw-r--r-- | opentrack-api/opentrack-guts.h | 27 | ||||
-rw-r--r-- | opentrack-api/opentrack.h | 6 | ||||
-rw-r--r-- | opentrack-api/trackers.cpp | 9 |
4 files changed, 36 insertions, 26 deletions
diff --git a/opentrack-api/context.cpp b/opentrack-api/context.cpp index 9b8aa718..e0fd5357 100644 --- a/opentrack-api/context.cpp +++ b/opentrack-api/context.cpp @@ -27,10 +27,12 @@ static Metadata* get_metadata(DynamicLibrary* lib, QString& longName, QIcon& ico return meta; } -static QList<opentrack_meta> list_files(QDir& dir, QString filter) +static QList<opentrack_meta> list_files(QString filter) { QList<opentrack_meta> ret; - QStringList filenames = dir.entryList( QStringList() << (LIB_PREFIX + filter + ("*." SONAME)), QDir::Files, QDir::Name ); + QStringList filenames = QDir((qApp->applicationDirPath())).entryList( + QStringList() << (LIB_PREFIX + filter + ("*." SONAME)), + QDir::Files, QDir::Name ); for ( int i = 0; i < filenames.size(); i++) { QIcon icon; QString long_name; @@ -49,7 +51,7 @@ static QList<opentrack_meta> list_files(QDir& dir, QString filter) if (str.size() > prefix.size() + suffix.size() && str.startsWith(prefix) && str.endsWith(suffix)) { auto str2 = str.mid(prefix.size(), str.size() - prefix.size() - suffix.size()); - opentrack_meta item(meta, str2, lib); + opentrack_meta item(str2, lib); ret.push_back(item); } } @@ -57,9 +59,10 @@ static QList<opentrack_meta> list_files(QDir& dir, QString filter) return ret; } -opentrack_ctx::opentrack_ctx(QDir& dir) : - dir(dir), - meta_list(list_files(dir, "opentrack-tracker-")) +opentrack_ctx::opentrack_ctx(int argc, char** argv, void* window_parent) : + app(argc, argv), + meta_list(list_files("opentrack-tracker-")), + fake_frame(window_parent) { const int count = meta_list.size(); list = new char*[count + 1]; @@ -93,10 +96,9 @@ const char** opentrack_enum_trackers(opentrack ctx) return const_cast<const char**>(ctx->list); } -opentrack opentrack_make_ctx(const char *dir) +opentrack opentrack_make_ctx(int argc, char** argv, void* window_parent) { - QDir d(dir); - return new opentrack_ctx(d); + return new opentrack_ctx(argc, argv, window_parent); } void opentrack_finalize_ctx(opentrack foo) diff --git a/opentrack-api/opentrack-guts.h b/opentrack-api/opentrack-guts.h index b9c3878b..fd94ea34 100644 --- a/opentrack-api/opentrack-guts.h +++ b/opentrack-api/opentrack-guts.h @@ -1,5 +1,6 @@ #pragma once +#include <QFrame> #include <QDir> #include <QList> #include <QStringList> @@ -8,33 +9,39 @@ #include <iostream> #include <cstring> #include <QString> +#include <QApplication> #include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "facetracknoir/global-settings.h" +#include <memory> typedef ITracker* opentrack_tracker; class opentrack_meta { public: - Metadata* meta; QString path; - DynamicLibrary* lib; + std::shared_ptr<DynamicLibrary> lib; - opentrack_meta(Metadata* meta, QString& path, DynamicLibrary* lib) : - meta(meta), path(path), lib(lib) + opentrack_meta(QString& path, DynamicLibrary* lib) : + path(path), lib(lib) {} - ~opentrack_meta() +}; + +class MyFrame : public QFrame { + Q_OBJECT +public: + MyFrame(void* parent) { - delete meta; - delete lib; + create((WId) parent); } + explicit MyFrame() {} }; typedef class opentrack_ctx { public: - QDir dir; + QApplication app; char** list; QList<opentrack_meta> meta_list; - QFrame fake_frame; - opentrack_ctx(QDir& dir); + MyFrame fake_frame; + opentrack_ctx(int argc, char** argv, void* window_parent); ~opentrack_ctx(); } *opentrack; diff --git a/opentrack-api/opentrack.h b/opentrack-api/opentrack.h index 1c8fcee5..63136abc 100644 --- a/opentrack-api/opentrack.h +++ b/opentrack-api/opentrack.h @@ -6,9 +6,9 @@ extern "C" { #ifndef IN_OPENTRACK /* opaque pointers, forward definitions */ struct opentrack_opaque_ctx; -typedef opentrack_opaque_ctx* opentrack; +typedef struct opentrack_opaque_ctx* opentrack; struct opentrack_opaque_tracker; -typedef opentrack_opaque_tracker* opentrack_tracker; +typedef struct opentrack_opaque_tracker* opentrack_tracker; #endif #ifdef IN_OPENTRACK @@ -42,7 +42,7 @@ enum opentrack_dof { }; #endif -opentrack opentrack_make_ctx(const char* dir); +opentrack opentrack_make_ctx(int argc, char** argv, void* window_parent); void opentrack_finalize_ctx(opentrack self); /* no need to free the return value; invalid to modify it */ diff --git a/opentrack-api/trackers.cpp b/opentrack-api/trackers.cpp index 2527017b..0f698e4c 100644 --- a/opentrack-api/trackers.cpp +++ b/opentrack-api/trackers.cpp @@ -5,13 +5,12 @@ extern "C" { opentrack_tracker OPENTRACK_EXPORT opentrack_make_tracker(opentrack ctx, const char* name) { - QString n(name); for (int i = 0; i < ctx->meta_list.size(); i++) { - auto meta = ctx->meta_list[i]; + auto meta = ctx->meta_list.at(i); if (ctx->meta_list.at(i).path == name) { - ITracker* foo = reinterpret_cast<ITracker*>(meta.lib->Constructor()); + ITracker* foo = static_cast<ITracker*>(meta.lib->Constructor()); return foo; } } @@ -32,7 +31,9 @@ void OPENTRACK_EXPORT opentrack_tracker_start(opentrack self, opentrack_tracker int OPENTRACK_EXPORT opentrack_tracker_tick(opentrack_tracker tracker, double* headpose) { - return tracker->GiveHeadPoseData(headpose); + int ret = tracker->GiveHeadPoseData(headpose); + QApplication::processEvents(0, 5); + return ret; } } |