[svn-commits] mvanbaak: branch group/res_clialiases r150726 - in /team/group/res_clialiases...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Oct 17 13:59:15 CDT 2008


Author: mvanbaak
Date: Fri Oct 17 13:59:14 2008
New Revision: 150726

URL: http://svn.digium.com/view/asterisk?view=rev&rev=150726
Log:
- add ability to run callback functions when asterisk is loaded
- register callback to reload the clialiases.conf file once asterisk is loaded

Modified:
    team/group/res_clialiases/include/asterisk.h
    team/group/res_clialiases/main/asterisk.c
    team/group/res_clialiases/res/res_clialiases.c

Modified: team/group/res_clialiases/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/team/group/res_clialiases/include/asterisk.h?view=diff&rev=150726&r1=150725&r2=150726
==============================================================================
--- team/group/res_clialiases/include/asterisk.h (original)
+++ team/group/res_clialiases/include/asterisk.h Fri Oct 17 13:59:14 2008
@@ -59,6 +59,21 @@
  * \param func The callback function to unregister.   
  */
 void ast_unregister_atexit(void (*func)(void));
+
+/*!
+ * \brief Register a function to be executed after Asterisk started.
+ * \param func The callback function to use.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int ast_register_atstarted(void (*func)(void));
+
+/*!   
+ * \brief Unregister a function registered with ast_register_atstarted().
+ * \param func The callback function to unregister.   
+ */
+void ast_unregister_atstarted(void (*func)(void));
 
 #if !defined(LOW_MEMORY)
 /*!

Modified: team/group/res_clialiases/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/res_clialiases/main/asterisk.c?view=diff&rev=150726&r1=150725&r2=150726
==============================================================================
--- team/group/res_clialiases/main/asterisk.c (original)
+++ team/group/res_clialiases/main/asterisk.c Fri Oct 17 13:59:14 2008
@@ -184,6 +184,13 @@
 
 static AST_RWLIST_HEAD_STATIC(atexits, ast_atexit);
 
+struct ast_atstarted {
+	void (*func)(void);
+	AST_RWLIST_ENTRY(ast_atstarted) list;
+};
+
+static AST_RWLIST_HEAD_STATIC(atstarteds, ast_atstarted);
+
 struct timeval ast_startuptime;
 struct timeval ast_lastreloadtime;
 
@@ -799,6 +806,42 @@
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 	AST_RWLIST_UNLOCK(&atexits);
+
+	if (ae)
+		free(ae);
+}
+
+int ast_register_atstarted(void (*func)(void))
+{
+	struct ast_atstarted *ae;
+
+	if (!(ae = ast_calloc(1, sizeof(*ae))))
+		return -1;
+
+	ae->func = func;
+
+	ast_unregister_atstarted(func);	
+
+	AST_RWLIST_WRLOCK(&atstarteds);
+	AST_RWLIST_INSERT_HEAD(&atstarteds, ae, list);
+	AST_RWLIST_UNLOCK(&atstarteds);
+
+	return 0;
+}
+
+void ast_unregister_atstarted(void (*func)(void))
+{
+	struct ast_atstarted *ae = NULL;
+
+	AST_RWLIST_WRLOCK(&atstarteds);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atstarteds, ae, list) {
+		if (ae->func == func) {
+			AST_RWLIST_REMOVE_CURRENT(list);
+			break;
+		}
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&atstarteds);
 
 	if (ae)
 		free(ae);
@@ -1324,6 +1367,17 @@
 			ae->func();
 	}
 	AST_RWLIST_UNLOCK(&atexits);
+}
+
+static void ast_run_atstarteds(void)
+{
+	struct ast_atstarted *ae;
+	AST_RWLIST_RDLOCK(&atstarteds);
+	AST_RWLIST_TRAVERSE(&atstarteds, ae, list) {
+		if (ae->func) 
+			ae->func();
+	}
+	AST_RWLIST_UNLOCK(&atstarteds);
 }
 
 static void quit_handler(int num, int niceness, int safeshutdown, int restart)
@@ -3334,6 +3388,9 @@
 
 	dnsmgr_start_refresh();
 
+	/* run commands for post startup */
+	ast_run_atstarteds();
+
 	/* We might have the option of showing a console, but for now just
 	   do nothing... */
 	if (ast_opt_console && !option_verbose)

Modified: team/group/res_clialiases/res/res_clialiases.c
URL: http://svn.digium.com/view/asterisk/team/group/res_clialiases/res/res_clialiases.c?view=diff&rev=150726&r1=150725&r2=150726
==============================================================================
--- team/group/res_clialiases/res/res_clialiases.c (original)
+++ team/group/res_clialiases/res/res_clialiases.c Fri Oct 17 13:59:14 2008
@@ -257,6 +257,11 @@
 	return 0;
 }
 
+static void clialiases_atloaded(void)
+{
+	load_config(1);
+}
+
 /*! \brief Function called to unload the module */
 static int unload_module(void)
 {
@@ -277,6 +282,7 @@
 	load_config(0);
 
 	ast_cli_register_multiple(cli_alias, sizeof(cli_alias) / sizeof(struct ast_cli_entry));
+	ast_register_atstarted(clialiases_atloaded);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }




More information about the svn-commits mailing list