[asterisk-commits] tilghman: trunk r133860 - in /trunk: channels/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 25 16:20:04 CDT 2008


Author: tilghman
Date: Fri Jul 25 16:20:03 2008
New Revision: 133860

URL: http://svn.digium.com/view/asterisk?view=rev&rev=133860
Log:
Deprecate *_device_state_* APIs in favor of *_devstate_* APIs

Modified:
    trunk/channels/chan_agent.c
    trunk/channels/chan_dahdi.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_skinny.c
    trunk/include/asterisk/devicestate.h
    trunk/main/channel.c
    trunk/main/devicestate.c

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Fri Jul 25 16:20:03 2008
@@ -303,7 +303,7 @@
 			}
 			if (strcasecmp(p->chan->name, device) == 0 || strcasecmp(basename, device) == 0) {
 				p->inherited_devicestate = state;
-				ast_device_state_changed("Agent/%s", p->agent);
+				ast_devstate_changed(state, "Agent/%s", p->agent);
 			}
 		}
 		ast_mutex_unlock(&p->lock);
@@ -518,7 +518,7 @@
 			}
 			p->chan = NULL;
 			p->inherited_devicestate = -1;
-			ast_device_state_changed("Agent/%s", p->agent);
+			ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
 			p->acknowledged = 0;
 		}
  	} else {
@@ -734,7 +734,7 @@
 		/* Agent hung-up */
 		p->chan = NULL;
 		p->inherited_devicestate = -1;
-		ast_device_state_changed("Agent/%s", p->agent);
+		ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
 	}
 
 	if (!res) {
@@ -856,7 +856,7 @@
 				ast_hangup(p->chan);
 				p->chan = NULL;
 				p->inherited_devicestate = -1;
-				ast_device_state_changed("Agent/%s", p->agent);
+				ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
 			}
 			ast_debug(1, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
 			if ((p->deferlogoff) || (howlong && p->autologoff && (howlong > p->autologoff))) {
@@ -890,7 +890,7 @@
 		if (persistent_agents)
 			dump_agents();
 	} else {
-		ast_device_state_changed("Agent/%s", p->agent);
+		ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
 	}
 
 	if (p->pending) {
@@ -1581,7 +1581,7 @@
 	p->loginchan[0] ='\0';
 	p->logincallerid[0] = '\0';
 	p->inherited_devicestate = -1;
-	ast_device_state_changed("Agent/%s", p->agent);
+	ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
 	if (persistent_agents)
 		dump_agents();	
 
@@ -2082,7 +2082,7 @@
 							check_availability(p, 0);
 						ast_mutex_unlock(&p->lock);
 						AST_LIST_UNLOCK(&agents);
-						ast_device_state_changed("Agent/%s", p->agent);
+						ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
 						while (res >= 0) {
 							ast_mutex_lock(&p->lock);
 							if (p->deferlogoff && p->chan) {
@@ -2103,7 +2103,7 @@
 								if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > 0) {
 									ast_debug(1, "Wrapup time for %s expired!\n", p->agent);
 									p->lastdisc = ast_tv(0, 0);
-									ast_device_state_changed("Agent/%s", p->agent);
+									ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
 									if (p->ackcall > 1)
 										check_beep(p, 0);
 									else
@@ -2152,7 +2152,7 @@
 						ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGOFF", "%s|%ld", chan->name, logintime);
 						ast_verb(2, "Agent '%s' logged out\n", p->agent);
 						/* If there is no owner, go ahead and kill it now */
-						ast_device_state_changed("Agent/%s", p->agent);
+						ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
 						if (p->dead && !p->owner) {
 							ast_mutex_destroy(&p->lock);
 							ast_mutex_destroy(&p->app_lock);
@@ -2317,7 +2317,7 @@
 				cur_agent->logincallerid[0] = '\0';
 			if (cur_agent->loginstart == 0)
 				time(&cur_agent->loginstart);
-			ast_device_state_changed("Agent/%s", cur_agent->agent);	
+			ast_devstate_changed(AST_DEVICE_UNKNOWN, "Agent/%s", cur_agent->agent);	
 		}
 	}
 	AST_LIST_UNLOCK(&agents);

Modified: trunk/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_dahdi.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/channels/chan_dahdi.c (original)
+++ trunk/channels/chan_dahdi.c Fri Jul 25 16:20:03 2008
@@ -6001,7 +6001,7 @@
 	/* Configure the new channel jb */
 	ast_jb_configure(tmp, &global_jbconf);
 
-	ast_device_state_changed_literal(tmp->name);
+	ast_devstate_changed_literal(ast_state_chan2dev(state), tmp->name);
 
 	for (v = i->vars ; v ; v = v->next)
                 pbx_builtin_setvar_helper(tmp, v->name, v->value);

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Fri Jul 25 16:20:03 2008
@@ -6253,7 +6253,7 @@
 	if (expire && (expire < iaxs[callno]->expiry)) 
 		iaxs[callno]->expiry = expire;
 
-	ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+	ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
 
 	res = 0;
 
@@ -6764,7 +6764,7 @@
 	if (!ast_test_flag(peer, IAX_TEMPONLY))
 		ast_db_del("IAX/Registry", peer->name);
 	register_peer_exten(peer, 0);
-	ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+	ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
 	if (iax2_regfunk)
 		iax2_regfunk(peer->name, 0);
 
@@ -6814,7 +6814,7 @@
  							peer_unref(p);
  						}
  					}
-  					ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+  					ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
  					p->expire = iax2_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, peer_ref(p));
  					if (p->expire == -1)
  						peer_unref(p);
