equal
deleted
inserted
replaced
25 */ |
25 */ |
26 TAILQ_HEAD(irc_log_ctx_channels, irc_log_chan) channels; |
26 TAILQ_HEAD(irc_log_ctx_channels, irc_log_chan) channels; |
27 |
27 |
28 /** Are we currently unloading ourself (via irc_log_unload) ? */ |
28 /** Are we currently unloading ourself (via irc_log_unload) ? */ |
29 bool unloading; |
29 bool unloading; |
|
30 |
|
31 /** The `struct module` passed to us once we unload() */ |
|
32 struct module *module; |
30 }; |
33 }; |
31 |
34 |
32 /** |
35 /** |
33 * State required to use irc_cmd_handler with irc_chan.handlers. |
36 * State required to use irc_cmd_handler with irc_chan.handlers. |
34 */ |
37 */ |
51 */ |
54 */ |
52 static void irc_log_chan_destroy (struct irc_log_chan *chan_ctx); |
55 static void irc_log_chan_destroy (struct irc_log_chan *chan_ctx); |
53 |
56 |
54 /** |
57 /** |
55 * The irc_log_ctx has completed stopping all the channels, and should now destroy itself |
58 * The irc_log_ctx has completed stopping all the channels, and should now destroy itself |
56 * |
|
57 */ |
59 */ |
58 static void irc_log_stopped (struct irc_log_ctx *ctx) |
60 static void irc_log_stopped (struct irc_log_ctx *ctx) |
59 { |
61 { |
60 log_debug("destroying the irc_log_ctx"); |
62 log_debug("module unload() completed"); |
61 |
63 |
62 // schedule an evsql_destroy |
64 // notify |
63 if (evsql_destroy_next(ctx->db)) |
65 module_unloaded(ctx->module); |
64 log_fatal("evsql_destroy_next failed"); |
|
65 |
|
66 // hands-off on the db |
|
67 ctx->db = NULL; |
|
68 |
|
69 // free ourself |
|
70 // XXX: wrong, we need to implement a irc_log_destroy that's called by module? |
|
71 free(ctx); |
|
72 } |
66 } |
73 |
67 |
74 /** |
68 /** |
75 * The irc_log_chan has completed shutdown |
69 * The irc_log_chan has completed shutdown |
76 */ |
70 */ |
476 }; |
470 }; |
477 |
471 |
478 /** |
472 /** |
479 * Deinitialize, logging CLOSE events for all channels, and removing any hooks we've added |
473 * Deinitialize, logging CLOSE events for all channels, and removing any hooks we've added |
480 */ |
474 */ |
481 static err_t irc_log_unload (void *_ctx) |
475 static err_t irc_log_unload (void *_ctx, struct module *module) |
482 { |
476 { |
483 struct irc_log_ctx *ctx = _ctx; |
477 struct irc_log_ctx *ctx = _ctx; |
484 struct irc_log_chan *chan_ctx; |
478 struct irc_log_chan *chan_ctx; |
485 |
479 |
486 // update our state to mark ourselves as unloading |
480 // update our state to mark ourselves as unloading |
487 ctx->unloading = true; |
481 ctx->unloading = true; |
|
482 ctx->module = module; |
488 |
483 |
489 // stop logging each channel |
484 // stop logging each channel |
490 TAILQ_FOREACH(chan_ctx, &ctx->channels, ctx_channels) { |
485 TAILQ_FOREACH(chan_ctx, &ctx->channels, ctx_channels) { |
491 irc_log_chan_stop(chan_ctx); |
486 irc_log_chan_stop(chan_ctx); |
492 } |
487 } |
494 // wait for all the channels to be stopped, which will call irc_log_stopped |
489 // wait for all the channels to be stopped, which will call irc_log_stopped |
495 return SUCCESS; |
490 return SUCCESS; |
496 } |
491 } |
497 |
492 |
498 /** |
493 /** |
|
494 * We can safely destroy the evsql instance from here, since we're outside of any callbacks from this module |
|
495 */ |
|
496 static void irc_log_destroy (void *_ctx) |
|
497 { |
|
498 struct irc_log_ctx *ctx = _ctx; |
|
499 |
|
500 log_debug("destroying the irc_log_ctx"); |
|
501 |
|
502 // destroy the evsql instance |
|
503 evsql_destroy(ctx->db); |
|
504 |
|
505 // ...no more |
|
506 free(ctx); |
|
507 } |
|
508 |
|
509 /** |
499 * The module function table |
510 * The module function table |
500 */ |
511 */ |
501 struct module_desc irc_log_module = { |
512 struct module_desc irc_log_module = { |
502 .init = &irc_log_init, |
513 .init = &irc_log_init, |
503 .config_options = irc_log_config_options, |
514 .config_options = irc_log_config_options, |
504 .unload = &irc_log_unload, |
515 .unload = &irc_log_unload, |
|
516 .destroy = &irc_log_destroy |
505 }; |
517 }; |
506 |
518 |