summaryrefslogtreecommitdiffstats
path: root/veslibrary/ves_cpplibrary/src/lib/encode/XCounterImp.cpp
blob: 96036a8b9e4cee54b17a4bbb45b0ecea2b788092 (plain)
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
#include "XCounterImp.h"

const std::string XEnumCounterCriticalityMapping[] = {
    "CRIT",
    "MAJ"
};

XCounterImp::XCounterImp(XEnumCounterCriticality criticality,
    const XHashMap& hashMap,
    const XString& thresholdCrossed) :
    criticality_(criticality),
    hashMap_(hashMap),
    thresholdCrossed_(thresholdCrossed)
{

}

void XCounterImp::setThresholdCrossed(const XString& thresholdCrossed)
{
    comVals_["thresholdCrossed"] = thresholdCrossed;
}

void XCounterImp::setHashMap(const XHashMap& hashMap)
{
    hashMap_ = hashMap;
}

void XCounterImp::setCriticality(XEnumCounterCriticality criticality)
{
    auto val = XEnumCounterCriticalityMapping[criticality];
    comVals_["criticality"] = val;
}

json XCounterImp::toJson()
{
    try
    {
        json field = {
            { "thresholdCrossed", thresholdCrossed_ },
            { "hashMap", hashMap_ },
            { "criticality", XEnumCounterCriticalityMapping[criticality_] }
        };

        //optional val

        field = mergeCommonValues(field, comVals_);

        return field;
    }
    catch (json::exception& e)
    {
        SPDLOG_ERROR("Fail to build XCounter to json object:{}.", e.what());
        return json();
    }
}