[asterisk-commits] file: branch file/stasis_peerevent r390468 - in /team/file/stasis_peerevent: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 5 07:21:53 CDT 2013
Author: file
Date: Wed Jun 5 07:21:50 2013
New Revision: 390468
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390468
Log:
Add some devicestate support for chan_pjsip, but it currently runs into a caching problem with stasis.
Modified:
team/file/stasis_peerevent/channels/chan_gulp.c
team/file/stasis_peerevent/include/asterisk/res_sip.h
team/file/stasis_peerevent/res/res_sip.c
team/file/stasis_peerevent/res/res_sip/sip_configuration.c
Modified: team/file/stasis_peerevent/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_gulp.c?view=diff&rev=390468&r1=390467&r2=390468
==============================================================================
--- team/file/stasis_peerevent/channels/chan_gulp.c (original)
+++ team/file/stasis_peerevent/channels/chan_gulp.c Wed Jun 5 07:21:50 2013
@@ -53,6 +53,8 @@
#include "asterisk/musiconhold.h"
#include "asterisk/causes.h"
#include "asterisk/taskprocessor.h"
+#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_channels.h"
#include "asterisk/res_sip.h"
#include "asterisk/res_sip_session.h"
@@ -82,6 +84,8 @@
static const char desc[] = "Gulp SIP Channel";
static const char channel_type[] = "Gulp";
+static unsigned int chan_idx;
+
/*!
* \brief Positions of various media
*/
@@ -125,6 +129,7 @@
static int gulp_write(struct ast_channel *ast, struct ast_frame *f);
static int gulp_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
static int gulp_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
+static int gulp_devicestate(const char *data);
/*! \brief PBX interface structure for channel registration */
static struct ast_channel_tech gulp_tech = {
@@ -144,6 +149,7 @@
.exception = gulp_read,
.indicate = gulp_indicate,
.fixup = gulp_fixup,
+ .devicestate = gulp_devicestate,
.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER
};
@@ -422,8 +428,8 @@
return NULL;
}
- if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), "", "", "", linkedid, 0, "Gulp/%s-%.*s", ast_sorcery_object_get_id(session->endpoint),
- (int)session->inv_session->dlg->call_id->id.slen, session->inv_session->dlg->call_id->id.ptr))) {
+ if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), "", "", "", linkedid, 0, "Gulp/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
+ ast_atomic_fetchadd_int((int *)&chan_idx, +1)))) {
ao2_cleanup(pvt);
return NULL;
}
@@ -623,6 +629,65 @@
}
return 0;
+}
+
+/*! \brief Function called to get the device state of an endpoint */
+static int gulp_devicestate(const char *data)
+{
+ RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", data), ao2_cleanup);
+ enum ast_device_state state = AST_DEVICE_UNKNOWN;
+ RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
+
+ if (!endpoint) {
+ return AST_DEVICE_INVALID;
+ }
+
+ endpoint_snapshot = ast_endpoint_latest_snapshot(ast_endpoint_get_tech(endpoint->persistent), ast_endpoint_get_resource(endpoint->persistent));
+
+ if (endpoint_snapshot->state == AST_ENDPOINT_OFFLINE) {
+ state = AST_DEVICE_UNAVAILABLE;
+ } else if (endpoint_snapshot->state == AST_ENDPOINT_ONLINE) {
+ state = AST_DEVICE_NOT_INUSE;
+ }
+
+ if (endpoint_snapshot->num_channels && (caching_topic = ast_channel_topic_all_cached())) {
+ struct ast_devstate_aggregate aggregate;
+ int num, inuse = 0;
+
+ ast_devstate_aggregate_init(&aggregate);
+
+ ao2_ref(caching_topic, +1);
+
+ for (num = 0; num < endpoint_snapshot->num_channels; num++) {
+ RAII_VAR(struct stasis_message *, msg, stasis_cache_get(caching_topic, ast_channel_snapshot_type(), endpoint_snapshot->channel_ids[num]), ao2_cleanup);
+ struct ast_channel_snapshot *snapshot;
+
+ if (!msg) {
+ continue;
+ }
+
+ snapshot = stasis_message_data(msg);
+
+ if (snapshot->state == AST_STATE_DOWN) {
+ ast_devstate_aggregate_add(&aggregate, AST_DEVICE_NOT_INUSE);
+ } else if (snapshot->state == AST_STATE_RINGING) {
+ ast_devstate_aggregate_add(&aggregate, AST_DEVICE_RINGING);
+ } else if ((snapshot->state == AST_STATE_UP) || (snapshot->state == AST_STATE_RING) ||
+ (snapshot->state == AST_STATE_BUSY)) {
+ ast_devstate_aggregate_add(&aggregate, AST_DEVICE_INUSE);
+ inuse++;
+ }
+ }
+
+ if (endpoint->devicestate_busy_at && (inuse == endpoint->devicestate_busy_at)) {
+ state = AST_DEVICE_BUSY;
+ } else {
+ state = ast_devstate_aggregate_result(&aggregate);
+ }
+ }
+
+ return state;
}
struct indicate_data {
Modified: team/file/stasis_peerevent/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/include/asterisk/res_sip.h?view=diff&rev=390468&r1=390467&r2=390468
==============================================================================
--- team/file/stasis_peerevent/include/asterisk/res_sip.h (original)
+++ team/file/stasis_peerevent/include/asterisk/res_sip.h Wed Jun 5 07:21:50 2013
@@ -330,6 +330,8 @@
unsigned int aggregate_mwi;
/*! Pointer to the persistent Asterisk endpoint */
struct ast_endpoint *persistent;
+ /*! The number of channels at which busy device state is returned */
+ unsigned int devicestate_busy_at;
};
/*!
Modified: team/file/stasis_peerevent/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/res/res_sip.c?view=diff&rev=390468&r1=390467&r2=390468
==============================================================================
--- team/file/stasis_peerevent/res/res_sip.c (original)
+++ team/file/stasis_peerevent/res/res_sip.c Wed Jun 5 07:21:50 2013
@@ -298,6 +298,13 @@
<configOption name="use_ptime" default="no">
<synopsis>Use Endpoint's requested packetisation interval</synopsis>
</configOption>
+ <configOption name="devicestate_busy_at" default="0">
+ <synopsis>The number of in-use channels which will cause busy to be returned as device state</synopsis>
+ <description><para>
+ When the number of in-use channels for the endpoint matches the devicestate_busy_at setting the
+ Gulp channel driver will return busy as the device state instead of in use.
+ </para></description>
+ </configOption>
</configObject>
<configObject name="auth">
<synopsis>Authentication type</synopsis>
Modified: team/file/stasis_peerevent/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/res/res_sip/sip_configuration.c?view=diff&rev=390468&r1=390467&r2=390468
==============================================================================
--- team/file/stasis_peerevent/res/res_sip/sip_configuration.c (original)
+++ team/file/stasis_peerevent/res/res_sip/sip_configuration.c Wed Jun 5 07:21:50 2013
@@ -75,6 +75,8 @@
}
ast_endpoint_blob_publish(persistent->endpoint, ast_endpoint_state_type(), blob);
+
+ ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "Gulp/%s", ast_endpoint_get_resource(persistent->endpoint));
return 0;
}
@@ -481,6 +483,7 @@
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_rpid", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_rpid));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, mailboxes));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, aggregate_mwi));
+ ast_sorcery_object_field_register(sip_sorcery, "endpoint", "devicestate_busy_at", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_endpoint, devicestate_busy_at));
if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
More information about the asterisk-commits
mailing list