From b256886a5cb9f2ae3ebda70a2045b19ed9f4233e Mon Sep 17 00:00:00 2001
From: Stanislaw Halik <sthalik@misaki.pl>
Date: Sun, 3 Dec 2017 22:23:08 +0100
Subject: api: add status check for modules

---
 api/plugin-api.cpp | 21 +++++++++++++++++++++
 api/plugin-api.hpp | 31 ++++++++++++++++++++++++-------
 2 files changed, 45 insertions(+), 7 deletions(-)

(limited to 'api')

diff --git a/api/plugin-api.cpp b/api/plugin-api.cpp
index c28b5d4e..eed377b0 100644
--- a/api/plugin-api.cpp
+++ b/api/plugin-api.cpp
@@ -26,6 +26,16 @@ void BaseDialog::closeEvent(QCloseEvent*)
 
 bool ITracker::center() { return false; }
 
+module_status ITracker::status_ok()
+{
+    return module_status();
+}
+
+module_status ITracker::error(const QString& error)
+{
+    return module_status(error);
+}
+
 Metadata::Metadata() {}
 IFilter::IFilter() {}
 IFilterDialog::IFilterDialog() {}
@@ -46,3 +56,14 @@ void BaseDialog::done(int)
 IExtensionDialog::~IExtensionDialog()
 {
 }
+
+bool module_status::is_ok() const
+{
+    return error.isEmpty();
+}
+
+module_status::module_status(const QString& error) : error(error) {}
+
+module_status module_status_mixin::status_ok() { return module_status(); }
+
+module_status module_status_mixin::error(const QString& error) { return module_status(error); }
diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp
index 29f678f3..15a2cc48 100644
--- a/api/plugin-api.hpp
+++ b/api/plugin-api.hpp
@@ -82,8 +82,24 @@ struct OTR_API_EXPORT Metadata
     virtual ~Metadata();
 };
 
+struct OTR_API_EXPORT module_status final
+{
+    QString error;
+
+    bool is_ok() const;
+    module_status(const QString& error = QString());
+};
+
+struct OTR_API_EXPORT module_status_mixin
+{
+    static module_status status_ok();
+    static module_status error(const QString& error);
+
+    virtual module_status check_status() = 0;
+};
+
 // implement this in filters
-struct OTR_API_EXPORT IFilter
+struct OTR_API_EXPORT IFilter : module_status_mixin
 {
     IFilter(const IFilter&) = delete;
     IFilter(IFilter&&) = delete;
@@ -116,7 +132,7 @@ struct OTR_API_EXPORT IFilterDialog : public plugin_api::detail::BaseDialog
     OPENTRACK_DECLARE_PLUGIN_INTERNAL(filter_class, IFilter, metadata_class, dialog_class, IFilterDialog)
 
 // implement this in protocols
-struct OTR_API_EXPORT IProtocol
+struct OTR_API_EXPORT IProtocol : module_status_mixin
 {
     IProtocol();
 
@@ -126,10 +142,8 @@ struct OTR_API_EXPORT IProtocol
 
     // optional destructor
     virtual ~IProtocol();
-    // return true if protocol was properly initialized
-    virtual bool correct() = 0;
     // called 250 times a second with XYZ yaw pitch roll pose
-    // try not to perform intense computation here. if you must, use a thread.
+    // try not to perform intense computation here. use a thread.
     virtual void pose(const double* headpose) = 0;
     // return game name or placeholder text
     virtual QString game_name() = 0;
@@ -159,13 +173,16 @@ struct OTR_API_EXPORT ITracker
     // optional destructor
     virtual ~ITracker();
     // start tracking, and grab a frame to display webcam video in, optionally
-    virtual void start_tracker(QFrame* frame) = 0;
+    virtual module_status start_tracker(QFrame* frame) = 0;
     // return XYZ yaw pitch roll data. don't block here, use a separate thread for computation.
     virtual void data(double *data) = 0;
     // tracker notified of centering
     // returning true makes identity the center pose
     virtual bool center();
 
+    static module_status status_ok();
+    static module_status error(const QString& error);
+
     ITracker(const ITracker&) = delete;
     ITracker(ITracker&&) = delete;
     ITracker& operator=(const ITracker&) = delete;
@@ -187,7 +204,7 @@ struct OTR_API_EXPORT ITrackerDialog : public plugin_api::detail::BaseDialog
 #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
+struct OTR_API_EXPORT IExtension : module_status_mixin
 {
     enum event_mask : unsigned
     {
-- 
cgit v1.2.3