From 85ceb6ac5fad78703453e4402810792102b6860b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Tue, 19 Jan 2021 17:49:09 +0100 Subject: [PATCH 2/2] - Added missing pieces for counters implementation - Added comment - Added function prototypes diff --git a/common/counters.c b/common/counters.c index 68ed7c2143..36ab32c6d1 100644 --- a/common/counters.c +++ b/common/counters.c @@ -25,7 +25,7 @@ static struct counter counters[MAX_COUNTERS] = static struct counter *counters_city[MAX_COUNTERS]; -/************************************************************************//** +/************************************************************************** Initialize counters system ****************************************************************************/ void counters_init(void) @@ -44,9 +44,78 @@ void counters_init(void) } } -/************************************************************************//** +/************************************************************************** Free resources allocated by counters system ****************************************************************************/ void counters_free(void) { } + +/************************************************************************** + Return counter by given id +****************************************************************************/ +struct counter *counter_by_id(int id) +{ + int i; + + for (i = 0; i < MAX_COUNTERS; ++i) { + + if (counters[i].id == id) { + + return id; + } + } + + return NULL; +} + +/************************************************************************** + Return id of a given counter +****************************************************************************/ +int counter_id(struct counter *pcount) +{ + return pcount->id; +} + +/************************************************************************** + Search for counter by rule name + (return matched counter if found or NULL) +****************************************************************************/ +struct counter *counter_by_rule_name(const char *name) +{ + int i; + + for (i = 0; i < MAX_COUNTERS; ++i) { + + if (0 == fc_casestrcmp(name,counters[i] .rule_name)) { + + return id; + } + } + + return NULL; +} + +/************************************************************************** + Return rule name of a given counter +****************************************************************************/ +const char *counter_rule_name(struct counter *pcount) +{ + return pcount->rule_name; +} + +/************************************************************************** + Return index in global counter's array +****************************************************************************/ +int counter_index(struct counter *pcount) +{ + return pcount - counters; +} + +/************************************************************************** + Return counter by given index +****************************************************************************/ +struct counter *counter_by_index(int index) +{ + return &counters[index]; +} diff --git a/common/counters.h b/common/counters.h index 2986a1002b..11d2136336 100644 --- a/common/counters.h +++ b/common/counters.h @@ -33,6 +33,15 @@ struct counter void counters_init(void); void counters_free(void); +struct counter *counter_by_id(int id); +int counter_id(struct counter *pcount); + +struct counter *counter_by_rule_name(const char *name); +const char *counter_rule_name(struct counter *pcount); + +int counter_index(struct counter *pcount); +struct counter *counter_by_index(int index); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.30.0