<p>sungtae kim has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8166">View Change</a></p><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 include/asterisk/module.h<br>M main/loader.c<br>2 files changed, 100 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/8166/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/module.h b/include/asterisk/module.h<br>index ebd41c0..a1ce5b9 100644<br>--- a/include/asterisk/module.h<br>+++ b/include/asterisk/module.h<br>@@ -65,6 +65,10 @@<br> as it may cause crashes */<br> };<br> <br>+enum ast_module_unload_result {<br>+ AST_MODULE_UNLOAD_SUCCESS = 0, /*!< Module was unloaded successfully */<br>+};<br>+<br> enum ast_module_load_result {<br> AST_MODULE_LOAD_SUCCESS = 0, /*!< Module loaded and configured */<br> AST_MODULE_LOAD_DECLINE = 1, /*!< Module is not configured */<br>diff --git a/main/loader.c b/main/loader.c<br>index 6b29f0e..550298c 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -87,6 +87,44 @@<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 numeric status code denoting the success or failure<br>+ of the load request.</para><br>+ <enumlist><br>+ <enum name="-1"><para>Module could not be loaded properly</para></enum><br>+ <enum name="0"><para>Success. Module loaded and configured</para></enum><br>+ <enum name="1"><para>Module is not configured</para></enum><br>+ <enum name="2"><para>Module was skipped for some reason</para></enum><br>+ <enum name="3"><para>Module is not loaded yet, but is added to priority list</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 numeric status code denoting the success or failure<br>+ of the unload request.</para><br>+ <enumlist><br>+ <enum name="0"><para>Success. Module unloaded successfully</para></enum><br>+ </enumlist><br>+ </parameter><br>+ </syntax><br>+ </managerEventInstance><br>+ </managerEvent><br> ***/<br> <br> #ifndef RTLD_NOW<br>@@ -160,6 +198,12 @@<br> };<br> <br> static AST_DLLIST_HEAD_STATIC(module_list, ast_module);<br>+<br>+static void publish_load_message_type(const char* type, const char *name, int result);<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, enum ast_module_unload_result result);<br>+<br> <br> /*<br> * module_list is cleared by its constructor possibly after<br>@@ -1007,6 +1051,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, AST_MODULE_UNLOAD_SUCCESS);<br> }<br> <br> return res;<br>@@ -1196,9 +1241,9 @@<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, int result)<br> {<br> RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);<br> RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);<br>@@ -1206,19 +1251,22 @@<br> RAII_VAR(struct ast_json *, event_object, NULL, ast_json_unref);<br> char res_buffer[8];<br> <br>+ if ((!type) || (!name)) {<br>+ return;<br>+ }<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>+ snprintf(res_buffer, sizeof(res_buffer), "%d", result);<br>+ event_object = ast_json_pack("{s:s, s:s}",<br>+ "Module", name,<br> "Status", res_buffer);<br>- json_object = ast_json_pack("{s: s, s: i, s: o}",<br>- "type", "Reload",<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 +1282,44 @@<br> }<br> <br> stasis_publish(ast_manager_get_topic(), message);<br>+}<br>+<br>+/*!<br>+ * \since 12<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>+ publish_load_message_type("Load", name, result);<br>+}<br>+<br>+/*!<br>+ * \since 12<br>+ * \internal<br>+ * \brief Publish a \ref stasis message regarding the unload result<br>+ */<br>+static void publish_unload_message(const char *name, enum ast_module_unload_result result)<br>+{<br>+ publish_load_message_type("Unload", name, result);<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>+ const char* module_name;<br>+<br>+ module_name = name;<br>+ if (!module_name) {<br>+ module_name = "All";<br>+ return;<br>+ }<br>+<br>+ publish_load_message_type("Reload", module_name, result);<br> }<br> <br> enum ast_module_reload_result ast_module_reload(const char *name)<br>@@ -1484,6 +1570,8 @@<br> res = start_resource(mod);<br> }<br> <br>+ publish_load_message(resource_name, res);<br>+<br> return res;<br> <br> prestart_error:<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: newchange </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: 1 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>