summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/providers/data_provider_be.c1
-rw-r--r--src/providers/data_provider_callbacks.c22
-rw-r--r--src/providers/dp_backend.h10
3 files changed, 32 insertions, 1 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 5b67d26fd..059a0514e 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -167,6 +167,7 @@ void be_mark_offline(struct be_ctx *ctx)
ctx->offstat.went_offline = time(NULL);
ctx->offstat.offline = true;
ctx->run_online_cb = true;
+ be_run_offline_cb(ctx);
}
static int be_check_online(DBusMessage *message, struct sbus_connection *conn)
diff --git a/src/providers/data_provider_callbacks.c b/src/providers/data_provider_callbacks.c
index 00bc8fd5d..555271306 100644
--- a/src/providers/data_provider_callbacks.c
+++ b/src/providers/data_provider_callbacks.c
@@ -180,3 +180,25 @@ void be_run_online_cb(struct be_ctx *be) {
DEBUG(9, ("Online call back list is empty, nothing to do.\n"));
}
}
+
+int be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
+ void *pvt, struct be_cb **offline_cb)
+{
+ return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->offline_cb_list, offline_cb);
+}
+
+void be_run_offline_cb(struct be_ctx *be) {
+ int ret;
+
+ if (be->offline_cb_list) {
+ DEBUG(3, ("Going offline. Running callbacks.\n"));
+
+ ret = be_run_cb(be, be->offline_cb_list);
+ if (ret != EOK) {
+ DEBUG(1, ("be_run_cb failed.\n"));
+ }
+
+ } else {
+ DEBUG(9, ("Offline call back list is empty, nothing to do.\n"));
+ }
+}
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
index 43d79ba2c..fc5e558c1 100644
--- a/src/providers/dp_backend.h
+++ b/src/providers/dp_backend.h
@@ -95,10 +95,11 @@ struct be_ctx {
struct be_failover_ctx *be_fo;
/* Functions to be invoked when the
- * backend goes online
+ * backend goes online or offline
*/
struct be_cb *online_cb_list;
bool run_online_cb;
+ struct be_cb *offline_cb_list;
struct be_offline_status offstat;
@@ -148,6 +149,13 @@ int be_add_online_cb(TALLOC_CTX *mem_ctx,
struct be_cb **online_cb);
void be_run_online_cb(struct be_ctx *be);
+int be_add_offline_cb(TALLOC_CTX *mem_ctx,
+ struct be_ctx *ctx,
+ be_callback_t cb,
+ void *pvt,
+ struct be_cb **online_cb);
+void be_run_offline_cb(struct be_ctx *be);
+
/* from data_provider_fo.c */
typedef void (be_svc_callback_fn_t)(void *, struct fo_server *);