[asterisk-dev] [asterisk-commits] mvanbaak: branch group/res_clialiases r150726 - in /team/group/res_clialiases...
Tilghman Lesher
tilghman at mail.jeffandtilghman.com
Sun Oct 19 11:44:53 CDT 2008
On Sunday 19 October 2008 07:12:03 Michiel van Baak wrote:
> On 02:17, Sun 19 Oct 08, Eliel Sarda?ons wrote:
> > mvanbaak,
> > If I am not wrong, your call to clialiases_atloaded() (when
> > registered _atstart) wont do anything because of the
> > CONFIG_STATUS_FILEUNCHANGED being returned because the file did not
> > change.
>
> Yet it still works.
> Without the callback aliases for 'core stop *' etc wont work, and
> with the callback they work fine.
I don't think he was disputing your callback method, but rather the argument
to load_config(). If you pass 1, indicating reload, then the method should
not do anything, because it detects that the file did not change since the
last load. You should probably pass 0 to load_config, instead, from the
callback. Note that if you're using "#exec" in your file, you won't see this
problem, because Asterisk never caches filestamps if that directive is within
a file.
> > On 10/17/08, SVN commits to the Asterisk project
> >
> > <asterisk-commits at lists.digium.com> wrote:
> > > 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/a
> > >sterisk.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/aste
> > >risk.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_c
> > >lialiases.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;
> > > }
> > >
> > >
> > > _______________________________________________
> > > --Bandwidth and Colocation Provided by http://www.api-digital.com--
> > >
> > > asterisk-commits mailing list
> > > To UNSUBSCRIBE or update options visit:
> > > http://lists.digium.com/mailman/listinfo/asterisk-commits
> >
> > _______________________________________________
> > --Bandwidth and Colocation Provided by http://www.api-digital.com--
> >
> > asterisk-dev mailing list
> > To UNSUBSCRIBE or update options visit:
> > http://lists.digium.com/mailman/listinfo/asterisk-dev
--
Tilghman
More information about the asterisk-dev
mailing list