44 #define CATEGORY "/main/amihooks/"
46 AST_MUTEX_DEFINE_STATIC(hook_lock);
50 static int wait_for_hook(
struct ast_test *
test)
53 struct timespec timeout = {
54 .tv_sec = start.tv_sec + 2,
55 .tv_nsec = start.tv_usec * 1000
59 ast_mutex_lock(&hook_lock);
61 if (ast_cond_timedwait(&hook_cond, &hook_lock, &timeout) == ETIMEDOUT) {
62 ast_test_status_update(test,
"Test timed out while waiting for hook event\n");
67 ast_mutex_unlock(&hook_lock);
76 info->name = __func__;
78 info->summary =
"Execute an action using an AMI hook";
79 info->description = info->summary;
80 return AST_TEST_NOT_RUN;
90 return wait_for_hook(test) ? AST_TEST_FAIL : AST_TEST_PASS;
95 static int amihook_helper(
int category,
const char *
event,
char *content)
97 ast_log(LOG_NOTICE,
"AMI Event: \nCategory: %d Event: %s\n%s\n", category, event, content);
99 ast_mutex_lock(&hook_lock);
101 ast_cond_signal(&hook_cond);
102 ast_mutex_unlock(&hook_lock);
108 .helper = &amihook_helper,
111 static int hook_send(
void) {
115 res =
ast_hook_send_action(&test_hook,
"Action: Command\nCommand: core show version\nActionID: 987654321\n");
120 static void register_hook(
void) {
130 static void unregister_hook(
void) {
143 "Usage: amihook send"
160 e->
command =
"amihook register";
162 "Usage: amihook register"
179 e->
command =
"amihook unregister";
181 "Usage: amihook unregister"
195 AST_CLI_DEFINE(handle_cli_amihook_send,
"Send an AMI event"),
196 AST_CLI_DEFINE(handle_cli_amihook_register_hook,
"Register module for AMI hook"),
197 AST_CLI_DEFINE(handle_cli_amihook_unregister_hook,
"Unregister module for AMI hook"),
200 static int unload_module(
void)
202 AST_TEST_UNREGISTER(amihook_cli_send);
207 static int load_module(
void)
213 AST_TEST_REGISTER(amihook_cli_send);
Asterisk main include file. File version handling, generic pbx functions.
void ast_manager_unregister_hook(struct manager_custom_hook *hook)
Delete a custom hook to be called when an event is fired.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
int ast_hook_send_action(struct manager_custom_hook *hook, const char *msg)
Registered hooks can call this function to invoke actions and they will receive responses through reg...
void ast_manager_register_hook(struct manager_custom_hook *hook)
Add a custom hook to be called when an event is fired.
descriptor for a cli entry.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
ast_cli_command
calling arguments for new-style handlers.
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
Module has failed to load, may be in an inconsistent state.
Standard Command Line Interface.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.