[svn-commits] kmoore: branch kmoore/channel_event_refactor r392276 - /team/kmoore/channel_e...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 19 15:15:43 CDT 2013


Author: kmoore
Date: Wed Jun 19 15:15:41 2013
New Revision: 392276

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392276
Log:
Rework the chan_dahdi/sig_analog interaction and revert changes in chan_agent that will be handled in a different review

Removed:
    team/kmoore/channel_event_refactor/channels/chan_dahdi.h
Modified:
    team/kmoore/channel_event_refactor/channels/chan_agent.c
    team/kmoore/channel_event_refactor/channels/chan_dahdi.c
    team/kmoore/channel_event_refactor/channels/sig_analog.c

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=392276&r1=392275&r2=392276
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_agent.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_agent.c Wed Jun 19 15:15:41 2013
@@ -69,7 +69,6 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/event.h"
 #include "asterisk/data.h"
-#include "asterisk/stasis_channels.h"
 
 /*** DOCUMENTATION
 	<application name="AgentLogin" language="en_US">
@@ -194,36 +193,6 @@
 			<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";
@@ -1888,83 +1857,6 @@
 	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,
-	);
-
-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,
-	);
-
-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).
  * 
@@ -2161,7 +2053,25 @@
 						p->lastdisc = ast_tvnow();
 						time(&p->loginstart);
 
-						send_agent_login(chan, p->agent);
+						/*** 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));
 						ast_queue_log("NONE", ast_channel_uniqueid(chan), agent, "AGENTLOGIN", "%s", ast_channel_name(chan));
 						ast_verb(2, "Agent '%s' logged in (format %s/%s)\n", p->agent,
 								    ast_getformatname(ast_channel_readformat(chan)), ast_getformatname(ast_channel_writeformat(chan)));
@@ -2243,7 +2153,22 @@
 						ast_mutex_unlock(&p->lock);
 
 						ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "%s", agent);
-						send_agent_logoff(chan, p->agent, logintime);
+						/*** 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));
 						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);
 
@@ -2562,14 +2487,6 @@
  */
 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;
@@ -2639,10 +2556,6 @@
 	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;
 }
 

Modified: team/kmoore/channel_event_refactor/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_dahdi.c?view=diff&rev=392276&r1=392275&r2=392276
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_dahdi.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_dahdi.c Wed Jun 19 15:15:41 2013
@@ -69,7 +69,6 @@
 
 #include <dahdi/user.h>
 #include <dahdi/tonezone.h>
-#include "chan_dahdi.h"
 #include "sig_analog.h"
 /* Analog signaling is currently still present in chan_dahdi for use with
  * radio. Sig_analog does not currently handle any radio operations. If
@@ -4065,7 +4064,7 @@
 	}
 }
 
-void dahdi_publish_channel_alarm_clear(int channel)
+static void publish_channel_alarm_clear(int channel)
 {
 	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 
@@ -4100,7 +4099,7 @@
 #endif	/* defined(HAVE_PRI) */
 
 	if (report_alarms & REPORT_CHANNEL_ALARMS) {
-		dahdi_publish_channel_alarm_clear(p->channel);
+		publish_channel_alarm_clear(p->channel);
 	}
 	if (report_alarms & REPORT_SPAN_ALARMS && p->manages_span_alarms) {
 		publish_span_alarm_clear(p->span);
@@ -10218,7 +10217,7 @@
 	return 0;
 }
 
-void dahdi_publish_dnd_state(int channel, const char *status)
+static void publish_dnd_state(int channel, const char *status)
 {
 	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 	RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
@@ -10263,7 +10262,7 @@
 	ast_verb(3, "%s DND on channel %d\n",
 			flag? "Enabled" : "Disabled",
 			dahdichan->channel);
-	dahdi_publish_dnd_state(dahdichan->channel, flag ? "enabled" : "disabled");
+	publish_dnd_state(dahdichan->channel, flag ? "enabled" : "disabled");
 	manager_event(EVENT_FLAG_SYSTEM, "DNDState",
 			"Channel: DAHDI/%d\r\n"
 			"Status: %s\r\n", dahdichan->channel,

Modified: team/kmoore/channel_event_refactor/channels/sig_analog.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/sig_analog.c?view=diff&rev=392276&r1=392275&r2=392276
==============================================================================
--- team/kmoore/channel_event_refactor/channels/sig_analog.c (original)
+++ team/kmoore/channel_event_refactor/channels/sig_analog.c Wed Jun 19 15:15:41 2013
@@ -47,7 +47,6 @@
 #include "asterisk/bridging.h"
 
 #include "sig_analog.h"
-#include "chan_dahdi.h"
 
 /*** DOCUMENTATION
  ***/
@@ -2623,6 +2622,19 @@
 	return ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p);
 }
 
+static void analog_publish_channel_alarm_clear(int channel)
+{
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+
+	ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
+	body = ast_json_pack("{s: i}", "Channel", channel);
+	if (!body) {
+		return;
+	}
+	
+	ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
+}
+
 static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
 {
 	int res, x;
@@ -3087,7 +3099,7 @@
 		break;
 	case ANALOG_EVENT_NOALARM:
 		analog_set_alarm(p, 0);
-		dahdi_publish_channel_alarm_clear(p->channel);
+		analog_publish_channel_alarm_clear(p->channel);
 		break;
 	case ANALOG_EVENT_WINKFLASH:
 		if (p->inalarm) {
@@ -3729,7 +3741,7 @@
 		break;
 	case ANALOG_EVENT_NOALARM:
 		analog_set_alarm(i, 0);
-		dahdi_publish_channel_alarm_clear(i->channel);
+		analog_publish_channel_alarm_clear(i->channel);
 		break;
 	case ANALOG_EVENT_ALARM:
 		analog_set_alarm(i, 1);
@@ -3932,6 +3944,27 @@
 	return 0;
 }
 
+static void analog_publish_dnd_state(int channel, const char *status)
+{
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+	RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
+	if (!dahdichan) {
+		return;
+	}
+
+	ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
+
+	ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
+	body = ast_json_pack("{s: s, s: s}",
+		"Channel", ast_str_buffer(dahdichan),
+		"Status", status);
+	if (!body) {
+		return;
+	}
+	
+	ast_manager_publish_event("DNDState", EVENT_FLAG_SYSTEM, body);
+}
+
 int analog_dnd(struct analog_pvt *p, int flag)
 {
 	if (flag == -1) {
@@ -3943,7 +3976,7 @@
 	ast_verb(3, "%s DND on channel %d\n",
 			flag ? "Enabled" : "Disabled",
 			p->channel);
-	dahdi_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
+	analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
 
 	return 0;
 }




More information about the svn-commits mailing list