From 36ce07093b68b07513149577c209ae7a57ab356b Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周日, 15 3月 2020 16:26:21 +0800 Subject: [PATCH] Merge branch 'feature/pc_identifiers' into develop issues #2 #3 #14 #49 --- src/library/hw_identifier/identification_strategy.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/src/library/hw_identifier/identification_strategy.cpp b/src/library/hw_identifier/identification_strategy.cpp new file mode 100644 index 0000000..273c670 --- /dev/null +++ b/src/library/hw_identifier/identification_strategy.cpp @@ -0,0 +1,60 @@ +#include <array> +#include "identification_strategy.hpp" +#include "default_strategy.hpp" +#include "ethernet.hpp" +#include "disk_strategy.hpp" +namespace license { +namespace hw_identifier { + +using namespace std; +LCC_EVENT_TYPE IdentificationStrategy::validate_identifier(const HwIdentifier& identifier) const { + LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; + + if (identifier.get_identification_strategy() == identification_strategy()) { + const vector<HwIdentifier> available_ids = alternative_ids(); + for (const auto& it : available_ids) { + if (it == identifier) { + result = LICENSE_OK; + break; + } + } + } + return result; +} + +FUNCTION_RETURN IdentificationStrategy::identify_pc(HwIdentifier& pc_id) const { + vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data; + const vector<HwIdentifier> available_ids = alternative_ids(); + FUNCTION_RETURN result = FUNC_RET_NOT_AVAIL; + if (available_ids.size() > 0) { + pc_id = available_ids[0]; + result = FUNC_RET_OK; + } + return result; +} + +std::unique_ptr<IdentificationStrategy> IdentificationStrategy::get_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { + unique_ptr<IdentificationStrategy> result; + switch (strategy) { + case STRATEGY_DEFAULT: + result = unique_ptr<IdentificationStrategy>(dynamic_cast<IdentificationStrategy*>(new DefaultStrategy())); + break; + case STRATEGY_ETHERNET: + result = unique_ptr<IdentificationStrategy>(dynamic_cast<IdentificationStrategy*>(new Ethernet(false))); + break; + case STRATEGY_IP_ADDRESS: + result = unique_ptr<IdentificationStrategy>(dynamic_cast<IdentificationStrategy*>(new Ethernet(true))); + break; + case STRATEGY_DISK_NUM: + result = unique_ptr<IdentificationStrategy>(dynamic_cast<IdentificationStrategy*>(new DiskStrategy(true))); + break; + case STRATEGY_DISK_LABEL: + result = unique_ptr<IdentificationStrategy>(dynamic_cast<IdentificationStrategy*>(new DiskStrategy(false))); + break; + default: + throw logic_error("strategy not supported"); + } + return result; +} +} // namespace hw_identifier +} // namespace license -- Gitblit v1.9.1