f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Data Provider Process - Callback
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Stephen Gallagher <sgallagh@redhat.com>
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Sumit Bose <sbose@redhat.com>
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Copyright (C) 2010 Red Hat
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose This program is free software; you can redistribute it and/or modify
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose it under the terms of the GNU General Public License as published by
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose the Free Software Foundation; either version 3 of the License, or
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose (at your option) any later version.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose This program is distributed in the hope that it will be useful,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose GNU General Public License for more details.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose You should have received a copy of the GNU General Public License
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *cb = talloc_get_type(ptr, struct be_cb);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestatic int be_add_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be_callback_t cb, void *pvt, struct be_cb **cb_list,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose talloc_set_destructor((TALLOC_CTX *) new_cb, cb_destructor);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestatic void be_run_cb_step(struct tevent_context *ev, struct tevent_timer *te,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb_ctx *cb_ctx = talloc_get_type(pvt, struct be_cb_ctx);
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina /* Store next callback in case this callback frees itself */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Call the callback */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Delay 30ms so we don't block any other events */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose tev = tevent_add_timer(cb_ctx->be->ev, cb_ctx, soon,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Steal the timer event onto the be_ctx so it doesn't
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * get freed with the cb_ctx
d2e2e5240c0da20d4091e7543ad8e7560be5f820Jakub Hrozekstatic errno_t be_run_cb(struct be_ctx *be, struct be_cb *cb_list)
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Delay 30ms so we don't block any other events */
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zelenyint be_add_reconnect_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->reconnect_cb_list, reconnect_cb);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_add_cb failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Reconnecting. Running callbacks.\n");
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * Call the callback: we have to call this right away
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * so the provider doesn't go into offline even for
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * a little while
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina /* Store next callback in case this callback frees itself */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Reconnect call back list is empty, nothing to do.\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Boseint be_add_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->online_cb_list, online_cb);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_add_cb failed.\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Make sure we run the callback for the first
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * connection after startup.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Reset the flag. We only want to run these
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * callbacks when transitioning to online
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Going online. Running callbacks.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Online call back list is empty, nothing to do.\n");
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Boseint be_add_unconditional_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->unconditional_online_cb_list,
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bosevoid be_run_unconditional_online_cb(struct be_ctx *be)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Running unconditional online callbacks.\n");
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose ret = be_run_cb(be, be->unconditional_online_cb_list);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "be_run_cb failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "List of unconditional online callbacks is empty, " \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "nothing to do.\n");
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Boseint be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->offline_cb_list, offline_cb);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Going offline. Running callbacks.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Offline call back list is empty, nothing to do.\n");