1 /*************************************************************************
3 * Copyright 2020 highstreet technologies GmbH and others
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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 ***************************************************************************/
21 #include "utils/log_utils.h"
22 #include "utils/rand_utils.h"
23 #include "utils/sys_utils.h"
28 static uint16_t *faults_fault_list = 0;
29 static uint16_t faults_fault_list_len = 0;
30 static uint16_t faults_fault_list_iterator = 0;
32 void faults_fault_list_clear(void) {
33 faults_fault_list_len = 0;
34 free(faults_fault_list);
35 faults_fault_list = 0;
36 faults_fault_list_iterator = 0;
37 log_add_verbose(2, "[faults] fault list cleared\n");
40 int faults_fault_list_add(uint16_t delay) {
41 faults_fault_list_len++;
42 faults_fault_list = (uint16_t *)realloc(faults_fault_list, sizeof(uint16_t) * (faults_fault_list_len));
43 if(faults_fault_list == 0) {
44 log_error("realloc failed\n");
45 return NTS_ERR_FAILED;
47 faults_fault_list[faults_fault_list_len - 1] = delay;
48 log_add_verbose(2, "[faults] added %d\n", delay);
53 bool faults_fault_list_not_empty(void) {
54 bool not_empty = (faults_fault_list_len != 0);
55 if(not_empty == true) {
57 for(int i = 0; i < faults_fault_list_len; i++) {
58 delay_sum += faults_fault_list[i];
61 not_empty = (delay_sum != 0);
66 uint16_t faults_fault_list_get_next(void) {
67 assert(faults_fault_list_iterator < faults_fault_list_len);
69 uint16_t ret = faults_fault_list[faults_fault_list_iterator];
70 faults_fault_list_iterator++;
71 if(faults_fault_list_iterator >= faults_fault_list_len) {
72 faults_fault_list_iterator = 0;