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;
39 int faults_fault_list_add(uint16_t delay) {
40 faults_fault_list_len++;
41 faults_fault_list = (uint16_t *)realloc(faults_fault_list, sizeof(uint16_t) * (faults_fault_list_len));
42 if(faults_fault_list == 0) {
43 log_error("realloc failed");
44 return NTS_ERR_FAILED;
46 faults_fault_list[faults_fault_list_len - 1] = delay;
51 bool faults_fault_list_not_empty(void) {
52 bool not_empty = (faults_fault_list_len != 0);
53 if(not_empty == true) {
55 for(int i = 0; i < faults_fault_list_len; i++) {
56 delay_sum += faults_fault_list[i];
59 not_empty = (delay_sum != 0);
64 uint16_t faults_fault_list_get_next(void) {
65 assert(faults_fault_list_iterator < faults_fault_list_len);
67 uint16_t ret = faults_fault_list[faults_fault_list_iterator];
68 faults_fault_list_iterator++;
69 if(faults_fault_list_iterator >= faults_fault_list_len) {
70 faults_fault_list_iterator = 0;