[asterisk-commits] oej: branch oej/sip-callpickup-1.2 r73663 - in /team/oej/sip-callpickup-1.2: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jul 6 03:53:20 CDT 2007
Author: oej
Date: Fri Jul 6 03:53:20 2007
New Revision: 73663
URL: http://svn.digium.com/view/asterisk?view=rev&rev=73663
Log:
Adding some infrastructure changes to get the channel name that
forces a state change across the extension/devicestate system
*if* we have a channel involved.
Registrations and devicestate changes that have no channel
involved will have no channel information to attach.
Modified:
team/oej/sip-callpickup-1.2/channel.c
team/oej/sip-callpickup-1.2/devicestate.c
team/oej/sip-callpickup-1.2/include/asterisk/devicestate.h
Modified: team/oej/sip-callpickup-1.2/channel.c
URL: http://svn.digium.com/view/asterisk/team/oej/sip-callpickup-1.2/channel.c?view=diff&rev=73663&r1=73662&r2=73663
==============================================================================
--- team/oej/sip-callpickup-1.2/channel.c (original)
+++ team/oej/sip-callpickup-1.2/channel.c Fri Jul 6 03:53:20 2007
@@ -972,7 +972,7 @@
free(chan);
ast_mutex_unlock(&chlock);
- ast_device_state_changed_literal(name);
+ ast_device_state_changed_literal(name, name);
}
int ast_channel_spy_add(struct ast_channel *chan, struct ast_channel_spy *spy)
@@ -3275,7 +3275,7 @@
return 0;
chan->_state = state;
- ast_device_state_changed_literal(chan->name);
+ ast_device_state_changed_literal(chan->name, chan->name);
manager_event(EVENT_FLAG_CALL,
(oldstate == AST_STATE_DOWN && !ast_test_flag(chan, AST_FLAG_NOTNEW)) ? "Newchannel" : "Newstate",
"Channel: %s\r\n"
Modified: team/oej/sip-callpickup-1.2/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/oej/sip-callpickup-1.2/devicestate.c?view=diff&rev=73663&r1=73662&r2=73663
==============================================================================
--- team/oej/sip-callpickup-1.2/devicestate.c (original)
+++ team/oej/sip-callpickup-1.2/devicestate.c Fri Jul 6 03:53:20 2007
@@ -63,6 +63,7 @@
struct state_change {
AST_LIST_ENTRY(state_change) list;
char device[1];
+ char channel[1];
};
static AST_LIST_HEAD_STATIC(state_changes, state_change);
@@ -177,24 +178,24 @@
}
/*--- do_state_change: Notify callback watchers of change, and notify PBX core for hint updates */
-static void do_state_change(const char *device)
+static void do_state_change(const char *device, const char *channel)
{
int state;
struct devstate_cb *devcb;
state = ast_device_state(device);
if (option_debug > 2)
- ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state));
+ ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s) - channel involved %s \n", device, state, devstate2str(state), channel ? channel : "<none>");
AST_LIST_LOCK(&devstate_cbs);
AST_LIST_TRAVERSE(&devstate_cbs, devcb, list)
- devcb->callback(device, state, devcb->data);
+ devcb->callback(device, state, devcb->data, channel);
AST_LIST_UNLOCK(&devstate_cbs);
ast_hint_state_changed(device);
}
-static int __ast_device_state_changed_literal(char *buf)
+static int __ast_device_state_changed_literal(char *buf, const char *channel)
{
char *device;
struct state_change *change = NULL;
@@ -205,17 +206,20 @@
tmp = strrchr(device, '-');
if (tmp)
*tmp = '\0';
+ ast_log(LOG_DEBUG, "=== Device state change for %s (channel %s)\n", device, channel ? channel : "<none>");
if (change_thread != AST_PTHREADT_NULL)
- change = calloc(1, sizeof(*change) + strlen(device));
+ change = calloc(1, sizeof(*change) + strlen(device) + strlen(channel));
if (!change) {
/* we could not allocate a change struct, or */
/* there is no background thread, so process the change now */
- do_state_change(device);
+ do_state_change(device, channel);
} else {
/* queue the change */
strcpy(change->device, device);
+ if (change->channel)
+ strcpy(change->channel, channel);
AST_LIST_LOCK(&state_changes);
AST_LIST_INSERT_TAIL(&state_changes, change, list);
if (AST_LIST_FIRST(&state_changes) == change)
@@ -227,11 +231,11 @@
return 1;
}
-int ast_device_state_changed_literal(const char *dev)
+int ast_device_state_changed_literal(const char *dev, const char *channel)
{
char *buf;
buf = ast_strdupa(dev);
- return __ast_device_state_changed_literal(buf);
+ return __ast_device_state_changed_literal(buf, channel);
}
/*--- ast_device_state_changed: Accept change notification, add it to change queue */
@@ -243,7 +247,7 @@
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- return __ast_device_state_changed_literal(buf);
+ return __ast_device_state_changed_literal(buf, NULL);
}
/*--- do_devstate_changes: Go through the dev state change queue and update changes in the dev state thread */
@@ -258,7 +262,7 @@
if (cur) {
/* we got an entry, so unlock the list while we process it */
AST_LIST_UNLOCK(&state_changes);
- do_state_change(cur->device);
+ do_state_change(cur->device, cur->channel);
free(cur);
AST_LIST_LOCK(&state_changes);
} else {
Modified: team/oej/sip-callpickup-1.2/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/team/oej/sip-callpickup-1.2/include/asterisk/devicestate.h?view=diff&rev=73663&r1=73662&r2=73663
==============================================================================
--- team/oej/sip-callpickup-1.2/include/asterisk/devicestate.h (original)
+++ team/oej/sip-callpickup-1.2/include/asterisk/devicestate.h Fri Jul 6 03:53:20 2007
@@ -42,7 +42,7 @@
/*! Device is ringing */
#define AST_DEVICE_RINGING 6
-typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data);
+typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data, const char *channelname);
/*! \brief Convert device state to text string for output
* \param devstate Current device state
@@ -79,12 +79,15 @@
/*! \brief Tells Asterisk the State for Device is changed
- * \param device devicename like a dialstrin
+ * \param device devicename like a dialstring
* Asterisk polls the new extensionstates and calls the registered
* callbacks for the changed extensions
+ * Either give a device name or a channel name. Channel names will be split
+ * on "-" for non-zap channels to find the device, but also used for notification
+ * on channel-related events.
* Returns 0 on success, -1 on failure
*/
-int ast_device_state_changed_literal(const char *device);
+int ast_device_state_changed_literal(const char *device, const char *channel);
/*! \brief Registers a device state change callback
* \param callback Callback
More information about the asterisk-commits
mailing list