[Asterisk-code-review] res smdi.c: Made use defaults if the smdi.conf file does not... (asterisk[16])

George Joseph asteriskteam at digium.com
Fri Oct 5 10:09:17 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10383 )

Change subject: res_smdi.c: Made use defaults if the smdi.conf file does not exist.
......................................................................

res_smdi.c: Made use defaults if the smdi.conf file does not exist.

This module is an optional dependency of a couple of other modules.  If it
declines to load, it then forces other modules that can optionally use
this module to also decline.

* Made use the default configuration if the config file does not exist and
simplified some of the logic.

Change-Id: Ib93191f1fe28c0dd9ebe3d84c7762b32f83c4eb9
---
M res/res_smdi.c
1 file changed, 24 insertions(+), 45 deletions(-)

Approvals:
  Richard Mudgett: Verified
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/res/res_smdi.c b/res/res_smdi.c
index 1d4826a..b8bf5d8 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -162,7 +162,6 @@
  ***/
 
 static const char config_file[] = "smdi.conf";
-static int smdi_loaded;
 
 struct ast_smdi_interface {
 	char name[SMDI_MAX_FILENAME_LEN];
@@ -1035,7 +1034,7 @@
 		} else if (!strcasecmp(v->name, "twostopbits")) {
 			stopbits = ast_true(v->name);
 		} else if (!strcasecmp(v->name, "smdiport")) {
-			if (reload) {
+			if (reload && old_ifaces) {
 				/* we are reloading, check if we are already
 				 * monitoring this interface, if we are we do
 				 * not want to start it again.  This also has
@@ -1371,7 +1370,26 @@
 	.read = smdi_msg_read,
 };
 
-static int _unload_module(int fromload);
+static int unload_module(void)
+{
+	ao2_global_obj_release(smdi_ifaces);
+
+	destroy_all_mailbox_mappings();
+
+	ast_mutex_lock(&mwi_monitor.lock);
+	mwi_monitor.stop = 1;
+	ast_cond_signal(&mwi_monitor.cond);
+	ast_mutex_unlock(&mwi_monitor.lock);
+
+	if (mwi_monitor.thread != AST_PTHREADT_NULL) {
+		pthread_join(mwi_monitor.thread, NULL);
+	}
+
+	ast_custom_function_unregister(&smdi_msg_retrieve_function);
+	ast_custom_function_unregister(&smdi_msg_function);
+
+	return 0;
+}
 
 /*!
  * \brief Load the module
@@ -1386,7 +1404,6 @@
 static int load_module(void)
 {
 	int res;
-	smdi_loaded = 1;
 
 	ast_mutex_init(&mwi_monitor.lock);
 	ast_cond_init(&mwi_monitor.cond, NULL);
@@ -1394,12 +1411,10 @@
 	/* load the config and start the listener threads*/
 	res = smdi_load(0);
 	if (res < 0) {
-		_unload_module(1);
+		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	} else if (res == 1) {
-		_unload_module(1);
 		ast_log(LOG_NOTICE, "No SMDI interfaces are available to listen on, not starting SMDI listener.\n");
-		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	ast_custom_function_register(&smdi_msg_retrieve_function);
@@ -1408,53 +1423,17 @@
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int _unload_module(int fromload)
-{
-	if (!smdi_loaded) {
-		return 0;
-	}
-
-	ao2_global_obj_release(smdi_ifaces);
-
-	destroy_all_mailbox_mappings();
-
-	ast_mutex_lock(&mwi_monitor.lock);
-	mwi_monitor.stop = 1;
-	ast_cond_signal(&mwi_monitor.cond);
-	ast_mutex_unlock(&mwi_monitor.lock);
-
-	if (mwi_monitor.thread != AST_PTHREADT_NULL) {
-		pthread_join(mwi_monitor.thread, NULL);
-	}
-
-	if (!fromload) {
-		ast_custom_function_unregister(&smdi_msg_retrieve_function);
-		ast_custom_function_unregister(&smdi_msg_function);
-	}
-
-	smdi_loaded = 0;
-
-	return 0;
-}
-
-static int unload_module(void)
-{
-	return _unload_module(0);
-}
-
 static int reload(void)
 {
 	int res;
 
 	res = smdi_load(1);
-
 	if (res < 0) {
 		return res;
 	} else if (res == 1) {
 		ast_log(LOG_WARNING, "No SMDI interfaces were specified to listen on, not starting SDMI listener.\n");
-		return 0;
-	} else
-		return 0;
+	}
+	return 0;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Simplified Message Desk Interface (SMDI) Resource",

-- 
To view, visit https://gerrit.asterisk.org/10383
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib93191f1fe28c0dd9ebe3d84c7762b32f83c4eb9
Gerrit-Change-Number: 10383
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181005/dfbeadb2/attachment-0001.html>


More information about the asterisk-code-review mailing list