[asterisk-commits] moy: branch moy/mfcr2-1.4 r218098 - /team/moy/mfcr2-1.4/channels/chan_dahdi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Sep 11 14:46:59 CDT 2009
Author: moy
Date: Fri Sep 11 14:46:55 2009
New Revision: 218098
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=218098
Log:
commited evandro patch to block lines when openr2_chan_set_blocked is called or remote blocking is detected
Modified:
team/moy/mfcr2-1.4/channels/chan_dahdi.c
Modified: team/moy/mfcr2-1.4/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/moy/mfcr2-1.4/channels/chan_dahdi.c?view=diff&rev=218098&r1=218097&r2=218098
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_dahdi.c Fri Sep 11 14:46:55 2009
@@ -304,7 +304,7 @@
#ifdef HAVE_OPENR2
-struct zt_mfcr2 {
+struct dahdi_mfcr2 {
pthread_t master; /*!< Thread of master */
openr2_context_t *protocol_context; /*!< OpenR2 context handle */
struct dahdi_pvt *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
@@ -314,7 +314,7 @@
ast_cond_t do_monitor; /*!< Condition to wake up the monitor thread when there's work to do */
};
-static struct zt_mfcr2 r2links[NUM_SPANS];
+static struct dahdi_mfcr2 r2links[NUM_SPANS];
static openr2_variant_t mfcr2_cur_variant = OR2_VAR_UNKNOWN;
static int mfcr2_cur_mfback_timeout = -1;
static int mfcr2_cur_metering_pulse_timeout = -1;
@@ -922,7 +922,8 @@
#endif
#ifdef HAVE_OPENR2
int mfcr2call;
- struct zt_mfcr2 *mfcr2;
+ int mfcr2block;
+ struct dahdi_mfcr2 *mfcr2;
openr2_chan_t *r2chan;
openr2_calling_party_category_t mfcr2_recvd_category;
openr2_calling_party_category_t mfcr2_category;
@@ -1374,7 +1375,7 @@
ast_mutex_unlock(&p->lock);
}
-static void dahdi_r2_update_monitor_count(struct zt_mfcr2 *mfcr2, int increment)
+static void dahdi_r2_update_monitor_count(struct dahdi_mfcr2 *mfcr2, int increment)
{
ast_mutex_lock(&mfcr2->monitored_count_lock);
if (increment) {
@@ -1629,14 +1630,24 @@
}
}
+#define DAHDI_R2_REMOTE_BLOCK (1 << 0)
+#define DAHDI_R2_LOCAL_BLOCK (1 << 1)
static void dahdi_r2_on_line_blocked(openr2_chan_t *r2chan)
{
- ast_log(LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan));
+ struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_log(LOG_NOTICE, "Far end blocked on chan %d\n", p->channel);
+ ast_mutex_lock(&p->lock);
+ p->mfcr2block |= DAHDI_R2_REMOTE_BLOCK;
+ ast_mutex_unlock(&p->lock);
}
static void dahdi_r2_on_line_idle(openr2_chan_t *r2chan)
{
+ struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
ast_log(LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan));
+ ast_mutex_lock(&p->lock);
+ p->mfcr2block &= ~DAHDI_R2_REMOTE_BLOCK;
+ ast_mutex_unlock(&p->lock);
}
static void dahdi_r2_on_context_log(openr2_context_t *r2context, openr2_log_level_t level, const char *fmt, va_list ap)
@@ -8329,7 +8340,7 @@
}
#ifdef HAVE_OPENR2
-static struct zt_mfcr2 *mfcr2_get_context(int id)
+static struct dahdi_mfcr2 *mfcr2_get_context(int id)
{
if ((id < 0) || (id >= (sizeof(r2links)/sizeof(r2links[0])))) {
ast_log(LOG_ERROR, "No more R2 links available!.\n");
@@ -8688,7 +8699,7 @@
#ifdef HAVE_OPENR2
if (chan_sig == SIG_MFCR2 && reloading != 1) {
char logdir[OR2_MAX_PATH];
- struct zt_mfcr2 *dahdi_r2;
+ struct dahdi_mfcr2 *dahdi_r2;
int threshold = 0;
int snres = 0;
dahdi_r2 = mfcr2_get_context(mfcr2_cur_context_index);
@@ -8759,6 +8770,7 @@
tmp->mfcr2_category = mfcr2_cur_category;
tmp->mfcr2 = dahdi_r2;
tmp->mfcr2call = 0;
+ tmp->mfcr2block = DAHDI_R2_REMOTE_BLOCK | DAHDI_R2_LOCAL_BLOCK;
tmp->mfcr2_accept_on_offer = mfcr2_cur_accept_on_offer;
tmp->mfcr2_charge_calls = mfcr2_cur_charge_calls;
tmp->mfcr2_ani_index = 0;
@@ -9080,7 +9092,7 @@
#ifdef HAVE_OPENR2
/* Trust MFC/R2 */
if (p->mfcr2) {
- if (p->mfcr2call)
+ if (p->mfcr2call || p->mfcr2block)
return 0;
else
return 1;
@@ -9386,7 +9398,12 @@
ast_mutex_lock(&p->lock);
if (p->mfcr2call) {
ast_mutex_unlock(&p->lock);
- ast_log(LOG_DEBUG, "Yay!, someone just beat us in the race for channel %d.\n", p->channel);
+ ast_log(LOG_NOTICE, "Yay!, someone just beat us in the race for channel %d.\n", p->channel);
+ goto next;
+ }
+ if (p->mfcr2block) {
+ ast_mutex_unlock(&p->lock);
+ ast_log(LOG_NOTICE, "Yay!, channel %d just got blocked (%d).\n", p->channel, p->mfcr2block);
goto next;
}
p->mfcr2call = 1;
@@ -9472,7 +9489,8 @@
#ifdef HAVE_OPENR2
static void *mfcr2_monitor(void *data)
{
- struct zt_mfcr2 *mfcr2 = data;
+ struct dahdi_pvt *p;
+ struct dahdi_mfcr2 *mfcr2 = data;
/* we should be using pthread_key_create
and allocate pollers dynamically.
I think do_monitor() could be leaking, since it
@@ -9487,7 +9505,15 @@
/* now that we're ready to get calls, unblock our side and
get current line state */
for (i = 0; i < mfcr2->numchans; i++) {
- openr2_chan_set_idle(mfcr2->pvts[i]->r2chan);
+ p = mfcr2->pvts[i];
+ if (openr2_chan_set_idle(p->r2chan)) {
+ ast_log(LOG_ERROR, "Failed to set channel %d in IDLE\n", p->channel);
+ } else {
+ ast_mutex_lock(&p->lock);
+ mfcr2->pvts[i]->mfcr2block &= ~DAHDI_R2_LOCAL_BLOCK;
+ mfcr2->pvts[i]->mfcr2call = 0;
+ ast_mutex_unlock(&p->lock);
+ }
openr2_chan_handle_cas(mfcr2->pvts[i]->r2chan);
}
while(1) {
@@ -11647,10 +11673,12 @@
p = p->next;
continue;
}
- openr2_chan_set_idle(p->r2chan);
- ast_mutex_lock(&p->lock);
- p->mfcr2call = 0;
- ast_mutex_unlock(&p->lock);
+ if (!openr2_chan_set_idle(p->r2chan)) {
+ ast_mutex_lock(&p->lock);
+ p->mfcr2call = 0;
+ p->mfcr2block &= ~DAHDI_R2_LOCAL_BLOCK;
+ ast_mutex_unlock(&p->lock);
+ }
if (channo != -1) {
break;
} else {
@@ -11680,7 +11708,13 @@
p = p->next;
continue;
}
- openr2_chan_set_blocked(p->r2chan);
+ if (!openr2_chan_set_blocked(p->r2chan)) {
+ ast_mutex_lock(&p->lock);
+ p->mfcr2block |= DAHDI_R2_LOCAL_BLOCK;
+ ast_mutex_unlock(&p->lock);
+ } else {
+ ast_cli(fd, "MFC/R2 channel %d could not be blocked.\n", p->channel);
+ }
if (channo != -1) {
break;
} else {
@@ -12066,6 +12100,8 @@
char calldir[OR2_MAX_PATH];
openr2_context_t *r2context = openr2_chan_get_context(tmp->r2chan);
openr2_variant_t r2variant = openr2_context_get_variant(r2context);
+ ast_cli(fd, "MFC/R2 Call: %s\n", tmp->mfcr2call ? "Yes" : "No");
+ ast_cli(fd, "MFC/R2 Blocked: %s\n", tmp->mfcr2block ? "Yes" : "No");
ast_cli(fd, "MFC/R2 MF State: %s\n", openr2_chan_get_mf_state_string(tmp->r2chan));
ast_cli(fd, "MFC/R2 MF Group: %s\n", openr2_chan_get_mf_group_string(tmp->r2chan));
ast_cli(fd, "MFC/R2 State: %s\n", openr2_chan_get_r2_state_string(tmp->r2chan));
@@ -12089,8 +12125,6 @@
ast_cli(fd, "MFC/R2 MF Tx Signal: %d\n", openr2_chan_get_tx_mf_signal(tmp->r2chan));
ast_cli(fd, "MFC/R2 MF Rx Signal: %d\n", openr2_chan_get_rx_mf_signal(tmp->r2chan));
ast_cli(fd, "MFC/R2 Call Files Directory: %s\n", openr2_context_get_log_directory(r2context, calldir, sizeof(calldir)));
-
-
}
#endif
#ifdef HAVE_PRI
More information about the asterisk-commits
mailing list