[asterisk-commits] dbrooks: trunk r228661 - /trunk/tests/test_amihooks.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 6 16:07:23 CST 2009


Author: dbrooks
Date: Fri Nov  6 16:07:22 2009
New Revision: 228661

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=228661
Log:
ami_testhooks.c automatically registers hook

ami_testhooks.c was registering for AMI events upon module load. Moved the registration
to its own CLI command. Added CLI command for unregistering the hook. Changed some of
the wording, removed unnecessary arguments/parameters.

Reported by: rmudgett

Modified:
    trunk/tests/test_amihooks.c

Modified: trunk/tests/test_amihooks.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_amihooks.c?view=diff&rev=228661&r1=228660&r2=228661
==============================================================================
--- trunk/tests/test_amihooks.c (original)
+++ trunk/tests/test_amihooks.c Fri Nov  6 16:07:22 2009
@@ -51,7 +51,7 @@
 	.helper = &amihook_helper,
 };
 
-static int test_send(struct ast_cli_args *a) {
+static int hook_send(void) {
 	int res;
 
 	/* Send a test action (core show version) to the AMI */
@@ -60,19 +60,74 @@
 	return res;
 }
 
-static char *handle_cli_amihook_test_send(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static void register_hook(void) {
+
+	/* Unregister the hook, we don't want a double-registration (Bad Things(tm) happen) */
+	ast_manager_unregister_hook(&test_hook);
+
+	/* Register the hook for AMI events */
+	ast_manager_register_hook(&test_hook);
+
+}
+
+static void unregister_hook(void) {
+
+	/* Unregister the hook */
+	ast_manager_unregister_hook(&test_hook);
+
+}
+
+static char *handle_cli_amihook_send(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "amihook send test";
+		e->command = "amihook send";
 		e->usage = ""
-			"Usage: amihook send test"
+			"Usage: amihook send"
 			"";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	case CLI_HANDLER:
-		test_send(a);
+		hook_send();
+		return CLI_SUCCESS;
+	}
+
+	return CLI_FAILURE;
+}
+
+static char *handle_cli_amihook_register_hook(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "amihook register";
+		e->usage = ""
+			"Usage: amihook register"
+			"";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	case CLI_HANDLER:
+		register_hook();
+		return CLI_SUCCESS;
+	}
+
+	return CLI_FAILURE;
+}
+
+static char *handle_cli_amihook_unregister_hook(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "amihook unregister";
+		e->usage = ""
+			"Usage: amihook unregister"
+			"";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	case CLI_HANDLER:
+		unregister_hook();
 		return CLI_SUCCESS;
 	}
 
@@ -80,7 +135,9 @@
 }
 
 static struct ast_cli_entry cli_amihook_evt[] = {
-	AST_CLI_DEFINE(handle_cli_amihook_test_send, "Test module for AMI hook"),
+	AST_CLI_DEFINE(handle_cli_amihook_send, "Send an AMI event"),
+	AST_CLI_DEFINE(handle_cli_amihook_register_hook, "Register module for AMI hook"),
+	AST_CLI_DEFINE(handle_cli_amihook_unregister_hook, "Unregister module for AMI hook"),
 };
 
 static int unload_module(void)
@@ -93,9 +150,6 @@
 {
 	int res;
 
-	/* Register the hook for AMI events */
-	ast_manager_register_hook(&test_hook);
-
 	res = ast_cli_register_multiple(cli_amihook_evt, ARRAY_LEN(cli_amihook_evt));
 
 	return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;




More information about the asterisk-commits mailing list