@@ -6881,14 +6881,14 @@
 					    ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
 			manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);
 			register_peer_exten(p, 1);
-			ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+			ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
 		} else if (!ast_test_flag(p, IAX_TEMPONLY)) {
 			ast_verb(3, "Unregistered IAX2 '%s' (%s)\n", p->name,
 					    ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
 			manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\n", p->name);
 			register_peer_exten(p, 0);
 			ast_db_del("IAX/Registry", p->name);
-			ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+			ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", p->name); /* Activate notification */
 		}
 		/* Update the host */
 		/* Verify that the host is really there */
@@ -8816,13 +8816,13 @@
 						if (iaxs[fr->callno]->pingtime <= peer->maxms) {
 							ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! Time: %d\n", peer->name, iaxs[fr->callno]->pingtime);
 							manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime); 
-							ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+							ast_devstate_changed(AST_DEVICE_NOT_INUSE, "IAX2/%s", peer->name); /* Activate notification */
 						}
 					} else if ((peer->historicms > 0) && (peer->historicms <= peer->maxms)) {
 						if (iaxs[fr->callno]->pingtime > peer->maxms) {
 							ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED (%d ms)!\n", peer->name, iaxs[fr->callno]->pingtime);
 							manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime); 
-							ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+							ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
 						}
 					}
 					peer->lastms = iaxs[fr->callno]->pingtime;
@@ -9863,7 +9863,7 @@
 	if (peer->lastms > -1) {
 		ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Time: %d\n", peer->name, peer->lastms);
 		manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, peer->lastms);
-		ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+		ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
 	}
 	if ((callno = peer->callno) > 0) {
 		ast_mutex_lock(&iaxsl[callno]);

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Fri Jul 25 16:20:03 2008
@@ -4691,7 +4691,7 @@
 		ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
 	}
 	if (p) {
-		ast_device_state_changed("SIP/%s", p->name);
+		ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->name);
 		unref_peer(p, "update_call_counter: unref_peer from call counter");
 	} 
 	return 0;
@@ -10035,7 +10035,7 @@
 	
 	manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
 	register_peer_exten(peer, FALSE);	/* Remove regexten */
-	ast_device_state_changed("SIP/%s", peer->name);
+	ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
 
 	/* Do we need to release this peer from memory? 
 		Only for realtime peers and autocreated peers
@@ -10660,7 +10660,7 @@
 	ast_atomic_fetchadd_int(&peer->onHold, (hold ? +1 : -1));
 
 	/* Request device state update */
