| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "control.h" |
| 5 | |
| 6 | Control::Control(bool active, bool forceClean) noexcept |
| 7 | : active_(active) |
| 8 | , forceClean_(forceClean) |
| 9 | { |
| 10 | } |
| 11 | |
| 12 | bool Control::active() const |
| 13 | { |
| 14 | return active_; |
| 15 | } |
| 16 | |
| 17 | void Control::activate(bool active) |
| 18 | { |
| 19 | if (active_ && !active) |
| 20 | dirty(true); |
| 21 | |
| 22 | active_ = active; |
| 23 | } |
| 24 | |
| 25 | void Control::cleanOnce() |
| 26 | { |
| 27 | dirty(true); |
| 28 | } |
| 29 | |
| 30 | void Control::importWith(Importable::Importer &i) |
| 31 | { |
| 32 | auto importer = i.provideImporter(*this); |
| 33 | if (importer.has_value()) { |
| 34 | auto &controlImporter = dynamic_cast<IControl::Importer &>(importer->get()); |
| 35 | |
| 36 | activate(controlImporter.provideActive()); |
| 37 | importControl(controlImporter); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void Control::exportWith(Exportable::Exporter &e) const |
| 42 | { |
| 43 | auto exporter = e.provideExporter(*this); |
| 44 | if (exporter.has_value()) { |
| 45 | auto &controlExporter = dynamic_cast<IControl::Exporter &>(exporter->get()); |
| 46 | |
| 47 | controlExporter.takeActive(active()); |
| 48 | exportControl(controlExporter); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void Control::clean(ICommandQueue &ctlCmds) |
| 53 | { |
| 54 | if (forceClean_ || dirty()) { |
| 55 | cleanControl(ctlCmds); |
| 56 | dirty(false); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void Control::sync(ICommandQueue &ctlCmds) |
| 61 | { |
| 62 | if (active()) |
| 63 | syncControl(ctlCmds); |
| 64 | } |
| 65 | |
| 66 | bool Control::dirty() const |
| 67 | { |
| 68 | return dirty_; |
| 69 | } |
| 70 | |
| 71 | void Control::dirty(bool isDirty) |
| 72 | { |
| 73 | dirty_ = isDirty; |
| 74 | } |