rsstats 0.0.1
Redis Enterprise Statistic collector
clusterlst.c
Go to the documentation of this file.
1
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include "clusterlst.h"
26#include "sclist.h"
27
28#include <stdlib.h>
29#include <string.h>
30
31static sclist_t* clusterlist=NULL;
32static sclistrecord_t* clusterlist_cursor=NULL;
33
34static void clusterlist_add_postinit (cluster_t* cluster);
35static cluster_t* clusterlist_find_postinit (const char* host);
36static cluster_t* clusterlist_first_postinit();
37static cluster_t* clusterlist_next_postinit();
38static cluster_t* clusterlist_get_postinit();
39
40static void clusterlist_init() {
41 /* Initialize the structure */
42 clusterlist = sclist_new();
43 clusterlist_cursor = NULL;
44
45 /* From now, the application can directly use the real functions */
46 clusterlist_add = clusterlist_add_postinit;
47 clusterlist_find = clusterlist_find_postinit;
48 clusterlist_first = clusterlist_first_postinit;
49 clusterlist_next = clusterlist_next_postinit;
50 clusterlist_get = clusterlist_get_postinit;
51}
52
53static void clusterlist_add_postinit (cluster_t* cluster) {
54 sclist_addrecord(clusterlist,cluster);
55}
56static void clusterlist_add_preinit (cluster_t* cluster) {
57 clusterlist_init();
58 clusterlist_add(cluster);
59}
60void (*clusterlist_add)(cluster_t* cluster) = clusterlist_add_preinit;
61
62
63static cluster_t* clusterlist_find_postinit(const char* host) {
64 cluster_t* cluster=NULL;
65 clusterlist_cursor = sclist_firstrecord(clusterlist);
66 while (clusterlist_cursor) {
67 cluster = sclist_getvalue(clusterlist_cursor);
68 if (
69 ((host==NULL)&&(cluster->host==NULL))||
70 ((host!=NULL)&&(cluster->host!=NULL)&&(0==strcmp(host,cluster->host))))
71 break;
72 clusterlist_cursor = sclist_nextrecord(clusterlist_cursor);
73 };
74 return (clusterlist_cursor?cluster:NULL);
75}
76static cluster_t* clusterlist_find_preinit(const char* host) {
77 clusterlist_init();
78 return clusterlist_find(host);
79}
80cluster_t* (*clusterlist_find)(const char* host) = clusterlist_find_preinit;
81
82
83static cluster_t* clusterlist_first_postinit() {
84 clusterlist_cursor = sclist_firstrecord(clusterlist);
85 return (clusterlist_cursor?sclist_getvalue(clusterlist_cursor):NULL);
86}
87static cluster_t* clusterlist_first_preinit() {
88 clusterlist_init();
89 return clusterlist_first();
90}
91cluster_t* (*clusterlist_first)() = clusterlist_first_preinit;
92
93
94static cluster_t* clusterlist_next_postinit() {
95 clusterlist_cursor = (clusterlist_cursor?sclist_nextrecord(clusterlist_cursor):NULL);
96 return (clusterlist_cursor?sclist_getvalue(clusterlist_cursor):NULL);
97}
98static cluster_t* clusterlist_next_preinit() {
99 clusterlist_init();
100 return clusterlist_next();
101}
102cluster_t* (*clusterlist_next)() = clusterlist_next_preinit;
103
104
105static cluster_t* clusterlist_get_postinit() {
106 return (clusterlist_cursor?sclist_getvalue(clusterlist_cursor):NULL);
107}
108static cluster_t* clusterlist_get_preinit() {
109 clusterlist_init();
110 return clusterlist_get();
111}
112cluster_t* (*clusterlist_get)() = clusterlist_get_preinit;
113
114/* vim: set tw=80: */
cluster_t *(* clusterlist_first)()
Definition: clusterlst.c:91
cluster_t *(* clusterlist_get)()
Definition: clusterlst.c:112
void(* clusterlist_add)(cluster_t *cluster)
Definition: clusterlst.c:60
cluster_t *(* clusterlist_next)()
Definition: clusterlst.c:102
cluster_t *(* clusterlist_find)(const char *host)
Definition: clusterlst.c:80
Self initialized cluster records list (non thread-safe)
#define NULL
Definition: rsstats-opts.c:64
void * sclist_getvalue(sclistrecord_t *record)
Returns the value pointer stored in the record.
Definition: sclist.c:131
sclist_t * sclist_new()
Allocate and initialize the internal list structure.
Definition: sclist.c:43
sclistrecord_t * sclist_nextrecord(const sclistrecord_t *record)
Returns the pointer on the record following the specified one.
Definition: sclist.c:125
sclistrecord_t * sclist_addrecord(sclist_t *sclist, void *value)
Add a value at the end of the list.
Definition: sclist.c:66
sclistrecord_t * sclist_firstrecord(const sclist_t *sclist)
Returns the pointer on the first list record.
Definition: sclist.c:119
Basic single chained generic list.
char * host
Definition: cluster.h:26
Opaque sclist structure.
Definition: sclist.c:38
Private list record structure.
Definition: sclist.c:31