>From c6cba8a2bf4128bc6898ba1268ace642702b8a26 Mon Sep 17 00:00:00 2001 From: eindenbom Date: Mon, 5 Apr 2010 15:40:28 +0400 Subject: [PATCH 2/4] Added an interface to query number of configured failover servers. --- src/providers/data_provider_fo.c | 21 +++++++++++++++++++++ src/providers/dp_backend.h | 1 + src/providers/fail_over.c | 13 +++++++++++++ src/providers/fail_over.h | 5 +++++ 4 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c index 482f744..cd2d2b4 100644 --- a/src/providers/data_provider_fo.c +++ b/src/providers/data_provider_fo.c @@ -226,6 +226,27 @@ int be_fo_service_add_callback(TALLOC_CTX *memctx, return EOK; } +int be_fo_get_server_count(struct be_ctx *ctx, const char *service_name) +{ + struct be_svc_data* svc_data; + + if (!ctx->be_fo) { + return 0; + } + + DLIST_FOR_EACH(svc_data, ctx->be_fo->svcs) { + if (strcmp(svc_data->name, service_name) == 0) { + break; + } + } + + if (!svc_data) { + return 0; + } + + return fo_get_server_count(svc_data->fo_service); +} + int be_fo_add_server(struct be_ctx *ctx, const char *service_name, const char *server, int port, void *user_data) { diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h index f1069d0..e414c7d 100644 --- a/src/providers/dp_backend.h +++ b/src/providers/dp_backend.h @@ -130,6 +130,7 @@ int be_fo_add_service(struct be_ctx *ctx, const char *service_name); int be_fo_service_add_callback(TALLOC_CTX *memctx, struct be_ctx *ctx, const char *service_name, be_svc_callback_fn_t *fn, void *private_data); +int be_fo_get_server_count(struct be_ctx *ctx, const char *service_name); int be_fo_add_server(struct be_ctx *ctx, const char *service_name, const char *server, int port, void *user_data); diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c index 54ad032..a6aa70c 100644 --- a/src/providers/fail_over.c +++ b/src/providers/fail_over.c @@ -341,6 +341,19 @@ create_server_common(TALLOC_CTX *mem_ctx, struct fo_ctx *ctx, const char *name) } int +fo_get_server_count(struct fo_service *service) +{ + struct fo_server *server; + int count = 0; + + DLIST_FOR_EACH(server, service->server_list) { + count++; + } + + return count; +} + +int fo_add_server(struct fo_service *service, const char *name, int port, void *user_data) { diff --git a/src/providers/fail_over.h b/src/providers/fail_over.h index ffcd068..5bf396d 100644 --- a/src/providers/fail_over.h +++ b/src/providers/fail_over.h @@ -93,6 +93,11 @@ int fo_get_service(struct fo_ctx *ctx, struct fo_service **_service); /* + * Get number of servers registered for the 'service'. + */ +int fo_get_server_count(struct fo_service *service); + +/* * Adds a server 'name' to the 'service'. Port 'port' will be used for * connection. If 'name' is NULL, no server resolution will be done. */ -- 1.6.6.1