[asterisk-commits] kmoore: branch kmoore/channel_event_refactor r391555 - in /team/kmoore/channe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 12 13:55:15 CDT 2013
Author: kmoore
Date: Wed Jun 12 13:55:13 2013
New Revision: 391555
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391555
Log:
Refactor Agentlogin/AgentLogoff
Modified:
team/kmoore/channel_event_refactor/CHANGES
team/kmoore/channel_event_refactor/channels/chan_agent.c
Modified: team/kmoore/channel_event_refactor/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/CHANGES?view=diff&rev=391555&r1=391554&r2=391555
==============================================================================
--- team/kmoore/channel_event_refactor/CHANGES (original)
+++ team/kmoore/channel_event_refactor/CHANGES Wed Jun 12 13:55:13 2013
@@ -116,6 +116,9 @@
"MConnectedID" prefixes with Subaddr*, Name*, and Num* suffixes instead
of "CallerID" and "ConnectedID" to avoid confusion with similarly named
parameters in the channel snapshot.
+
+ * The "Agentlogin" and "Agentlogoff" events have been renamed "AgentLogin" and
+ "AgentLogoff" respectively.
AGI (Asterisk Gateway Interface)
------------------
Modified: team/kmoore/channel_event_refactor/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_agent.c?view=diff&rev=391555&r1=391554&r2=391555
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_agent.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_agent.c Wed Jun 12 13:55:13 2013
@@ -69,6 +69,7 @@
#include "asterisk/stringfields.h"
#include "asterisk/event.h"
#include "asterisk/data.h"
+#include "asterisk/stasis_channels.h"
/*** DOCUMENTATION
<application name="AgentLogin" language="en_US">
@@ -197,6 +198,36 @@
<para>Sets an agent as no longer logged in.</para>
</description>
</manager>
+ <managerEvent language="en_US" name="AgentLogin">
+ <managerEventInstance class="EVENT_FLAG_AGENT">
+ <synopsis>Raised when an Agent has logged in.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Agent">
+ <para>The name of the agent.</para>
+ </parameter>
+ </syntax>
+ <see-also>
+ <ref type="application">AgentLogin</ref>
+ <ref type="managerEvent">Agentlogoff</ref>
+ </see-also>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="AgentLogoff">
+ <managerEventInstance class="EVENT_FLAG_AGENT">
+ <synopsis>Raised when an Agent has logged off.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='AgentLogin']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Logintime">
+ <para>The time the agent logged on.</para>
+ </parameter>
+ </syntax>
+ <see-also>
+ <ref type="managerEvent">AgentLogin</ref>
+ </see-also>
+ </managerEventInstance>
+ </managerEvent>
+
***/
static const char tdesc[] = "Call Agent Proxy Channel";
@@ -1869,6 +1900,85 @@
AST_CLI_DEFINE(agent_logoff_cmd, "Sets an agent offline"),
};
+static struct ast_manager_event_blob *login_to_ami(struct stasis_message *msg)
+{
+ RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
+ RAII_VAR(struct ast_str *, party_string, ast_str_create(256), ast_free);
+ struct ast_channel_blob *obj = stasis_message_data(msg);
+ const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
+
+ channel_string = ast_manager_build_channel_state_string(obj->snapshot);
+ if (!channel_string) {
+ return NULL;
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_AGENT, "AgentLogin",
+ "%s"
+ "Agent: %s\r\n",
+ ast_str_buffer(channel_string), agent);
+}
+
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(login_type,
+ .to_ami = login_to_ami,
+ );
+
+/*! \brief Sends a session timeout channel blob used to produce SessionTimeout AMI messages */
+static void send_agent_login(struct ast_channel *chan, const char *agent)
+{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+ ast_assert(agent != NULL);
+
+ blob = ast_json_pack("{s: s}",
+ "agent", agent);
+ if (!blob) {
+ return;
+ }
+
+ ast_channel_publish_blob(chan, login_type(), blob);
+}
+
+static struct ast_manager_event_blob *logoff_to_ami(struct stasis_message *msg)
+{
+ RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
+ RAII_VAR(struct ast_str *, party_string, ast_str_create(256), ast_free);
+ struct ast_channel_blob *obj = stasis_message_data(msg);
+ const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
+ long logintime = ast_json_integer_get(ast_json_object_get(obj->blob, "logintime"));
+
+ channel_string = ast_manager_build_channel_state_string(obj->snapshot);
+ if (!channel_string) {
+ return NULL;
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_AGENT, "AgentLogoff",
+ "%s"
+ "Agent: %s\r\n"
+ "Logintime: %ld\r\n",
+ ast_str_buffer(channel_string), agent, logintime);
+}
+
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(logoff_type,
+ .to_ami = logoff_to_ami,
+ );
+
+/*! \brief Sends a session timeout channel blob used to produce SessionTimeout AMI messages */
+static void send_agent_logoff(struct ast_channel *chan, const char *agent, long logintime)
+{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+ ast_assert(agent != NULL);
+
+ blob = ast_json_pack("{s: s, s: i}",
+ "agent", agent,
+ "logintime", logintime);
+ if (!blob) {
+ return;
+ }
+
+ ast_channel_publish_blob(chan, logoff_type(), blob);
+}
+
/*!
* Called by the AgentLogin application (from the dial plan).
*
@@ -2074,25 +2184,7 @@
p->lastdisc = ast_tvnow();
time(&p->loginstart);
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when an Agent has logged in.</synopsis>
- <syntax>
- <parameter name="Agent">
- <para>The name of the agent.</para>
- </parameter>
- </syntax>
- <see-also>
- <ref type="application">AgentLogin</ref>
- <ref type="managerEvent">Agentlogoff</ref>
- </see-also>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGENT, "Agentlogin",
- "Agent: %s\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- p->agent, ast_channel_name(chan), ast_channel_uniqueid(chan));
+ send_agent_login(chan, p->agent);
if (update_cdr && ast_channel_cdr(chan))
snprintf(ast_channel_cdr(chan)->channel, sizeof(ast_channel_cdr(chan)->channel), "%s", agent);
ast_queue_log("NONE", ast_channel_uniqueid(chan), agent, "AGENTLOGIN", "%s", ast_channel_name(chan));
@@ -2176,22 +2268,7 @@
ast_mutex_unlock(&p->lock);
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "%s", agent);
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when an Agent has logged off.</synopsis>
- <syntax>
- <xi:include xpointer="xpointer(/docs/managerEvent[@name='Agentlogin']/managerEventInstance/syntax/parameter[@name='Agent'])" />
- </syntax>
- <see-also>
- <ref type="managerEvent">Agentlogin</ref>
- </see-also>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGENT, "Agentlogoff",
- "Agent: %s\r\n"
- "Logintime: %ld\r\n"
- "Uniqueid: %s\r\n",
- p->agent, logintime, ast_channel_uniqueid(chan));
+ send_agent_logoff(chan, p->agent, logintime);
ast_queue_log("NONE", ast_channel_uniqueid(chan), agent, "AGENTLOGOFF", "%s|%ld", ast_channel_name(chan), logintime);
ast_verb(2, "Agent '%s' logged out\n", p->agent);
@@ -2512,6 +2589,14 @@
*/
static int load_module(void)
{
+ if (STASIS_MESSAGE_TYPE_INIT(login_type)) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
+ if (STASIS_MESSAGE_TYPE_INIT(logoff_type)) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
if (!(agent_tech.capabilities = ast_format_cap_alloc())) {
ast_log(LOG_ERROR, "ast_format_cap_alloc_nolock fail.\n");
return AST_MODULE_LOAD_FAILURE;
@@ -2581,6 +2666,10 @@
AST_LIST_UNLOCK(&agents);
agent_tech.capabilities = ast_format_cap_destroy(agent_tech.capabilities);
+
+ STASIS_MESSAGE_TYPE_CLEANUP(login_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(logoff_type);
+
return 0;
}
More information about the asterisk-commits
mailing list