[asterisk-commits] kpfleming: trunk r159631 - in /trunk: ./ apps/ autoconf/ contrib/ include/ast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 26 15:20:50 CST 2008


Author: kpfleming
Date: Wed Nov 26 15:20:50 2008
New Revision: 159631

URL: http://svn.digium.com/view/asterisk?view=rev&rev=159631
Log:
improve handling of API calls provided by loaded modules through use of some GCC features; this makes app_stack's usage of AGI APIs even cleaner, and will allow it to work 'as expected' either with or without res_agi being loaded

reviewed at http://reviewboard.digium.com/r/62


Added:
    trunk/include/asterisk/optional_api.h
      - copied unchanged from r159629, team/kpfleming/optional_api/include/asterisk/optional_api.h
Modified:
    trunk/apps/app_stack.c
    trunk/autoconf/ast_gcc_attribute.m4
    trunk/configure
    trunk/configure.ac
    trunk/contrib/asterisk-ng-doxygen
    trunk/include/asterisk/agi.h
    trunk/include/asterisk/autoconfig.h.in
    trunk/res/res_agi.c

Modified: trunk/apps/app_stack.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_stack.c?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/apps/app_stack.c (original)
+++ trunk/apps/app_stack.c Wed Nov 26 15:20:50 2008
@@ -38,9 +38,6 @@
 #include "asterisk/app.h"
 #include "asterisk/manager.h"
 #include "asterisk/channel.h"
-
-/* usage of AGI is optional, so indicate that to the header file */
-#define ASTERISK_AGI_OPTIONAL
 #include "asterisk/agi.h"
 
 /*** DOCUMENTATION
@@ -576,9 +573,7 @@
 {
 	struct ast_context *con;
 
-	if (ast_agi_unregister) {
-		ast_agi_unregister(ast_module_info->self, &gosub_agi_command);
-
+	if (ast_agi_unregister(ast_module_info->self, &gosub_agi_command) == 1) {
 		if ((con = ast_context_find("app_stack_gosub_virtual_context"))) {
 			ast_context_remove_extension2(con, "s", 1, NULL, 0);
 			ast_context_destroy(con, "app_stack"); /* leave nothing behind */
