[asterisk-commits] mjordan: branch mjordan/manager-events r368555 - /team/mjordan/manager-events...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 5 12:39:39 CDT 2012
Author: mjordan
Date: Tue Jun 5 12:39:34 2012
New Revision: 368555
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368555
Log:
Well, it compiles now
But the XML is a bit wonky inside the doc tree. Nuts.
Modified:
team/mjordan/manager-events/main/manager.c
team/mjordan/manager-events/main/xmldoc.c
Modified: team/mjordan/manager-events/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/manager-events/main/manager.c?view=diff&rev=368555&r1=368554&r2=368555
==============================================================================
--- team/mjordan/manager-events/main/manager.c (original)
+++ team/mjordan/manager-events/main/manager.c Tue Jun 5 12:39:34 2012
@@ -1086,6 +1086,9 @@
/*! \brief list of hooks registered */
static AST_RWLIST_HEAD_STATIC(manager_hooks, manager_custom_hook);
+
+/*! \brief A container of event documentation nodes */
+AO2_GLOBAL_OBJ_STATIC(event_docs);
static void free_channelvars(void);
@@ -6763,6 +6766,123 @@
return CLI_SUCCESS;
}
+static char *handle_manager_show_events(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ao2_container *events;
+ struct ao2_iterator it_events;
+ struct ast_xml_doc_item *item;
+ struct ast_str *buffer;
+ int i = 0;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "manager show events";
+ e->usage =
+ "Usage: manager show events\n"
+ " Prints a listing of the available Asterisk manager interface events.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3) {
+ return CLI_SHOWUSAGE;
+ }
+
+ buffer = ast_str_create(128);
+ if (!buffer) {
+ return CLI_SUCCESS;
+ }
+
+ events = ao2_global_obj_ref(event_docs);
+ if (!events) {
+ ast_cli(a->fd, "No manager event documentation loaded\n");
+ ast_free(buffer);
+ return CLI_SUCCESS;
+ }
+
+ ast_cli(a->fd, "Events:\n");
+ ast_cli(a->fd, "---------------------------");
+
+ it_events = ao2_iterator_init(events, 0);
+ while ((item = ao2_iterator_next(&it_events))) {
+ ast_str_append(&buffer, 0, " %-15.15s", item->name);
+ ++i;
+ if (i % 3 == 0) {
+ ast_cli(a->fd, "%s\n", ast_str_buffer(buffer));
+ ast_str_set(&buffer, 0, "%s", "");
+ }
+ }
+ if (i % 3 != 0) {
+ ast_cli(a->fd, "%s\n", ast_str_buffer(buffer));
+ }
+ ao2_iterator_destroy(&it_events);
+
+ ao2_ref(events, -1);
+ ast_free(buffer);
+
+ return CLI_SUCCESS;
+}
+
+static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ao2_container *events;
+ struct ast_xml_doc_item *item;
+ char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64], arguments_title[64];
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "manager show event";
+ e->usage =
+ "Usage: manager show event <eventname>\n"
+ " Provides a detailed description a Manager interface event.\n";
+ return NULL;
+ case CLI_GENERATE:
+ /* TODO: GENERATE NAME */
+ return NULL;
+ }
+ if (a->argc != 4) {
+ return CLI_SHOWUSAGE;
+ }
+
+ events = ao2_global_obj_ref(event_docs);
+ if (!events) {
+ ast_cli(a->fd, "No manager event documentation loaded\n");
+ return CLI_SUCCESS;
+ }
+
+ if (!(item = ao2_find(events, a->argv[3], OBJ_KEY))) {
+ ast_cli(a->fd, "Could not find event '%s'\n", a->argv[3]);
+ ao2_ref(events, -1);
+ return CLI_SUCCESS;
+ }
+
+ term_color(synopsis_title, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
+ term_color(description_title, "[Description]\n", COLOR_MAGENTA, 0, 40);
+ term_color(syntax_title, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
+ term_color(seealso_title, "[See Also]\n", COLOR_MAGENTA, 0, 40);
+ term_color(arguments_title, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
+
+ ast_cli(a->fd, "Event: %s\n", a->argv[3]);
+ for (; item; item = item->next) {
+ ast_cli(a->fd, "%s%s\n\n"
+ "%s%s\n\n"
+ "%s%s\n\n"
+ "%s%s\n\n"
+ "%s%s\n\n",
+ synopsis_title, ast_xmldoc_printable(S_OR(ast_str_buffer(item->synopsis), "Not available"), 1),
+ syntax_title, ast_xmldoc_printable(S_OR(ast_str_buffer(item->syntax), "Not available"), 1),
+ description_title, ast_xmldoc_printable(S_OR(ast_str_buffer(item->description), "Not available"),1),
+ arguments_title, ast_xmldoc_printable(S_OR(ast_str_buffer(item->arguments), "Not available"), 1),
+ seealso_title, ast_xmldoc_printable(S_OR(ast_str_buffer(item->seealso), "Not available"), 1)
+ );
+ }
+
+ ao2_ref(item, -1);
+ ao2_ref(events, -1);
+ return CLI_SUCCESS;
+}
+
+
static struct ast_cli_entry cli_manager[] = {
AST_CLI_DEFINE(handle_showmancmd, "Show a manager interface command"),
AST_CLI_DEFINE(handle_showmancmds, "List manager interface commands"),
@@ -6773,6 +6893,8 @@
AST_CLI_DEFINE(handle_mandebug, "Show, enable, disable debugging of the manager code"),
AST_CLI_DEFINE(handle_manager_reload, "Reload manager configurations"),
AST_CLI_DEFINE(handle_manager_show_settings, "Show manager global settings"),
+ AST_CLI_DEFINE(handle_manager_show_events, "List manager interface events"),
+ AST_CLI_DEFINE(handle_manager_show_event, "Show a manager interface event"),
};
/*!
@@ -6815,6 +6937,7 @@
static int __init_manager(int reload)
{
struct ast_config *ucfg = NULL, *cfg = NULL;
+ struct ao2_container *temp_event_docs;
const char *val;
char *cat = NULL;
int newhttptimeout = 60;
@@ -6872,6 +6995,15 @@
/* Append placeholder event so master_eventq never runs dry */
append_event("Event: Placeholder\r\n\r\n", 0);
}
+
+ temp_event_docs = ast_xmldoc_build_documentation("managerEvent");
+ if (temp_event_docs) {
+ temp_event_docs = ao2_global_obj_replace(event_docs, temp_event_docs);
+ if (temp_event_docs) {
+ ao2_ref(temp_event_docs, -1);
+ }
+ }
+
if ((cfg = ast_config_load2("manager.conf", "manager", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
return 0;
}
Modified: team/mjordan/manager-events/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/manager-events/main/xmldoc.c?view=diff&rev=368555&r1=368554&r2=368555
==============================================================================
--- team/mjordan/manager-events/main/xmldoc.c (original)
+++ team/mjordan/manager-events/main/xmldoc.c Tue Jun 5 12:39:34 2012
@@ -1976,7 +1976,7 @@
goto ast_xml_doc_item_failure;
}
- if (!ast_string_field_init(item, 64)) {
+ if (ast_string_field_init(item, 64)) {
ast_log(AST_LOG_ERROR, "Failed to initialize string field for ast_xml_doc_item instance\n");
goto ast_xml_doc_item_failure;
}
@@ -2064,17 +2064,17 @@
for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
/* Ignore empty nodes or nodes that aren't of the type requested */
- if (!ast_xml_node_get_children(node) || !strcasecmp(ast_xml_node_get_name(node), type)) {
+ if (!ast_xml_node_get_children(node) || strcasecmp(ast_xml_node_get_name(node), type)) {
continue;
}
-
+ ast_log(AST_LOG_NOTICE, "GOT %s!\n", ast_xml_node_get_name(node));
name = ast_xml_get_attribute(node, "name");
switch (xmldoc_get_syntax_type(type)) {
case MANAGER_EVENT_SYNTAX:
for (instance = ast_xml_node_get_children(node); instance; instance = ast_xml_node_get_next(instance)) {
struct ast_xml_doc_item *temp;
- if (!ast_xml_node_get_children(instance) || strcasecmp(ast_xml_node_get_name(node), "managerEventInstance")) {
+ if (!ast_xml_node_get_children(instance) || strcasecmp(ast_xml_node_get_name(instance), "managerEventInstance")) {
continue;
}
temp = xmldoc_build_documentation_item(instance, name, type);
More information about the asterisk-commits
mailing list