Add supoprt for D release use-case.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / faults / faults_counters.c
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #define _GNU_SOURCE
19
20 #include "faults.h"
21 #include "utils/log_utils.h"
22 #include "utils/rand_utils.h"
23 #include "utils/sys_utils.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27
28 static fault_counters_t fault_counters;
29
30 fault_counters_t faults_counters_get(void) {
31     return fault_counters;
32 }
33
34 void faults_counters_clear(void) {
35     fault_counters.normal = 0;
36     fault_counters.warning = 0;
37     fault_counters.minor = 0;
38     fault_counters.major = 0;
39     fault_counters.critical = 0;
40 }
41
42 int faults_counters_increase(const char *severity) {
43     assert(severity);
44
45     int ret = NTS_ERR_OK;
46     if(strcmp(severity, "NORMAL") == 0) {
47         fault_counters.normal++;
48     }
49     else if(strcmp(severity, "WARNING") == 0) {
50         fault_counters.warning++;
51     }
52     else if(strcmp(severity, "MINOR") == 0) {
53         fault_counters.minor++;
54     }
55     else if(strcmp(severity, "MAJOR") == 0) {
56         fault_counters.major++;
57     }
58     else if(strcmp(severity, "CRITICAL") == 0) {
59         fault_counters.critical++;
60     }
61     else {
62         log_error("severity not found: %s\n", severity);
63         ret = NTS_ERR_FAILED;
64     }
65
66     return ret;
67 }