@@ -598,19 +593,13 @@
 {
 	struct ast_context *con;
 
-	/* usage of AGI is optional, so check to see if the ast_agi_register()
-	   function is available; if so, use it.
-	*/
-	if (ast_agi_register) {
-		con = ast_context_find_or_create(NULL, NULL, "app_stack_gosub_virtual_context", "app_stack");
-		if (!con) {
+	if (ast_agi_register(ast_module_info->self, &gosub_agi_command) == 1) {
+		if (!(con = ast_context_find_or_create(NULL, NULL, "app_stack_gosub_virtual_context", "app_stack"))) {
 			ast_log(LOG_ERROR, "Virtual context 'app_stack_gosub_virtual_context' does not exist and unable to create\n");
 			return AST_MODULE_LOAD_DECLINE;
 		} else {
 			ast_add_extension2(con, 1, "s", 1, NULL, NULL, "KeepAlive", ast_strdup(""), ast_free_ptr, "app_stack");
 		}
-
-		ast_agi_register(ast_module_info->self, &gosub_agi_command);
 	}
 
 	ast_register_application_xml(app_pop, pop_exec);

Modified: trunk/autoconf/ast_gcc_attribute.m4
URL: http://svn.digium.com/view/asterisk/trunk/autoconf/ast_gcc_attribute.m4?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/autoconf/ast_gcc_attribute.m4 (original)
+++ trunk/autoconf/ast_gcc_attribute.m4 Wed Nov 26 15:20:50 2008
@@ -1,17 +1,31 @@
 # Helper function to check for gcc attributes.
-# AST_GCC_ATTRIBUTE([attribute name])
+# AST_GCC_ATTRIBUTE([attribute name], [attribute syntax])
 
 AC_DEFUN([AST_GCC_ATTRIBUTE],
 [
 AC_MSG_CHECKING(for compiler 'attribute $1' support)
 saved_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -Werror"
+
+if test "x$2" = "x"
+then
 AC_COMPILE_IFELSE(
 	AC_LANG_PROGRAM([void __attribute__(($1)) *test(void *muffin, ...) {}],
 			[]),
 	AC_MSG_RESULT(yes)
 	AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
-	AC_MSG_RESULT(no))
+	AC_MSG_RESULT(no)
+)
+else
+AC_COMPILE_IFELSE(
+	AC_LANG_PROGRAM([void __attribute__(($2)) *test(void *muffin, ...) {}],
+			[]),
+	AC_MSG_RESULT(yes)
+	AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
+	AC_MSG_RESULT(no)
+)
+fi
+
+CFLAGS="$saved_CFLAGS"
 ]
-CFLAGS="$saved_CFLAGS"
 )

Modified: trunk/configure.ac
URL: http://svn.digium.com/view/asterisk/trunk/configure.ac?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Nov 26 15:20:50 2008
@@ -480,6 +480,7 @@
 AST_GCC_ATTRIBUTE(sentinel)
 AST_GCC_ATTRIBUTE(warn_unused_result)
 AST_GCC_ATTRIBUTE(weak)
+AST_GCC_ATTRIBUTE(alias, [alias("foo")])
 
 AC_MSG_CHECKING(for -ffunction-sections support)
 saved_CFLAGS="${CFLAGS}"

Modified: trunk/contrib/asterisk-ng-doxygen
URL: http://svn.digium.com/view/asterisk/trunk/contrib/asterisk-ng-doxygen?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/contrib/asterisk-ng-doxygen (original)
+++ trunk/contrib/asterisk-ng-doxygen Wed Nov 26 15:20:50 2008
@@ -1098,7 +1098,9 @@
 			AST_RWDLLIST_HEAD_STATIC \
 			AST_DLLIST_ENTRY \
 			AST_RWDLLIST_ENTRY \
-			AST_CLI_DEFINE
+			AST_CLI_DEFINE \
+			AST_OPTIONAL_API \
+			AST_OPTIONAL_API_ATTR
 
 # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 
 # doxygen's preprocessor will remove all function-like macros that are alone 

Modified: trunk/include/asterisk/agi.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/agi.h?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/include/asterisk/agi.h (original)
+++ trunk/include/asterisk/agi.h Wed Nov 26 15:20:50 2008
@@ -28,6 +28,7 @@
 #endif
 
 #include "asterisk/cli.h"
+#include "asterisk/optional_api.h"
 
 typedef struct agi_state {
 	int fd;		        /*!< FD for general output */
@@ -60,11 +61,66 @@
 	AST_LIST_ENTRY(agi_command) list;
 } agi_command;
 
-#if defined(ASTERISK_AGI_OPTIONAL)
-#define AGI_WEAK attribute_weak
-#else
-#define AGI_WEAK
-#endif
+/*!
+ * \brief
+ *
+ * Registers an AGI command.
+ *
+ * \param mod Pointer to the module_info structure for the module that is registering the command
+ * \param cmd Pointer to the descriptor for the command
+ * \return 1 on success, 0 if the command is already registered
+ *
+ */
+AST_OPTIONAL_API(int, ast_agi_register, (struct ast_module *mod, agi_command *cmd),
+		 { return AST_OPTIONAL_API_UNAVAILABLE; });
+
+/*!
+ * \brief
+ *
+ * Unregisters an AGI command.
+ *
+ * \param mod Pointer to the module_info structure for the module that is unregistering the command
+ * \param cmd Pointer to the descriptor for the command
+ * \return 1 on success, 0 if the command was not already registered
+ *
+ */
+AST_OPTIONAL_API(int, ast_agi_unregister, (struct ast_module *mod, agi_command *cmd),
+		 { return AST_OPTIONAL_API_UNAVAILABLE; });
+
+/*!
+ * \brief
+ *
+ * Registers a group of AGI commands, provided as an array of struct agi_command
+ * entries.
+ *
+ * \param mod Pointer to the module_info structure for the module that is registering the commands
+ * \param cmd Pointer to the first entry in the array of command descriptors
+ * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
+ * \return 0 on success, -1 on failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded
+ *
+ * \note If any command fails to register, all commands previously registered during the operation
+ * will be unregistered. In other words, this function registers all the provided commands, or none
+ * of them.
+ */
+AST_OPTIONAL_API(int, ast_agi_register_multiple, (struct ast_module *mod, struct agi_command *cmd, unsigned int len),
+		 { return AST_OPTIONAL_API_UNAVAILABLE; });
+
+/*!
+ * \brief
+ *
+ * Unregisters a group of AGI commands, provided as an array of struct agi_command
+ * entries.
+ *
+ * \param mod Pointer to the module_info structure for the module that is unregistering the commands
+ * \param cmd Pointer to the first entry in the array of command descriptors
+ * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
+ * \return 0 on success, -1 on failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded
+ *
+ * \note If any command fails to unregister, this function will continue to unregister the
+ * remaining commands in the array; it will not reregister the already-unregistered commands.
+ */
+AST_OPTIONAL_API(int, ast_agi_unregister_multiple, (struct ast_module *mod, struct agi_command *cmd, unsigned int len),
+		 { return AST_OPTIONAL_API_UNAVAILABLE; });
 
 /*!
  * \brief
@@ -74,45 +130,11 @@
  * \param fd The file descriptor for the AGI session (from struct agi_state)
  * \param chan Pointer to an associated Asterisk channel, if any
  * \param fmt printf-style format string
- * \return 0 for success, -1 for failure
+ * \return 0 for success, -1 for failure, AST_OPTIONAL_API_UNAVAILABLE if res_agi is not loaded
  *
  */
-int AGI_WEAK ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...) __attribute__((format(printf, 3, 4)));
-int AGI_WEAK ast_agi_register(struct ast_module *mod, agi_command *cmd);
-int AGI_WEAK ast_agi_unregister(struct ast_module *mod, agi_command *cmd);
-
-/*!
- * \brief
- *
- * Registers a group of AGI commands, provided as an array of struct agi_command
- * entries.
- *
- * \param mod Pointer to the module_info structure for the module that is registering the commands
- * \param cmd Pointer to the first entry in the array of commands
- * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
- * \return 0 on success, -1 on failure
- *
- * \note If any command fails to register, all commands previously registered during the operation
- * will be unregistered. In other words, this function registers all the provided commands, or none
- * of them.
- */
-int AGI_WEAK ast_agi_register_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
-
-/*!
- * \brief
- *
- * Unregisters a group of AGI commands, provided as an array of struct agi_command
- * entries.
- *
- * \param mod Pointer to the module_info structure for the module that is unregistering the commands
- * \param cmd Pointer to the first entry in the array of commands
- * \param len Length of the array (use the ARRAY_LEN macro to determine this easily)
- * \return 0 on success, -1 on failure
- *
- * \note If any command fails to unregister, this function will continue to unregister the
- * remaining commands in the array; it will not reregister the already-unregistered commands.
- */
-int AGI_WEAK ast_agi_unregister_multiple(struct ast_module *mod, struct agi_command *cmd, unsigned int len);
+AST_OPTIONAL_API_ATTR(int, format(printf, 3, 4), ast_agi_send, (int fd, struct ast_channel *chan, char *fmt, ...),
+		      { return AST_OPTIONAL_API_UNAVAILABLE; });
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Wed Nov 26 15:20:50 2008
@@ -90,6 +90,9 @@
 
 /* Define to 1 if you have the `atexit' function. */
 #undef HAVE_ATEXIT
+
+/* Define to 1 if your GCC C compiler supports the 'alias' attribute. */
+#undef HAVE_ATTRIBUTE_alias
 
 /* Define to 1 if your GCC C compiler supports the 'always_inline' attribute.
    */

Modified: trunk/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_agi.c?view=diff&rev=159631&r1=159630&r2=159631
==============================================================================
--- trunk/res/res_agi.c (original)
+++ trunk/res/res_agi.c Wed Nov 26 15:20:50 2008
@@ -51,7 +51,6 @@
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
 #include "asterisk/strings.h"
-#include "asterisk/agi.h"
 #include "asterisk/manager.h"
 #include "asterisk/ast_version.h"
 #include "asterisk/speech.h"
@@ -59,6 +58,9 @@
 #include "asterisk/features.h"
 #include "asterisk/term.h"
 #include "asterisk/xmldoc.h"
+
+#define AST_API_MODULE
+#include "asterisk/agi.h"
 
 /*** DOCUMENTATION
 	<agi name="answer" language="en_US">




More information about the asterisk-commits mailing list