summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-22 10:24:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-23 11:05:33 +0200
commitc25ad3f1936028590358558bbf87b80c33613261 (patch)
treea40745ba9125cc7b9dc61d5f9353d7b5034065fc
parent81310e18abba8d17289cde6670e62d96f24e9d01 (diff)
logic/work: move from header
-rw-r--r--opentrack-logic/work.cpp32
-rw-r--r--opentrack-logic/work.hpp50
2 files changed, 45 insertions, 37 deletions
diff --git a/opentrack-logic/work.cpp b/opentrack-logic/work.cpp
new file mode 100644
index 00000000..820112bf
--- /dev/null
+++ b/opentrack-logic/work.cpp
@@ -0,0 +1,32 @@
+#include "work.hpp"
+
+
+Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) :
+ libs(libs),
+ tracker(std::make_shared<Tracker>(m, libs)),
+ sc(std::make_shared<Shortcuts>()),
+ handle(handle),
+ keys {
+ key_tuple(s.key_center, [&](bool) -> void { tracker->center(); }, true),
+ key_tuple(s.key_toggle, [&](bool) -> void { tracker->toggle_enabled(); }, true),
+ key_tuple(s.key_zero, [&](bool) -> void { tracker->zero(); }, true),
+ key_tuple(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false),
+ key_tuple(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false),
+ }
+{
+ reload_shortcuts();
+ tracker->start();
+}
+
+void Work::reload_shortcuts()
+{
+ sc->reload(keys);
+}
+
+Work::~Work()
+{
+ sc = nullptr;
+ // order matters, otherwise use-after-free -sh
+ tracker = nullptr;
+ libs = SelectedLibraries();
+}
diff --git a/opentrack-logic/work.hpp b/opentrack-logic/work.hpp
index 37bc58bf..70322be2 100644
--- a/opentrack-logic/work.hpp
+++ b/opentrack-logic/work.hpp
@@ -12,52 +12,28 @@
#include "opentrack/plugin-support.hpp"
#include "tracker.h"
#include "shortcuts.h"
+#include "export.hpp"
#include <QObject>
#include <QFrame>
#include <memory>
#include <vector>
-#include <functional>
#include <tuple>
+#include <functional>
-struct Work
+struct OPENTRACK_LOGIC_EXPORT Work
{
- main_settings s;
+ using fn_t = std::function<void(bool)>;
+ using key_tuple = std::tuple<key_opts&, fn_t, bool>;
+
SelectedLibraries& libs;
- mem<Tracker> tracker;
- mem<Shortcuts> sc;
+ std::shared_ptr<Tracker> tracker;
+ std::shared_ptr<Shortcuts> sc;
WId handle;
- using fn = std::function<void(bool)>;
- using tt = std::tuple<key_opts&, fn, bool>;
- std::vector<tt> keys;
-
- Work(Mappings& m, SelectedLibraries& libs, WId handle) :
- libs(libs),
- tracker(std::make_shared<Tracker>(m, libs)),
- sc(std::make_shared<Shortcuts>()),
- handle(handle),
- keys {
- tt(s.key_center, [&](bool) -> void { tracker->center(); }, true),
- tt(s.key_toggle, [&](bool) -> void { tracker->toggle_enabled(); }, true),
- tt(s.key_zero, [&](bool) -> void { tracker->zero(); }, true),
- tt(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false),
- tt(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false),
- }
- {
- reload_shortcuts();
- tracker->start();
- }
-
- void reload_shortcuts()
- {
- sc->reload(keys);
- }
+ std::vector<key_tuple> keys;
+ main_settings s;
- ~Work()
- {
- sc = nullptr;
- // order matters, otherwise use-after-free -sh
- tracker = nullptr;
- libs = SelectedLibraries();
- }
+ Work(Mappings& m, SelectedLibraries& libs, WId handle);
+ ~Work();
+ void reload_shortcuts();
};