summaryrefslogtreecommitdiffhomepage
path: root/logic
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-02 06:28:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-02 06:28:18 +0200
commit04ff6af035a2e1064cce2b3189c13f7a45fdca4a (patch)
tree7f1b33342159de089436259ad79e94306ecf2422 /logic
parentb09f2c2d699dff8c61eb0a83143c5930c005703f (diff)
logic: split extension handling to own file
Diffstat (limited to 'logic')
-rw-r--r--logic/extensions.cpp67
-rw-r--r--logic/extensions.hpp36
-rw-r--r--logic/runtime-libraries.cpp31
-rw-r--r--logic/runtime-libraries.hpp18
4 files changed, 105 insertions, 47 deletions
diff --git a/logic/extensions.cpp b/logic/extensions.cpp
new file mode 100644
index 00000000..c8a6a73b
--- /dev/null
+++ b/logic/extensions.cpp
@@ -0,0 +1,67 @@
+#include "extensions.hpp"
+
+#include <functional>
+#include "compat/util.hpp"
+
+using namespace options;
+
+using ext_fun_type = void(IExtension::*)(Pose&);
+using ext_mask = IExtension::event_mask;
+using ext_ord = IExtension::event_ordinal;
+
+static constexpr struct event_type_mapping
+{
+ ext_fun_type ptr;
+ ext_mask mask;
+ ext_ord idx;
+} ordinal_to_function[] = {
+ { &IExtension::process_raw, ext_mask::on_raw, ext_ord::ev_raw, },
+ { &IExtension::process_after_center, ext_mask::on_after_center, ext_ord::ev_after_center, },
+ { &IExtension::process_before_filter, ext_mask::on_before_filter, ext_ord::ev_before_filter, },
+ { &IExtension::process_before_transform, ext_mask::on_before_transform, ext_ord::ev_before_transform, },
+ { &IExtension::process_before_mapping, ext_mask::on_before_mapping, ext_ord::ev_before_mapping, },
+ { &IExtension::process_finished, ext_mask::on_finished, ext_ord::ev_finished, },
+};
+
+bool ext_settings::is_enabled(const QString& name)
+{
+ static const bundle b = make_bundle("extensions");
+
+ if (!b->contains(name))
+ return false;
+
+ return b->get<bool>(name);
+}
+
+event_handler::event_handler(Modules::dylib_list const& extensions)
+{
+ for (std::shared_ptr<dylib> const& lib : extensions)
+ {
+ std::shared_ptr<IExtension> ext(reinterpret_cast<IExtension*>(lib->Constructor()));
+ std::shared_ptr<IExtensionDialog> dlg(reinterpret_cast<IExtensionDialog*>(lib->Dialog()));
+ std::shared_ptr<Metadata> m(reinterpret_cast<Metadata*>(lib->Meta()));
+
+ const ext_mask mask = ext->hook_types();
+
+ if (!ext_settings::is_enabled(lib->module_name))
+ continue;
+
+ for (event_type_mapping const& mapping : ordinal_to_function)
+ {
+ const unsigned i = mapping.idx;
+ const ext_mask mask_ = mapping.mask;
+
+ if (mask & mask_)
+ extension_events[i].push_back({ ext, dlg, m });
+ }
+ }
+}
+
+void event_handler::run_events(event_ordinal k, Pose& pose)
+{
+ auto fun = std::mem_fn(ordinal_to_function[k].ptr);
+
+ for (extension& x : extension_events[k])
+ fun(*x.logic, pose);
+}
+
diff --git a/logic/extensions.hpp b/logic/extensions.hpp
new file mode 100644
index 00000000..8cb4a989
--- /dev/null
+++ b/logic/extensions.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "api/plugin-support.hpp"
+#include "options/options.hpp"
+
+#include <vector>
+#include <array>
+
+struct event_handler final
+{
+ using event_ordinal = IExtension::event_ordinal;
+
+ struct extension
+ {
+ using ext = std::shared_ptr<IExtension>;
+ using dlg = std::shared_ptr<IExtensionDialog>;
+ using m = std::shared_ptr<Metadata>;
+
+ ext logic;
+ dlg dialog;
+ m metadata;
+ };
+
+ void run_events(event_ordinal k, Pose& pose);
+ event_handler(Modules::dylib_list const& extensions);
+
+private:
+ using ext_list = std::vector<extension>;
+ std::array<ext_list, IExtension::event_count> extension_events;
+};
+
+struct ext_settings final
+{
+ static bool is_enabled(const QString& name);
+ ext_settings() = delete;
+};
diff --git a/logic/runtime-libraries.cpp b/logic/runtime-libraries.cpp
index fbe30fef..eb5f02cc 100644
--- a/logic/runtime-libraries.cpp
+++ b/logic/runtime-libraries.cpp
@@ -1,25 +1,7 @@
-#include "selected-libraries.hpp"
+#include "runtime-libraries.hpp"
#include "options/scoped.hpp"
#include <QDebug>
-using ext_ord = IExtension::event_ordinal;
-using ext_mask = IExtension::event_mask;
-using ext_fun_type = void(IExtension::*)(Pose&);
-
-static constexpr struct event_type_mapping
-{
- ext_fun_type ptr;
- ext_mask m;
- ext_ord idx;
-} ordinal_to_function[] = {
- { &IExtension::process_raw, ext_mask::on_raw, ext_ord::ev_raw, },
- { &IExtension::process_after_center, ext_mask::on_after_center, ext_ord::ev_after_center, },
- { &IExtension::process_before_filter, ext_mask::on_before_filter, ext_ord::ev_before_filter, },
- { &IExtension::process_before_transform, ext_mask::on_before_transform, ext_ord::ev_before_transform, },
- { &IExtension::process_before_mapping, ext_mask::on_before_mapping, ext_ord::ev_before_mapping, },
- { &IExtension::process_finished, ext_mask::on_finished, ext_ord::ev_finished, },
-};
-
runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) :
pTracker(nullptr),
pFilter(nullptr),
@@ -63,14 +45,3 @@ end:
opts::set_teardown_flag(prev_teardown_flag);
}
-void runtime_event_handler::run_events(ext_event_ordinal k, Pose& pose)
-{
- auto fun = std::mem_fn(ordinal_to_function[k].ptr);
-
- for (ext& x : extension_events[k])
- {
- if (x == nullptr)
- break;
- fun(x, pose);
- }
-}
diff --git a/logic/runtime-libraries.hpp b/logic/runtime-libraries.hpp
index 6cfd8b57..cc96f0e7 100644
--- a/logic/runtime-libraries.hpp
+++ b/logic/runtime-libraries.hpp
@@ -11,25 +11,9 @@
#include "api/plugin-support.hpp"
#include "export.hpp"
-#include <array>
-#include <functional>
-
#include <QFrame>
-struct runtime_event_handler
-{
- using ext_event_ordinal = IExtension::event_ordinal;
- using ext = std::shared_ptr<IExtension>;
-
- enum : unsigned { ext_max_events = 64 };
- using ext_list = std::array<ext, ext_max_events>;
-
- std::array<ext_list, ext_event_ordinal::event_count> extension_events;
-
- void run_events(ext_event_ordinal k, Pose& pose);
-};
-
-struct OTR_LOGIC_EXPORT runtime_libraries final : runtime_event_handler
+struct OTR_LOGIC_EXPORT runtime_libraries final
{
using dylibptr = std::shared_ptr<dylib>;