[asterisk-dev] const char * to AST_STRING_FIELD

Tilghman Lesher tilghman at meg.abyt.es
Tue Jan 31 09:26:00 CST 2012


On Tue, Jan 31, 2012 at 3:34 AM, Szasz Tamas
<szasz.tamas at elastoffice.com> wrote:
> I'm new in asterisk development, and I need to change something in our
> module, because the module was developed for asterisk 1.4.
> The problem from where I can't move out:
> In our old 1.4 module was a definition:
> FUNCTION_STATIC(Function, funcName, synopsis, syntax, description)
>                                 Function * Function::_instance = 0;
>                                 struct ast_custom_function
> Function::function =
>                                 {
>                                         funcName,  //const char *
>                                         synopsis,   //const char *
>                                         syntax,   //const char *
>                                         description,   //const char *
>                                         FuncReadWrapper<Function>,
>                                         FuncWriteWrapper<Function>
>                                 };
>
> But in the asterisk version 1.6 we must use the ast_custom_function like
> this:
>
> struct ast_custom_function {
>         const char *name;                       /*!< Name */
>         AST_DECLARE_STRING_FIELDS(
>                 AST_STRING_FIELD(synopsis);     /*!< Synopsis text for 'show
> functions' */
>                 AST_STRING_FIELD(desc);         /*!< Description (help text)
> for 'show functions &lt;name&gt;' */
>                 AST_STRING_FIELD(syntax);       /*!< Syntax text for 'core
> show functions' */
>                 AST_STRING_FIELD(arguments);    /*!< Arguments description
> */
>                 AST_STRING_FIELD(seealso);      /*!< See also */
>         );
>         enum ast_doc_src docsrc;                /*!< Where the documentation
> come from */
>         ast_acf_read_fn_t read;         /*!< Read function, if read is
> supported */
>         ast_acf_write_fn_t write;       /*!< Write function, if write is
> supported */
>         struct ast_module *mod;         /*!< Module this custom function
> belongs to */
>         AST_RWLIST_ENTRY(ast_custom_function) acflist;
> };
>
> Can somebody explain me, how can I change my code to the new style. I tried
> it, but neither one solution worked.
> Maybe for a senior developer, it's a simple question.

First of all, there is no version 1.6.  There's 1.6.0, 1.6.1, and
1.6.2, which are all separate branches, and additionally, all of which
are obsolete.  You should probably be using 1.8 for all new code at
this point.

The major change is that documentation is now created in XML format
and embedded within the source file, extracted at compile time, and
instantiated at runtime.  Unless you are creating dynamic functions
like func_odbc does, there is no need to ever access the stringfields
in the ast_custom_function structure.  And that's also the key module
if you are creating dynamic functions -- func_odbc.c shows all of the
necessary API calls to populate those stringfields.

-Tilghman



More information about the asterisk-dev mailing list