<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8166">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Corey Farrell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">manager: Add AMI event Load/Unload<br><br>Add an AMI events Load and Unload for notify when the<br>module has been loaded and unloaded.<br><br>ASTERISK-27661<br><br>Change-Id: Ib916c41eddd63651952998f2f49c57c42ef87a64<br>---<br>M main/loader.c<br>1 file changed, 125 insertions(+), 15 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/loader.c b/main/loader.c<br>index 6b29f0e..08d9552 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -87,6 +87,40 @@<br> </syntax><br> </managerEventInstance><br> </managerEvent><br>+ <managerEvent language="en_US" name="Load"><br>+ <managerEventInstance class="EVENT_FLAG_SYSTEM"><br>+ <synopsis>Raised when a module has been loaded in Asterisk.</synopsis><br>+ <syntax><br>+ <parameter name="Module"><br>+ <para>The name of the module that was loaded</para><br>+ </parameter><br>+ <parameter name="Status"><br>+ <para>The result of the load request.</para><br>+ <enumlist><br>+ <enum name="Failure"><para>Module could not be loaded properly</para></enum><br>+ <enum name="Success"><para>Module loaded and configured</para></enum><br>+ <enum name="Decline"><para>Module is not configured</para></enum><br>+ </enumlist><br>+ </parameter><br>+ </syntax><br>+ </managerEventInstance><br>+ </managerEvent><br>+ <managerEvent language="en_US" name="Unload"><br>+ <managerEventInstance class="EVENT_FLAG_SYSTEM"><br>+ <synopsis>Raised when a module has been unloaded in Asterisk.</synopsis><br>+ <syntax><br>+ <parameter name="Module"><br>+ <para>The name of the module that was unloaded</para><br>+ </parameter><br>+ <parameter name="Status"><br>+ <para>The result of the unload request.</para><br>+ <enumlist><br>+ <enum name="Success"><para>Module unloaded successfully</para></enum><br>+ </enumlist><br>+ </parameter><br>+ </syntax><br>+ </managerEventInstance><br>+ </managerEvent><br> ***/<br> <br> #ifndef RTLD_NOW<br>@@ -160,6 +194,27 @@<br> };<br> <br> static AST_DLLIST_HEAD_STATIC(module_list, ast_module);<br>+<br>+<br>+struct load_results_map {<br>+ int result;<br>+ const char *name;<br>+};<br>+<br>+static const struct load_results_map load_results[] = {<br>+ { AST_MODULE_LOAD_SUCCESS, "Success" },<br>+ { AST_MODULE_LOAD_DECLINE, "Decline" },<br>+ { AST_MODULE_LOAD_SKIP, "Skip" },<br>+ { AST_MODULE_LOAD_PRIORITY, "Priority" },<br>+ { AST_MODULE_LOAD_FAILURE, "Failure" },<br>+};<br>+#define AST_MODULE_LOAD_UNKNOWN_STRING "Unknown" /* Status string for unknown load status */<br>+<br>+static void publish_load_message_type(const char* type, const char *name, const char *status);<br>+static void publish_reload_message(const char *name, enum ast_module_reload_result result);<br>+static void publish_load_message(const char *name, enum ast_module_load_result result);<br>+static void publish_unload_message(const char *name, const char* status);<br>+<br> <br> /*<br> * module_list is cleared by its constructor possibly after<br>@@ -1007,6 +1062,7 @@<br> unload_dynamic_module(mod);<br> ast_test_suite_event_notify("MODULE_UNLOAD", "Message: %s", resource_name);<br> ast_update_use_count();<br>+ publish_unload_message(resource_name, "Success");<br> }<br> <br> return res;<br>@@ -1196,29 +1252,30 @@<br> /*!<br> * \since 12<br> * \internal<br>- * \brief Publish a \ref stasis message regarding the reload result<br>+ * \brief Publish a \ref stasis message regarding the type.<br> */<br>-static void publish_reload_message(const char *name, enum ast_module_reload_result result)<br>+static void publish_load_message_type(const char* type, const char *name, const char *status)<br> {<br> RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);<br> RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);<br> RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);<br> RAII_VAR(struct ast_json *, event_object, NULL, ast_json_unref);<br>- char res_buffer[8];<br>+<br>+ ast_assert(type != NULL);<br>+ ast_assert(!ast_strlen_zero(name));<br>+ ast_assert(!ast_strlen_zero(status));<br> <br> if (!ast_manager_get_generic_type()) {<br> return;<br> }<br> <br>- snprintf(res_buffer, sizeof(res_buffer), "%u", result);<br>- event_object = ast_json_pack("{s: s, s: s}",<br>- "Module", S_OR(name, "All"),<br>- "Status", res_buffer);<br>- json_object = ast_json_pack("{s: s, s: i, s: o}",<br>- "type", "Reload",<br>+ event_object = ast_json_pack("{s:s, s:s}",<br>+ "Module", name,<br>+ "Status", status);<br>+ json_object = ast_json_pack("{s:s, s:i, s:o}",<br>+ "type", type,<br> "class_type", EVENT_FLAG_SYSTEM,<br> "event", ast_json_ref(event_object));<br>-<br> if (!json_object) {<br> return;<br> }<br>@@ -1234,6 +1291,54 @@<br> }<br> <br> stasis_publish(ast_manager_get_topic(), message);<br>+}<br>+<br>+static const char* loadresult2str(enum ast_module_load_result result)<br>+{<br>+ int i;<br>+ for (i = 0; i < ARRAY_LEN(load_results); i++) {<br>+ if (load_results[i].result == result) {<br>+ return load_results[i].name;<br>+ }<br>+ }<br>+<br>+ ast_log(LOG_WARNING, "Failed to find correct load result status. result %d\n", result);<br>+ return AST_MODULE_LOAD_UNKNOWN_STRING;<br>+}<br>+<br>+/*!<br>+ * \internal<br>+ * \brief Publish a \ref stasis message regarding the load result<br>+ */<br>+static void publish_load_message(const char *name, enum ast_module_load_result result)<br>+{<br>+ const char *status;<br>+<br>+ status = loadresult2str(result);<br>+<br>+ publish_load_message_type("Load", name, status);<br>+}<br>+<br>+/*!<br>+ * \internal<br>+ * \brief Publish a \ref stasis message regarding the unload result<br>+ */<br>+static void publish_unload_message(const char *name, const char* status)<br>+{<br>+ publish_load_message_type("Unload", name, status);<br>+}<br>+<br>+/*!<br>+ * \since 12<br>+ * \internal<br>+ * \brief Publish a \ref stasis message regarding the reload result<br>+ */<br>+static void publish_reload_message(const char *name, enum ast_module_reload_result result)<br>+{<br>+ char res_buffer[8];<br>+<br>+ snprintf(res_buffer, sizeof(res_buffer), "%u", result);<br>+ publish_load_message_type("Reload", S_OR(name, "All"), res_buffer);<br> }<br> <br> enum ast_module_reload_result ast_module_reload(const char *name)<br>@@ -1462,10 +1567,7 @@<br> res |= ast_vector_string_split(&mod->optional_modules, mod->info->optional_modules, ",", 0, strcasecmp);<br> res |= ast_vector_string_split(&mod->enhances, mod->info->enhances, ",", 0, strcasecmp);<br> if (res) {<br>- ast_log(LOG_WARNING, "Failed to initialize dependency structures for module '%s'.\n", resource_name);<br>- unload_dynamic_module(mod);<br>-<br>- return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;<br>+ goto prestart_error;<br> }<br> }<br> <br>@@ -1484,12 +1586,20 @@<br> res = start_resource(mod);<br> }<br> <br>+ if (ast_fully_booted && !ast_shutdown_final()) {<br>+ publish_load_message(resource_name, res);<br>+ }<br>+<br> return res;<br> <br> prestart_error:<br> ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);<br> unload_dynamic_module(mod);<br>- return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;<br>+ res = required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;<br>+ if (ast_fully_booted && !ast_shutdown_final()) {<br>+ publish_load_message(resource_name, res);<br>+ }<br>+ return res;<br> }<br> <br> int ast_load_resource(const char *resource_name)<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8166">change 8166</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8166"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib916c41eddd63651952998f2f49c57c42ef87a64 </div>
<div style="display:none"> Gerrit-Change-Number: 8166 </div>
<div style="display:none"> Gerrit-PatchSet: 6 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: sungtae kim <pchero21@gmail.com> </div>