[asterisk-commits] file: branch file/app_agents r162270 - /team/file/app_agents/apps/app_agents.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Dec 9 14:35:43 CST 2008
Author: file
Date: Tue Dec 9 14:35:42 2008
New Revision: 162270
URL: http://svn.digium.com/view/asterisk?view=rev&rev=162270
Log:
Add an additional CLI command and some manager commands.
(closes issue #13475)
Reported by: korihor
Patches:
app_agents.c.agent_show_available.patch_v3 uploaded by korihor (license 462)
Modified:
team/file/app_agents/apps/app_agents.c
Modified: team/file/app_agents/apps/app_agents.c
URL: http://svn.digium.com/view/asterisk/team/file/app_agents/apps/app_agents.c?view=diff&rev=162270&r1=162269&r2=162270
==============================================================================
--- team/file/app_agents/apps/app_agents.c (original)
+++ team/file/app_agents/apps/app_agents.c Tue Dec 9 14:35:42 2008
@@ -104,6 +104,14 @@
static const char descrip2[] =
" AgentCall2(Agent Name):\n"
"Attempts to talk to the given agent. Always returns -1.";
+
+static const char mandescr_agents2[] =
+"Description: Will list info about all possible agents.\n"
+"Variables: NONE\n";
+
+static const char mandescr_agents2_available[] =
+"Description: Will list info about all available agents.\n"
+"Variables: NONE\n";
/*! \brief State that the agent should be in */
enum agent2_state {
@@ -920,9 +928,104 @@
return CLI_SUCCESS;
}
+/*! \brief CLI command to show all available agents */
+static char *agents2_show_available(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct agent2_agent *agent;
+ struct ao2_iterator i;
+ int total_available = 0;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "agents2 show available";
+ e->usage =
+ "Usage: agents2 show available\n"
+ " Provides a list of all available agents.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ i = ao2_iterator_init(agents, 0);
+
+ for (; (agent = ao2_iterator_next(&i)); ao2_ref(agent, -1)) {
+ if (!(agent->state == AGENT2_STATE_NONE || agent->state == AGENT2_STATE_HANGUP)) {
+ ast_cli(a->fd, "%s(%s) %s\n", agent->name, agent2_type2text(agent->type), agent2_state2text(agent->state));
+ total_available++;
+ }
+ }
+
+ ast_cli(a->fd, "%d agents available\n\n", total_available);
+
+ return CLI_SUCCESS;
+}
+
+/*! \brief Lists agents and their status to the Manager API. */
+static int action_agents2(struct mansession *s, const struct message *m)
+{
+ struct agent2_agent *agent;
+ struct ao2_iterator i;
+ const char *id = astman_get_header(m,"ActionID");
+ char idText[256] = "";
+
+ if (!ast_strlen_zero(id))
+ snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id);
+ astman_send_ack(s, m, "Agents2 will follow");
+
+ i = ao2_iterator_init(agents, 0);
+
+ for (; (agent = ao2_iterator_next(&i)); ao2_ref(agent, -1)) {
+ astman_append(s, "Event: Agents2\r\n"
+ "Agent: %s\r\n"
+ "Type: %s\r\n"
+ "Status: %s\r\n"
+ "%s"
+ "\r\n",
+ agent->name, agent2_type2text(agent->type), agent2_state2text(agent->state), idText);
+ }
+
+ astman_append(s, "Event: Agents2Complete\r\n"
+ "%s"
+ "\r\n",idText);
+ return 0;
+}
+
+/*! \brief Lists available agents and their status to the Manager API. */
+static int action_agents2_available(struct mansession *s, const struct message *m)
+{
+ struct agent2_agent *agent;
+ struct ao2_iterator i;
+ const char *id = astman_get_header(m,"ActionID");
+ char idText[256] = "";
+
+ if (!ast_strlen_zero(id))
+ snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id);
+ astman_send_ack(s, m, "Agents2Available will follow");
+
+ i = ao2_iterator_init(agents, 0);
+
+ for (; (agent = ao2_iterator_next(&i)); ao2_ref(agent, -1)) {
+ if (!(agent->state == AGENT2_STATE_NONE || agent->state == AGENT2_STATE_HANGUP)) {
+ astman_append(s, "Event: Agents2Available\r\n"
+ "Agent: %s\r\n"
+ "Type: %s\r\n"
+ "Status: %s\r\n"
+ "%s"
+ "\r\n",
+ agent->name, agent2_type2text(agent->type), agent2_state2text(agent->state), idText);
+ }
+ }
+
+ astman_append(s, "Event: Agents2AvailableComplete\r\n"
+ "%s"
+ "\r\n",idText);
+ return 0;
+}
+
/*! \brief CLI commands to interact with things */
static struct ast_cli_entry cli_agents2[] = {
AST_CLI_DEFINE(agents2_show, "Show status of agents"),
+ AST_CLI_DEFINE(agents2_show_available, "Show status of available agents"),
};
/*! \brief Function called when module should be reloaded */
@@ -945,6 +1048,9 @@
ast_register_application(app, agent2_login, synopsis, descrip);
ast_register_application(app2, agent2_call, synopsis2, descrip2);
+
+ ast_manager_register2("Agents2", EVENT_FLAG_AGENT, action_agents2, "Lists agents and their status", mandescr_agents2);
+ ast_manager_register2("Agents2Available", EVENT_FLAG_AGENT, action_agents2_available, "Lists available agents and their status", mandescr_agents2_available);
ast_cli_register_multiple(cli_agents2, sizeof(cli_agents2) / sizeof(struct ast_cli_entry));
@@ -957,6 +1063,8 @@
ast_cli_unregister_multiple(cli_agents2, sizeof(cli_agents2) / sizeof(struct ast_cli_entry));
ast_unregister_application(app);
ast_unregister_application(app2);
+ ast_manager_unregister("Agents2");
+ ast_manager_unregister("Agents2Available");
ast_devstate_prov_del("Agent");
ao2_ref(agents, -1);
More information about the asterisk-commits
mailing list