-	ast_device_state_changed("SIP/%s", peer->name);
+	ast_devstate_changed(hold ? AST_DEVICE_ONHOLD : AST_DEVICE_INUSE, "SIP/%s", peer->name);
 	unref_peer(peer, "sip_peer_hold: from find_peer operation");
 	
 	return;
@@ -10911,7 +10911,7 @@
 		}
 	}
 	if (!res) {
-		ast_device_state_changed("SIP/%s", peer->name);
+		ast_devstate_changed(AST_DEVICE_NOT_INUSE, "SIP/%s", peer->name);
 	}
 	if (res < 0) {
 		switch (res) {
@@ -15708,7 +15708,7 @@
 
 		ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n",
 			peer->name, s, pingtime, peer->maxms);
-		ast_device_state_changed("SIP/%s", peer->name);
+		ast_devstate_changed(is_reachable ? AST_DEVICE_NOT_INUSE : AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
 		manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
 			"ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n",
 			peer->name, s, pingtime);
@@ -19869,7 +19869,7 @@
 	}
 	
 	peer->lastms = -1;
-	ast_device_state_changed("SIP/%s", peer->name);
+	ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
 	/* Try again quickly */
 	AST_SCHED_REPLACE(peer->pokeexpire, sched, 
 		DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);

Modified: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Fri Jul 25 16:20:03 2008
@@ -1786,7 +1786,7 @@
 			}
 			AST_LIST_TRAVERSE(&d->lines, l, list) {
 				register_exten(l);
-				ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 			}
 			break;
 		}
@@ -1816,7 +1816,7 @@
 		}
 		AST_LIST_TRAVERSE(&d->lines, l, list) {
 			unregister_exten(l);
-			ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+			ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Skinny/%s@%s", l->name, d->name);
 		}
 	}
 
@@ -4623,8 +4623,6 @@
 
 		l->hookstate = SKINNY_OFFHOOK;
 
-		ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
-
 		if (sub && sub->outgoing) {
 			/* We're answering a ringing call */
 			ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
@@ -4665,7 +4663,7 @@
 			ast_verb(1, "RECEIVED UNKNOWN STIMULUS:  %d(%d/%d)\n", event, instance, callreference);
 		break;
 	}
-	ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+	ast_devstate_changed(AST_DEVICE_UNKNOWN, "Skinny/%s@%s", l->name, d->name);
 
 	return 1;
 }
@@ -4715,7 +4713,7 @@
 	transmit_ringer_mode(s, SKINNY_RING_OFF);
 	l->hookstate = SKINNY_OFFHOOK;
 
-	ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+	ast_devstate_changed(AST_DEVICE_INUSE, "Skinny/%s@%s", l->name, d->name);
 
 	if (sub && sub->onhold) {
 		return 1;
@@ -4787,7 +4785,7 @@
 		return 0;
 	}
 
-	ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+	ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 
 	if (sub->onhold) {
 		return 0;
@@ -5316,7 +5314,7 @@
 		return 0;
 	}
 
-	ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+	ast_devstate_changed(AST_DEVICE_INUSE, "Skinny/%s@%s", l->name, d->name);
 
 	switch(event) {
 	case SOFTKEY_NONE:
@@ -5517,6 +5515,7 @@
 			}
 
 			transmit_callstate(s, l->instance, l->hookstate, sub->callid);
+			ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 			if (skinnydebug)
 				ast_verb(1, "Skinny %s@%s went on hook\n", l->name, d->name);
 			if (l->transfer && sub->xferor && sub->owner->_state >= AST_STATE_RING) {
@@ -5541,6 +5540,7 @@
 			}
 			if ((l->hookstate == SKINNY_ONHOOK) && (AST_LIST_NEXT(sub, list) && !AST_LIST_NEXT(sub, list)->rtp)) {
 				do_housekeeping(s);
+				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 			}
 		}
 		break;
@@ -5633,7 +5633,6 @@
 			ast_verb(1, "Received unknown Softkey Event: %d(%d/%d)\n", event, instance, callreference);
 		break;
 	}
