From cfa0826c492951b2c57f1350a7ed1bc3a97d6f9b Mon Sep 17 00:00:00 2001
From: Terry Wilson <twilson@digium.com>
Date: Thu, 14 Jun 2012 13:41:47 +0000
Subject: [PATCH] Add a post_apply callback to the Config Options API

This adds a callback that only fires when changes have been successfully
applied via the Config Options API.

Review: https://reviewboard.asterisk.org/r/1980/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@368921 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 include/asterisk/config_options.h | 16 ++++++++++++----
 main/config_options.c             |  4 ++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/asterisk/config_options.h b/include/asterisk/config_options.h
index 3e4c4a5ca9..1bbf270251 100644
--- a/include/asterisk/config_options.h
+++ b/include/asterisk/config_options.h
@@ -124,13 +124,20 @@ struct aco_type {
 	struct aco_type_internal *internal;
 };
 
-/*! \brief A callback function for applying the config changes
+/*! \brief A callback function to run just prior to applying config changes
  * \retval 0 Success
  * \retval non-zero Failure. Changes not applied
  */
 typedef int (*aco_pre_apply_config)(void);
 
-/*! \brief A callback functino for allocating an object to hold all config objects
+/*! \brief A callback function called only if config changes have been applied
+ *
+ * \note If a config file has not been edited prior to performing a reload, this
+ * callback will not be called.
+ */
+typedef void (*aco_post_apply_config)(void);
+
+/*! \brief A callback function for allocating an object to hold all config objects
  * \retval NULL error
  * \retval non-NULL a config object container
  */
@@ -145,12 +152,13 @@ struct aco_file {
 };
 
 struct aco_info {
-	const char *module;         /*!< The name of the module whose config is being processed */
+	const char *module; /*!< The name of the module whose config is being processed */
 	aco_pre_apply_config pre_apply_config; /*!< A callback called after processing, but before changes are applied */
+	aco_post_apply_config post_apply_config;/*!< A callback called after changes are applied */
 	aco_snapshot_alloc snapshot_alloc;     /*!< Allocate an object to hold all global configs and item containers */
 	struct ao2_global_obj *global_obj;     /*!< The global object array that holds the user-defined config object */
 	struct aco_info_internal *internal;
-	struct aco_file *files[];    /*!< The config filename */
+	struct aco_file *files[];    /*!< An array of aco_files to process */
 };
 
 /*! \brief A helper macro to ensure that aco_info types always have a sentinel */
diff --git a/main/config_options.c b/main/config_options.c
index 7baf678369..3d15991ac4 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -480,6 +480,10 @@ try_alias:
 		goto end;
 	}
 
+	if (info->post_apply_config) {
+		info->post_apply_config();
+	}
+
 end:
 	ao2_cleanup(info->internal->pending);
 	return res;
-- 
GitLab