gcontini
2020-02-15 483c73630a82fe8fbe9fe74cc8bbdd23a13d8b6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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