summaryrefslogtreecommitdiffhomepage
path: root/api/plugin-api.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'api/plugin-api.hpp')
-rw-r--r--api/plugin-api.hpp141
1 files changed, 58 insertions, 83 deletions
diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp
index 4a797f73..2d77bdf4 100644
--- a/api/plugin-api.hpp
+++ b/api/plugin-api.hpp
@@ -14,20 +14,26 @@
#include <QIcon>
#include <QWidget>
#include <QDialog>
+#include <QCoreApplication>
-#include "compat/simple-mat.hpp"
+#include "../compat/simple-mat.hpp"
+#include "../compat/tr.hpp"
#include "export.hpp"
using Pose = Mat<double, 6, 1>;
-enum Axis {
- TX, TY, TZ, Yaw, Pitch, Roll,
-
+enum Axis : int
+{
NonAxis = -1,
+ TX = 0, TY = 1, TZ = 2,
+
+ Yaw = 3, Pitch = 4, Roll = 5,
+ Axis_MIN = TX, Axis_MAX = 5,
+
+ Axis_COUNT = 6,
};
-namespace plugin_api {
-namespace detail {
+namespace plugin_api::detail {
class OTR_API_EXPORT BaseDialog : public QDialog
{
@@ -36,50 +42,62 @@ protected:
BaseDialog();
public:
void closeEvent(QCloseEvent *) override;
+ virtual bool embeddable() noexcept;
+ virtual void set_buttons_visible(bool x); // XXX TODO remove it once all modules are converted
+ virtual void save(); // XXX HACK should be pure virtual
+ virtual void reload(); // XXX HACK should be pure virtual -sh 20211214
signals:
void closing();
private slots:
void done(int) override;
};
-} // ns
-} // ns
+} // ns plugin_api::detail
#define OTR_PLUGIN_EXPORT OTR_GENERIC_EXPORT
#define OPENTRACK_DECLARE_PLUGIN_INTERNAL(ctor_class, ctor_ret_class, metadata_class, dialog_class, dialog_ret_class) \
- extern "C" OTR_PLUGIN_EXPORT ctor_ret_class* GetConstructor(); \
- extern "C" OTR_PLUGIN_EXPORT Metadata* GetMetadata(); \
- extern "C" OTR_PLUGIN_EXPORT dialog_ret_class* GetDialog(); \
- \
- extern "C" OTR_PLUGIN_EXPORT ctor_ret_class* GetConstructor() \
- { \
- return new ctor_class; \
- } \
- extern "C" OTR_PLUGIN_EXPORT Metadata* GetMetadata() \
- { \
- return new metadata_class; \
- } \
- extern "C" OTR_PLUGIN_EXPORT dialog_ret_class* GetDialog() \
- { \
- return new dialog_class; \
+ extern "C" \
+ { \
+ OTR_PLUGIN_EXPORT ctor_ret_class* GetConstructor(void); \
+ ctor_ret_class* GetConstructor(void) \
+ { \
+ return new ctor_class; \
+ } \
+ OTR_PLUGIN_EXPORT Metadata_* GetMetadata(void); \
+ Metadata_* GetMetadata(void) \
+ { \
+ return new metadata_class; \
+ } \
+ OTR_PLUGIN_EXPORT dialog_ret_class* GetDialog(void); \
+ dialog_ret_class* GetDialog(void) \
+ { \
+ return new dialog_class; \
+ } \
}
// implement this in all plugins
// also you must link against "opentrack-api" in CMakeLists.txt to avoid vtable link errors
-struct OTR_API_EXPORT Metadata
+class OTR_API_EXPORT Metadata_
{
- Metadata(const Metadata&) = delete;
- Metadata(Metadata&&) = delete;
- Metadata& operator=(const Metadata&) = delete;
- Metadata();
+public:
+ Metadata_();
// plugin name to be displayed in the interface
virtual QString name() = 0;
// plugin icon, you can return an empty QIcon()
virtual QIcon icon() = 0;
// optional destructor
- virtual ~Metadata();
+ virtual ~Metadata_();
+};
+
+class OTR_API_EXPORT Metadata : public TR, public Metadata_
+{
+ Q_OBJECT
+
+public:
+ Metadata();
+ ~Metadata() override;
};
struct OTR_API_EXPORT module_status final
@@ -87,7 +105,8 @@ struct OTR_API_EXPORT module_status final
QString error;
bool is_ok() const;
- module_status(const QString& error = QString());
+ module_status();
+ module_status(const QString& error);
};
/*
@@ -99,18 +118,20 @@ struct OTR_API_EXPORT module_status_mixin
static module_status error(const QString& error); // return error message on init failure
virtual module_status initialize() = 0; // where to return from
+ virtual ~module_status_mixin();
+
+ Q_DECLARE_TR_FUNCTIONS(module_status_mixin)
};
// implement this in filters
struct OTR_API_EXPORT IFilter : module_status_mixin
{
IFilter(const IFilter&) = delete;
- IFilter(IFilter&&) = delete;
IFilter& operator=(const IFilter&) = delete;
IFilter();
// optional destructor
- virtual ~IFilter();
+ ~IFilter() override;
// perform filtering step.
// you have to take care of dt on your own, try "opentrack-compat/timer.hpp"
virtual void filter(const double *input, double *output) = 0;
@@ -121,6 +142,7 @@ struct OTR_API_EXPORT IFilter : module_status_mixin
struct OTR_API_EXPORT IFilterDialog : public plugin_api::detail::BaseDialog
{
IFilterDialog();
+ ~IFilterDialog() override;
// optional destructor
//~IFilterDialog() override;
@@ -138,16 +160,14 @@ struct OTR_API_EXPORT IFilterDialog : public plugin_api::detail::BaseDialog
struct OTR_API_EXPORT IProtocol : module_status_mixin
{
IProtocol();
+ ~IProtocol() override;
IProtocol(const IProtocol&) = delete;
- IProtocol(IProtocol&&) = delete;
IProtocol& operator=(const IProtocol&) = delete;
- // optional destructor
- virtual ~IProtocol();
// called 250 times a second with XYZ yaw pitch roll pose
// try not to perform intense computation here. use a thread.
- virtual void pose(const double* headpose) = 0;
+ virtual void pose(const double* pose, const double* raw) = 0;
// return game name or placeholder text
virtual QString game_name() = 0;
};
@@ -162,6 +182,7 @@ struct OTR_API_EXPORT IProtocolDialog : public plugin_api::detail::BaseDialog
virtual void unregister_protocol() = 0;
IProtocolDialog();
+ ~IProtocolDialog() override;
};
// call once with your chosen class names in the plugin
@@ -187,7 +208,6 @@ struct OTR_API_EXPORT ITracker
static module_status error(const QString& error);
ITracker(const ITracker&) = delete;
- ITracker(ITracker&&) = delete;
ITracker& operator=(const ITracker&) = delete;
};
@@ -201,55 +221,10 @@ struct OTR_API_EXPORT ITrackerDialog : public plugin_api::detail::BaseDialog
virtual void unregister_tracker();
ITrackerDialog();
+ ~ITrackerDialog() override;
};
// call once with your chosen class names in the plugin
#define OPENTRACK_DECLARE_TRACKER(tracker_class, dialog_class, metadata_class) \
OPENTRACK_DECLARE_PLUGIN_INTERNAL(tracker_class, ITracker, metadata_class, dialog_class, ITrackerDialog)
-struct OTR_API_EXPORT IExtension : module_status_mixin
-{
- enum event_mask : unsigned
- {
- none = 0u,
- on_raw = 1 << 0,
- on_before_filter = 1 << 1,
- on_before_mapping = 1 << 2,
- on_finished = 1 << 3,
- };
-
- enum event_ordinal : unsigned
- {
- ev_raw = 0,
- ev_before_filter = 1,
- ev_before_mapping = 2,
- ev_finished = 3,
-
- event_count = 4,
- };
-
- IExtension() = default;
- virtual ~IExtension();
-
- virtual event_mask hook_types() = 0;
-
- virtual void process_raw(Pose&) {}
- virtual void process_before_filter(Pose&) {}
- virtual void process_before_mapping(Pose&) {}
- virtual void process_finished(Pose&) {}
-
- IExtension(const IExtension&) = delete;
- IExtension(IExtension&&) = delete;
- IExtension& operator=(const IExtension&) = delete;
-};
-
-struct OTR_API_EXPORT IExtensionDialog : public plugin_api::detail::BaseDialog
-{
- ~IExtensionDialog() override;
-
- virtual void register_extension(IExtension& ext) = 0;
- virtual void unregister_extension() = 0;
-};
-
-#define OPENTRACK_DECLARE_EXTENSION(ext_class, dialog_class, metadata_class) \
- OPENTRACK_DECLARE_PLUGIN_INTERNAL(ext_class, IExtension, metadata_class, dialog_class, IExtensionDialog)