[asterisk-dev] const char * to AST_STRING_FIELD

Szasz Tamas szasz.tamas at elastoffice.com
Tue Jan 31 12:25:51 CST 2012


Hi,

You are right, the 1.6.2 branch is on end of life, but our configuration 
is for 1.6.2.
I checked some source code from the version 1.6.2.22 (especially the 
func_cdr and func_odb), in witch i saw that the ast_custom_function is 
used in this format:
static struct ast_custom_function cdr_function = {
         .name = "CDR",
         .read = cdr_read,
         .write = cdr_write,
};
But when i tried in my code, I got these errors at compile time:
func/FuncStartCall.cpp:48: error: expected primary-expression before '.' 
token
func/FuncStartCall.cpp:48: error: expected primary-expression before '.' 
token
func/FuncStartCall.cpp:48: error: expected primary-expression before '.' 
token
func/FuncStartCall.cpp:48: error: uninitialized const member 
'ast_custom_function::desc'
func/FuncStartCall.cpp:48: error: uninitialized const member 
'ast_custom_function::syntax'
func/FuncStartCall.cpp:48: error: uninitialized const member 
'ast_custom_function::arguments'
func/FuncStartCall.cpp:48: error: uninitialized const member 
'ast_custom_function::seealso'

Maybe I need to add some compiler option, or there some minimum version 
in gcc to use this format of value assignment?

Regards

On 1/31/12 7:40 PM, asterisk-dev-request at lists.digium.com wrote:
> <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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120131/8916234d/attachment.htm>


More information about the asterisk-dev mailing list