-	ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
 
 	return 1;
 }

Modified: trunk/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/devicestate.h?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/include/asterisk/devicestate.h (original)
+++ trunk/include/asterisk/devicestate.h Fri Jul 25 16:20:03 2008
@@ -61,6 +61,13 @@
 /*! \brief Devicestate provider call back */
 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
 
+/*!
+ * \brief Convert channel state to devicestate
+ *
+ * \param chanstate Current channel state
+ */
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate);
+
 /*! 
  * \brief Convert device state to text string for output 
  *
@@ -158,7 +165,7 @@
  * \note This is deprecated in favor of ast_devstate_changed()
  */
 int ast_device_state_changed(const char *fmt, ...)
-	__attribute__ ((format (printf, 1, 2)));
+	__attribute__ ((deprecated,format (printf, 1, 2)));
 
 /*! 
  * \brief Tells Asterisk the State for Device is changed 
@@ -173,7 +180,8 @@
  *
  * \note This is deprecated in favor of ast_devstate_changed_literal()
  */
-int ast_device_state_changed_literal(const char *device);
+int ast_device_state_changed_literal(const char *device)
+	__attribute__ ((deprecated));
 
 /*! 
  * \brief Add device state provider 

Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Fri Jul 25 16:20:03 2008
@@ -1364,7 +1364,7 @@
 	ast_free(chan);
 	AST_RWLIST_UNLOCK(&channels);
 
-	ast_device_state_changed_literal(name);
+	ast_devstate_changed_literal(AST_DEVICE_NOT_INUSE, name);
 }
 
 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
@@ -4100,7 +4100,7 @@
 	}
 
 	chan->_state = state;
-	ast_device_state_changed_literal(name);
+	ast_devstate_changed_literal(ast_state_chan2dev(state), name);
 	/* setstate used to conditionally report Newchannel; this is no more */
 	manager_event(EVENT_FLAG_CALL,
 		      "Newstate",

Modified: trunk/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/devicestate.c?view=diff&rev=133860&r1=133859&r2=133860
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Fri Jul 25 16:20:03 2008
@@ -140,6 +140,24 @@
 	/* 8 AST_DEVICE_ONHOLD */	"On Hold"	/*!< On Hold */
 };
 
+/*!\brief Mapping for channel states to device states */
+static const struct chan2dev {
+	enum ast_channel_state chan;
+	enum ast_device_state dev;
+} chan2dev[] = {
+	{ AST_STATE_DOWN,            AST_DEVICE_NOT_INUSE },
+	{ AST_STATE_RESERVED,        AST_DEVICE_INUSE },
+	{ AST_STATE_OFFHOOK,         AST_DEVICE_INUSE },
+	{ AST_STATE_DIALING,         AST_DEVICE_INUSE },
+	{ AST_STATE_RING,            AST_DEVICE_INUSE },
+	{ AST_STATE_RINGING,         AST_DEVICE_RINGING },
+	{ AST_STATE_UP,              AST_DEVICE_INUSE },
+	{ AST_STATE_BUSY,            AST_DEVICE_BUSY },
+	{ AST_STATE_DIALING_OFFHOOK, AST_DEVICE_INUSE },
+	{ AST_STATE_PRERING,         AST_DEVICE_RINGING },
+	{ -100,                      -100 },
+};
+
 /*! \brief  A device state provider (not a channel) */
 struct devstate_prov {
 	char label[40];
@@ -200,6 +218,18 @@
 const char *devstate2str(enum ast_device_state devstate) 
 {
 	return devstatestring[devstate];
+}
+
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
+{
+	int i;
+	chanstate &= 0xFFFF;
+	for (i = 0; chan2dev[i].chan != -100; i++) {
+		if (chan2dev[i].chan == chanstate) {
+			return chan2dev[i].dev;
+		}
+	}
+	return AST_DEVICE_UNKNOWN;
 }
 
 const char *ast_devstate_str(enum ast_device_state state)




More information about the asterisk-commits mailing list