| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2024 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "epphandler.h" |
| 5 | |
| 6 | #include "common/stringutils.h" |
| 7 | #include "core/icommandqueue.h" |
| 8 | #include <algorithm> |
| 9 | #include <utility> |
| 10 | |
| 11 | EPPHandler::EPPHandler( |
| 12 | std::unique_ptr<IDataSource<std::string>> &&avaiableEPPHintsDataSource, |
| 13 | std::vector<std::unique_ptr<IDataSource<std::string>>> &&eppHintDataSources) noexcept |
| 14 | : avaiableEPPHintsDataSource_(std::move(avaiableEPPHintsDataSource)) |
| 15 | , eppHintDataSources_(std::move(eppHintDataSources)) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | std::string const &EPPHandler::hint() const |
| 20 | { |
| 21 | return hint_; |
| 22 | } |
| 23 | |
| 24 | void EPPHandler::hint(std::string const &eppHint) |
| 25 | { |
| 26 | // only assign known EPP hints |
| 27 | auto iter = std::find_if( |
| 28 | hints().cbegin(), hints().cend(), |
| 29 | [&](auto const &availableHint) { return eppHint == availableHint; }); |
| 30 | if (iter != hints().cend()) |
| 31 | hint_ = eppHint; |
| 32 | } |
| 33 | |
| 34 | std::vector<std::string> const &EPPHandler::hints() const |
| 35 | { |
| 36 | return hints_; |
| 37 | } |
| 38 | |
| 39 | void EPPHandler::init() |
| 40 | { |
| 41 | if (avaiableEPPHintsDataSource_->read(dataSourceEntry_)) { |
| 42 | // set available hints |
| 43 | hints_ = Utils::String::split(dataSourceEntry_); |
| 44 | |
| 45 | // set default hint |
| 46 | hint("default"); |
| 47 | if (hint_.empty()) |
| 48 | hint(hints_.front()); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void EPPHandler::saveState() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | void EPPHandler::restoreState(ICommandQueue &) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void EPPHandler::reset(ICommandQueue &) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | void EPPHandler::sync(ICommandQueue &ctlCmds) |
| 65 | { |
| 66 | for (auto &eppHintDataSource : eppHintDataSources_) |
| 67 | if (eppHintDataSource->read(dataSourceEntry_)) { |
| 68 | if (dataSourceEntry_ != hint()) |
| 69 | ctlCmds.add({eppHintDataSource->source(), hint()}); |
| 70 | } |
| 71 | } |