diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-30 17:22:02 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-30 17:22:34 +0100 |
commit | 2af0ddbcf5cf32e4f6e8e1e3993a1aca0c409c90 (patch) | |
tree | b32c4bfbfdeafcdcad72e383edbb04b8f8ada797 | |
parent | ea2660dd167a853e704f167410037da162eccc6f (diff) |
add initial, untested opentrack-api.dll
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
-rw-r--r-- | CMakeLists.txt | 26 | ||||
-rw-r--r-- | opentrack-api/context.cpp | 108 | ||||
-rw-r--r-- | opentrack-api/opentrack-api.cpp | 13 | ||||
-rw-r--r-- | opentrack-api/opentrack-guts.h | 40 | ||||
-rw-r--r-- | opentrack-api/opentrack.h | 57 | ||||
-rw-r--r-- | opentrack-api/trackers.cpp | 38 |
6 files changed, 274 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a4daad1..0eb1b3c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -add_definitions(-DOPENTRACK_API) +add_definitions(-DOPENTRACK_API -DIN_OPENTRACK) if(MSVC) add_definitions(-DNOMINMAX) @@ -154,6 +154,9 @@ else() endif() # main app +file(GLOB opentrack-lib-c "opentrack-api/*.cpp") +file(GLOB opentrack-lib-h "opentrack-api/*.h") + file(GLOB opentrack-bin-c "facetracknoir/*.cpp" "facetracknoir/*.rc") file(GLOB opentrack-bin-h "facetracknoir/*.h") file(GLOB opentrack-bin-ui "facetracknoir/*.ui") @@ -608,6 +611,12 @@ add_executable(opentrack ${opentrack-win32-executable} ${opentrack-bin-c} ${open set_target_properties(opentrack PROPERTIES COMPILE_DEFINITIONS OPENTRACK_VERSION=\"${OPENTRACK__COMMIT}\") set(OPENTRACK_COMMIT_VERSION \"${OPENTRACK__COMMIT}\") configure_file("${CMAKE_SOURCE_DIR}/opentrack-version.h" "${CMAKE_BINARY_DIR}/opentrack-version.h" @ONLY NEWLINE_STYLE UNIX) + +add_library(opentrack-api ${opentrack-lib-c} ${opentrack-lib-h} ${opentrack-lib-moc}) +target_link_libraries(opentrack-api ${MY_QT_LIBS}) + +set_target_properties(opentrack PROPERTIES COMPILE_DEFINITIONS OPENTRACK_VERSION=\"${OPENTRACK__COMMIT}\") + if(UNIX) target_link_libraries(opentrack opentrack-qxt-mini) endif() @@ -631,15 +640,16 @@ endif() target_link_libraries(opentrack opentrack-pose-widget opentrack-spline-widget ${MY_QT_LIBS} ${QXT_QXTCORE_LIB_RELEASE} ${QXT_QXTWIDGETS_LIB_RELEASE}) if(NOT WIN32) target_link_libraries(opentrack dl) + target_link_libraries(opentrack-api dl) endif() - if(SDK_GOOGLE_BREAKPAD) - if(MSVC) - target_link_libraries(opentrack - "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/crash_generation_client.lib" - "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/exception_handler.lib" - "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/common.lib") - endif() +if(SDK_GOOGLE_BREAKPAD) + if(MSVC) + target_link_libraries(opentrack + "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/crash_generation_client.lib" + "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/exception_handler.lib" + "${SDK_GOOGLE_BREAKPAD}/src/client/windows/Release/lib/common.lib") endif() +endif() set_target_properties(opentrack PROPERTIES COMPILE_FLAGS -DOPENTRACK_MAIN) # make install diff --git a/opentrack-api/context.cpp b/opentrack-api/context.cpp new file mode 100644 index 00000000..100acf5c --- /dev/null +++ b/opentrack-api/context.cpp @@ -0,0 +1,108 @@ +#include "opentrack-guts.h" +#include "opentrack.h" + +#if defined(__APPLE__) +# define SONAME "dylib" +#elif defined(_WIN32) +# define SONAME "dll" +#else +# define SONAME "so" +#endif + +#include <iostream> + +#ifdef _MSC_VER +# define LIB_PREFIX "" +#else +# define LIB_PREFIX "lib" +#endif + +// shamelessly copied from core +static Metadata* get_metadata(DynamicLibrary* lib, QString& longName, QIcon& icon) +{ + Metadata* meta; + if (!lib->Metadata || ((meta = lib->Metadata()), !meta)) + return NULL; + meta->getFullName(&longName); + meta->getIcon(&icon); + return meta; +} + +static QList<opentrack_meta> list_files(QDir& dir, QString filter) +{ + QList<opentrack_meta> ret; + QStringList filenames = dir.entryList( QStringList() << (LIB_PREFIX + filter + ("*." SONAME)), QDir::Files, QDir::Name ); + for ( int i = 0; i < filenames.size(); i++) { + QIcon icon; + QString long_name; + QString str = filenames.at(i); + DynamicLibrary* lib = new DynamicLibrary(str); + qDebug() << "Loading" << str; + std::cout.flush(); + Metadata* meta; + if (!(meta = get_metadata(lib, long_name, icon))) + { + delete lib; + continue; + } + QString prefix(LIB_PREFIX + filter); + QString suffix("*." SONAME); + 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); + ret.push_back(item); + } + } + + return ret; +} + +opentrack_ctx::opentrack_ctx(QDir& dir) : + dir(dir), + meta_list(list_files(dir, "opentrack-tracker-")) +{ + const int count = meta_list.size(); + list = new char*[count + 1]; + for (int i = 0; i < count; i++) + { + QByteArray tmp = meta_list.at(i).path.toUtf8(); + int len = tmp.size(); + auto foo = new char[len+1]; + for (int j = 0; j < len; j++) + foo[j] = tmp.at(j); + foo[len] = '\0'; + list[i] = foo; + } + list[count] = NULL; +} + +opentrack_ctx::~opentrack_ctx() +{ + for (int i = 0; list[i]; i++) + { + delete list[i]; + } + delete list; +} + +extern "C" +{ + +const char** OPENTRACK_EXPORT opentrack_enum_trackers(opentrack ctx) +{ + return const_cast<const char**>(ctx->list); +} + +opentrack OPENTRACK_EXPORT opentrack_make_ctx(const char *dir) +{ + QDir d(dir); + return new opentrack_ctx(d); +} + +void OPENTRACK_EXPORT opentrack_finalize_ctx(opentrack foo) +{ + delete foo; +} + +} diff --git a/opentrack-api/opentrack-api.cpp b/opentrack-api/opentrack-api.cpp new file mode 100644 index 00000000..acb6d823 --- /dev/null +++ b/opentrack-api/opentrack-api.cpp @@ -0,0 +1,13 @@ +#include "opentrack-guts.h" +#include "opentrack.h" + +opentrack opentrack_make_ctx(const char *dir) +{ + QDir d(dir); + return new opentrack_ctx(d); +} + +void opentrack_finalize_ctx(opentrack bye_bye) +{ + delete bye_bye; +} diff --git a/opentrack-api/opentrack-guts.h b/opentrack-api/opentrack-guts.h new file mode 100644 index 00000000..1061d75d --- /dev/null +++ b/opentrack-api/opentrack-guts.h @@ -0,0 +1,40 @@ +#pragma once + +#include "ftnoir_tracker_base/ftnoir_tracker_base.h" +#include "facetracknoir/global-settings.h" +#include <QString> +#include <QDir> +#include <QList> +#include <QStringList> +#include <QDebug> +#include <QIcon> +#include <iostream> +#include <cstring> + +typedef ITracker* opentrack_tracker; + +class opentrack_meta { +public: + Metadata* meta; + QString path; + DynamicLibrary* lib; + + opentrack_meta(Metadata* meta, QString& path, DynamicLibrary* lib) : + meta(meta), path(path), lib(lib) + {} + ~opentrack_meta() + { + delete meta; + delete lib; + } +}; + +typedef class opentrack_ctx { +public: + QDir dir; + char** list; + QList<opentrack_meta> meta_list; + QFrame fake_frame; + opentrack_ctx(QDir& dir); + ~opentrack_ctx(); +} *opentrack; diff --git a/opentrack-api/opentrack.h b/opentrack-api/opentrack.h new file mode 100644 index 00000000..afd5506b --- /dev/null +++ b/opentrack-api/opentrack.h @@ -0,0 +1,57 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +#ifndef IN_OPENTRACK + /* opaque pointers, forward definitions */ + struct opentrack_opaque_ctx; + typedef opentrack_opaque_ctx* opentrack; + struct opentrack_opaque_tracker; + typedef opentrack_opaque_tracker* opentrack_tracker; +#endif + +#ifdef IN_OPENTRACK +# ifdef _WIN32 +# define OPENTRACK_EXPORT __declspec(dllexport) +# else +# define OPENTRACK_EXPORT +# endif +#else +# ifdef _WIN32 +# define OPENTRACK_EXPORT __declspec(dllimport) +# else +# define OPENTRACK_EXPORT +# endif +#endif + + /* for `opentrack_tracker_tick', individual headpose elts */ +#ifndef IN_OPENTRACK + enum opentrack_dof { + TX = 0, + TY, + TZ, + Yaw, + Pitch, + Roll, + DOF_count + }; +#endif + + opentrack opentrack_make_ctx(const char* dir); + void opentrack_finalize_ctx(opentrack self); + + /* no need to free the return value; invalid to modify it */ + const char** opentrack_enum_trackers(opentrack self); + + /* + * don't `opentrack_tracker_tick an unstarted tracker, it's invalid to do so + * it's also invalid to start a finalized tracker + */ + opentrack_tracker opentrack_make_tracker(opentrack ctx, const char* name); + void opentrack_tracker_start(opentrack self, opentrack_tracker tracker); + int opentrack_tracker_tick(opentrack_tracker tracker, double* headpose); + void opentrack_finalize_tracker(opentrack_tracker tracker); +#ifdef __cplusplus +} +#endif diff --git a/opentrack-api/trackers.cpp b/opentrack-api/trackers.cpp new file mode 100644 index 00000000..2527017b --- /dev/null +++ b/opentrack-api/trackers.cpp @@ -0,0 +1,38 @@ +#include "opentrack-guts.h" +#include "opentrack.h" + +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]; + if (ctx->meta_list.at(i).path == name) + { + ITracker* foo = reinterpret_cast<ITracker*>(meta.lib->Constructor()); + return foo; + } + } + return NULL; +} + +void OPENTRACK_EXPORT opentrack_finalize_tracker(opentrack_tracker tracker) +{ + delete tracker; +} + +void OPENTRACK_EXPORT opentrack_tracker_start(opentrack self, opentrack_tracker tracker) +{ + // hot damn, this is problematic! + // need to pass QFrame from somewhere + return tracker->StartTracker(&self->fake_frame); +} + +int OPENTRACK_EXPORT opentrack_tracker_tick(opentrack_tracker tracker, double* headpose) +{ + return tracker->GiveHeadPoseData(headpose); +} + +} |