[asterisk-commits] mmichelson: branch mmichelson/queue-reset r167161 - /team/mmichelson/queue-re...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jan 4 13:28:07 CST 2009
Author: mmichelson
Date: Sun Jan 4 13:28:06 2009
New Revision: 167161
URL: http://svn.digium.com/view/asterisk?view=rev&rev=167161
Log:
Another earth-shattering change to the CLI commands.
I had a discussion with Kevin about this branch last
week, and he gave some wonderful suggestions for the
new CLI commands offered in this branch. Essentially,
I had made a mire of a command that was trying to do
way too much for not much benefit. We came to an
agreement that two changes needed to be made.
1) Simplify the 'queue reload' command significantly
2) Allow for multiple queues to be specified for the
new CLI commands.
This commit accomplishes part 1. This changes the queue
reload command to not allow arbitrary combinations of
qualifiers to be used when reloading queues. This simplifies
the command both from a user interface perspective, as
well as a coding perspective, so it is definitely a
good thing.
This code passes the "it compiles" test, but I have not
actually attempted to use the CLI commands at all yet
as I would like to finish part 2 of the modifications
first.
Modified:
team/mmichelson/queue-reset/apps/app_queue.c
Modified: team/mmichelson/queue-reset/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/queue-reset/apps/app_queue.c?view=diff&rev=167161&r1=167160&r2=167161
==============================================================================
--- team/mmichelson/queue-reset/apps/app_queue.c (original)
+++ team/mmichelson/queue-reset/apps/app_queue.c Sun Jan 4 13:28:06 2009
@@ -5512,7 +5512,7 @@
*/
static void reload_single_member(const char *memberdata, struct call_queue *q)
{
- const char *membername, *interface, *state_interface, *tmp;
+ char *membername, *interface, *state_interface, *tmp;
char *parse;
struct member *cur, *newm;
struct member tmpmem;
@@ -6769,90 +6769,61 @@
return CLI_SUCCESS;
}
-static char *complete_queue_reload(const char *line, const char *word, int pos, int state)
-{
- int wordlen;
- int which = 0;
- static int localstate = 0;
- int rules = strstr(line, "rules") != NULL;
- int stats = strstr(line, "stats") != NULL;
- int parameters = strstr(line, "parameters") != NULL;
- int members = strstr(line, "members") != NULL;
-
- if (pos > 7) {
- return NULL;
- }
-
- if (ast_strlen_zero(word)) {
- switch (state) {
- case 0:
- if (!rules)
- return ast_strdup("rules");
- case 1:
- if (!stats)
- return ast_strdup("stats");
- case 2:
- if (!parameters)
- return ast_strdup("parameters");
- case 3:
- if (!members)
- return ast_strdup("members");
- default:
- {
- char *ret = complete_queue(line, word, pos, localstate++);
- if (!ret) {
- localstate = 0;
- } else if (strstr(line, ret)) {
- ret = NULL;
- }
- return ret;
- }
- }
- }
-
- wordlen = strlen(word);
-
- if (!rules && !strncasecmp(word, "rules", wordlen) && (++which > state)) {
- return ast_strdup("rules");
- } else if (!stats && !strncasecmp(word, "stats", wordlen) && (++which > state)) {
- return ast_strdup("stats");
- } else if (!parameters && !strncasecmp(word, "parameters", wordlen) && (++which > state)) {
- return ast_strdup("parameters");
- } else if (!members && !strncasecmp(word, "members", wordlen) && (++which > state)) {
- return ast_strdup("members");
- } else {
- char *ret = complete_queue(line, word, pos, localstate++);
- if (!ret) {
- localstate = 0;
- } else if (strstr(line, ret)) {
+static char *handle_queue_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_flags mask = {0,};
+ char *queuename = NULL;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "queue reset stats";
+ e->usage =
+ "Usage: queue reset stats [<queuename>]\n"
+ "\n"
+ "Issuing this command will reset statistics for\n"
+ "<queuename>, or for all queues if no queue is\n"
+ "specified.\n";
return NULL;
- }
- return ret;
- }
+ case CLI_GENERATE:
+ if (a->pos == 3) {
+ return complete_queue(a->line, a->word, a->pos, a->n);
+ } else {
+ return NULL;
+ }
+ }
+
+ if (a->argc < 3 || a->argc > 4) {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (a->argc == 4) {
+ queuename = a->argv[3];
+ }
+
+ ast_set_flag(&mask, QUEUE_RESET_STATS);
+
+ reload_handler(1, &mask, queuename);
+ return CLI_SUCCESS;
}
static char *handle_queue_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_flags mask = {0,};
- int i;
char *queuename = NULL;
switch (cmd) {
case CLI_INIT:
- e->command = "queue reload";
+ e->command = "queue reload {parameters|members|rules|all}";
e->usage =
- "Usage: queue reload [<queuename>] [parameters] [members] [rules] [stats]\n"
+ "Usage: queue reload {parameters|members|rules|all} [<queuename>]\n"
"Reload queues. If <queuename> is specified, only reload information pertaining\n"
- "to <queuename>. If no extra qualifiers appear, then all aspects of the queue\n"
- "will be reloaded. If, however, qualifiers are added, then only those portions of\n"
- "the queue will be reloaded. As an example:\n"
- "\"queue reload myqueue\" would cause myqueue's members, parameters, and stats to\n"
- "be reloaded, and would cause a reload of queue rules, too.\n"
- "\"queue reload myqueue members\" would cause myqueue's members to be reloaded but\n"
- "no other queue parameters would be reloaded. myqueue's stats would not be reset and\n"
- "queue rules would also not be reloaded.\n"
- "\"queue reload parameters rules\" would cause all queues' parameters to be reloaded,\n"
- "but would not affect their members. The queues' stats would also not be reset. Queue\n"
- "rules would also be reloaded due to this command\n"
+ "to <queuename>. One of 'parameters,' 'members,' 'rules,' or 'all' must be\n"
+ "specified in order to know what information to reload. Below is an explanation\n"
+ "of each of these qualifiers.\n"
+ "\n"
+ "\t'members' - reload queue members from queues.conf\n"
+ "\t'parameters' - reload all queue options except for queue members\n"
+ "\t'rules' - reload the queuerules.conf file\n"
+ "\t'all' - reload queue rules, parameters, and members\n"
"\n"
"Note: the 'rules' qualifier here cannot actually be applied to a specific queue.\n"
"Use of the 'rules' qualifier causes queuerules.conf to be reloaded. Even if only\n"
@@ -6860,44 +6831,28 @@
"other queues to be affected\n";
return NULL;
case CLI_GENERATE:
- /* This will be a fun one to write :) */
- return complete_queue_reload(a->line, a->word, a->pos, a->n);
- }
-
- if (a->argc < 2 || a->argc > 7)
+ if (a->pos == 3) {
+ return complete_queue(a->line, a->word, a->pos, a->n);
+ } else {
+ return NULL;
+ }
+ }
+
+ if (a->argc < 3 || a->argc > 4)
return CLI_SHOWUSAGE;
- if (a->argc == 2) {
- /*Reload everything*/
+ if (!strcasecmp(a->argv[2], "rules")) {
+ ast_set_flag(&mask, QUEUE_RELOAD_RULES);
+ } else if (!strcasecmp(a->argv[2], "members")) {
+ ast_set_flag(&mask, QUEUE_RELOAD_MEMBER);
+ } else if (!strcasecmp(a->argv[2], "parameters")) {
+ ast_set_flag(&mask, QUEUE_RELOAD_PARAMETERS);
+ } else if (!strcasecmp(a->argv[2], "all")) {
ast_set_flag(&mask, AST_FLAGS_ALL);
- reload_handler(1, &mask, NULL);
- return CLI_SUCCESS;
- }
-
- for (i = 2; i < a->argc; i++) {
- if (!strcasecmp(a->argv[i], "members")) {
- ast_set_flag(&mask, QUEUE_RELOAD_MEMBER);
- } else if (!strcasecmp(a->argv[i], "rules")) {
- ast_set_flag(&mask, QUEUE_RELOAD_RULES);
- } else if (!strcasecmp(a->argv[i], "stats")) {
- ast_set_flag(&mask, QUEUE_RESET_STATS);
- } else if (!strcasecmp(a->argv[i], "parameters")) {
- ast_set_flag(&mask, QUEUE_RELOAD_PARAMETERS);
- } else {
- /*They must have specified a queue*/
- if (queuename)
- ast_log(LOG_WARNING, "Queue '%s' has already been specified. skipping '%s'\n", queuename, a->argv[i]);
- else {
- queuename = a->argv[i];
- }
- }
- }
-
- /* "queue reload <somequeue>" means to reload everything
- * for the queue, so set the mask appropriately
- */
- if (a->argc == 3 && queuename) {
- ast_set_flag(&mask, AST_FLAGS_ALL);
+ }
+
+ if (a->argc == 4) {
+ queuename = a->argv[3];
}
reload_handler(1, &mask, queuename);
@@ -6921,7 +6876,8 @@
AST_CLI_DEFINE(handle_queue_pause_member, "Pause or unpause a queue member"),
AST_CLI_DEFINE(handle_queue_set_member_penalty, "Set penalty for a channel of a specified queue"),
AST_CLI_DEFINE(handle_queue_rule_show, "Show the rules defined in queuerules.conf"),
- AST_CLI_DEFINE(handle_queue_reload, "Reload queues, members, queue rules, or any combination"),
+ AST_CLI_DEFINE(handle_queue_reload, "Reload queues, members, queue rules, or parameters"),
+ AST_CLI_DEFINE(handle_queue_reset, "Reset statistics for a queue"),
};
static int unload_module(void)
More information about the asterisk-commits
mailing list