[asterisk-commits] moy: branch moy/mfcr2 r157229 - /team/moy/mfcr2/channels/chan_dahdi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Nov 15 21:33:19 CST 2008
Author: moy
Date: Sat Nov 15 21:33:18 2008
New Revision: 157229
URL: http://svn.digium.com/view/asterisk?view=rev&rev=157229
Log:
refactoring of r2context creation
Modified:
team/moy/mfcr2/channels/chan_dahdi.c
Modified: team/moy/mfcr2/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2/channels/chan_dahdi.c?view=diff&rev=157229&r1=157228&r2=157229
==============================================================================
--- team/moy/mfcr2/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2/channels/chan_dahdi.c Sat Nov 15 21:33:18 2008
@@ -9009,11 +9009,58 @@
return NULL;
}
r2links = new_r2links;
- new_r2links->r2master = AST_PTHREADT_NULL;
+ new_r2link->r2master = AST_PTHREADT_NULL;
r2links[r2links_index] = new_r2link;
r2links_count++;
}
return r2links[r2links_index];
+}
+
+static int dahdi_r2_set_context(struct dahdi_mfcr2 *r2_link, const struct dahdi_chan_conf *conf)
+{
+ char tmplogdir[] = "/tmp";
+ char logdir[OR2_MAX_PATH];
+ int threshold = 0;
+ int snres = 0;
+ r2_link->protocol_context = openr2_context_new(NULL, &dahdi_r2_event_iface,
+ &dahdi_r2_transcode_iface, conf->mfcr2.variant, conf->mfcr2.max_ani,
+ conf->mfcr2.max_dnis);
+ if (!r2_link->protocol_context) {
+ return -1;
+ }
+ openr2_context_set_log_level(r2_link->protocol_context, conf->mfcr2.loglevel);
+ openr2_context_set_ani_first(r2_link->protocol_context, conf->mfcr2.get_ani_first);
+ openr2_context_set_mf_threshold(r2_link->protocol_context, threshold);
+ openr2_context_set_mf_back_timeout(r2_link->protocol_context, conf->mfcr2.mfback_timeout);
+ openr2_context_set_metering_pulse_timeout(r2_link->protocol_context, conf->mfcr2.metering_pulse_timeout);
+ openr2_context_set_double_answer(r2_link->protocol_context, conf->mfcr2.double_answer);
+ openr2_context_set_immediate_accept(r2_link->protocol_context, conf->mfcr2.immediate_accept);
+ if (ast_strlen_zero(conf->mfcr2.logdir)) {
+ if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
+ ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
+ }
+ } else {
+ snres = snprintf(logdir, sizeof(logdir), "%s/%s/%s", ast_config_AST_LOG_DIR, "mfcr2", conf->mfcr2.logdir);
+ if (snres >= sizeof(logdir)) {
+ ast_log(LOG_ERROR, "MFC/R2 logging directory truncated, using %s\n", tmplogdir);
+ if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
+ ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
+ }
+ } else {
+ if (openr2_context_set_log_directory(r2_link->protocol_context, logdir)) {
+ ast_log(LOG_ERROR, "Failed setting MFC/R2 log directory %s\n", logdir);
+ }
+ }
+ }
+ if (!ast_strlen_zero(conf->mfcr2.r2proto_file)) {
+ if (openr2_context_configure_from_advanced_file(r2_link->protocol_context, conf->mfcr2.r2proto_file)) {
+ ast_log(LOG_ERROR, "Failed to configure r2context from advanced configuration file %s\n", conf->mfcr2.r2proto_file);
+ }
+ }
+ ast_cond_init(&r2_link->do_monitor, NULL);
+ ast_mutex_init(&r2_link->monitored_count_lock);
+ r2_link->monitored_count = 0;
+ return 0;
}
#endif
@@ -9169,82 +9216,47 @@
#endif
#ifdef HAVE_OPENR2
if (chan_sig == SIG_MFCR2 && reloading != 1) {
- char logdir[OR2_MAX_PATH];
struct dahdi_mfcr2 *r2_link;
- int threshold = 0;
- int snres = 0;
r2_link = dahdi_r2_get_link();
if (!r2_link) {
ast_log(LOG_WARNING, "Cannot get another R2 DAHDI context!\n");
- } else if (!r2_link->protocol_context) {
- char tmplogdir[] = "/tmp";
- r2_link->protocol_context = openr2_context_new(NULL, &dahdi_r2_event_iface,
- &dahdi_r2_transcode_iface, conf->mfcr2.variant, conf->mfcr2.max_ani,
- conf->mfcr2.max_dnis);
- if (!r2_link->protocol_context) {
- ast_log(LOG_ERROR, "Cannot create OpenR2 protocol context.\n");
- destroy_dahdi_pvt(&tmp);
- return NULL;
- }
- openr2_context_set_log_level(r2_link->protocol_context, conf->mfcr2.loglevel);
- openr2_context_set_ani_first(r2_link->protocol_context, conf->mfcr2.get_ani_first);
- openr2_context_set_mf_threshold(r2_link->protocol_context, threshold);
- openr2_context_set_mf_back_timeout(r2_link->protocol_context, conf->mfcr2.mfback_timeout);
- openr2_context_set_metering_pulse_timeout(r2_link->protocol_context, conf->mfcr2.metering_pulse_timeout);
- openr2_context_set_double_answer(r2_link->protocol_context, conf->mfcr2.double_answer);
- openr2_context_set_immediate_accept(r2_link->protocol_context, conf->mfcr2.immediate_accept);
- if (ast_strlen_zero(conf->mfcr2.logdir)) {
- if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
- ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
- }
- } else {
- snres = snprintf(logdir, sizeof(logdir), "%s/%s/%s", ast_config_AST_LOG_DIR, "mfcr2", conf->mfcr2.logdir);
- if (snres >= sizeof(logdir)) {
- ast_log(LOG_ERROR, "MFC/R2 logging directory truncated, using %s\n", tmplogdir);
- if (openr2_context_set_log_directory(r2_link->protocol_context, tmplogdir)) {
- ast_log(LOG_ERROR, "Failed setting default MFC/R2 log directory %s\n", tmplogdir);
- }
- } else {
- if (openr2_context_set_log_directory(r2_link->protocol_context, logdir)) {
- ast_log(LOG_ERROR, "Failed setting MFC/R2 log directory %s\n", logdir);
- }
- }
- }
- if (!ast_strlen_zero(conf->mfcr2.r2proto_file)) {
- if (openr2_context_configure_from_advanced_file(r2_link->protocol_context, conf->mfcr2.r2proto_file)) {
- ast_log(LOG_ERROR, "Failed to configure r2context from advanced configuration file %s\n", conf->mfcr2.r2proto_file);
- }
- }
- ast_cond_init(&r2_link->do_monitor, NULL);
- ast_mutex_init(&r2_link->monitored_count_lock);
- r2_link->monitored_count = 0;
+ destroy_dahdi_pvt(&tmp);
+ return NULL;
}
- if (r2_link) {
- /* TODO: should we check numchans overflow, or is it already done by dahdi? */
- r2_link->pvts[r2_link->numchans++] = tmp;
- tmp->r2chan = openr2_chan_new_from_fd(r2_link->protocol_context, tmp->subs[SUB_REAL].dfd,
- NULL, NULL);
- if (!tmp->r2chan) {
- ast_log(LOG_ERROR, "Cannot create OpenR2 channel.\n");
- destroy_dahdi_pvt(&tmp);
- return NULL;
- }
- openr2_chan_set_client_data(tmp->r2chan, tmp);
- openr2_chan_set_logging_func(tmp->r2chan, dahdi_r2_on_chan_log);
- openr2_chan_set_log_level(tmp->r2chan, conf->mfcr2.loglevel);
- if (conf->mfcr2.call_files) {
- openr2_chan_enable_call_files(tmp->r2chan);
- }
- tmp->mfcr2_category = conf->mfcr2.category;
- tmp->mfcr2 = r2_link;
- tmp->mfcr2call = 0;
- tmp->mfcr2_charge_calls = conf->mfcr2.charge_calls;
- tmp->mfcr2_dnis_index = 0;
- tmp->mfcr2_ani_index = 0;
- tmp->mfcr2_allow_collect_calls = conf->mfcr2.allow_collect_calls;
- tmp->mfcr2_forced_release = conf->mfcr2.forced_release;
- r2_link->monitored_count++;
- }
+ if (!r2_link->protocol_context && dahdi_r2_set_context(r2_link, conf)) {
+ ast_log(LOG_ERROR, "Cannot create OpenR2 protocol context.\n");
+ destroy_dahdi_pvt(&tmp);
+ return NULL;
+ }
+ if (r2_link->numchans == (sizeof(r2_link->pvts)/sizeof(r2_link->pvts[0]))) {
+ ast_log(LOG_ERROR, "Cannot add more channels to this link!\n");
+ destroy_dahdi_pvt(&tmp);
+ return NULL;
+ }
+ r2_link->pvts[r2_link->numchans++] = tmp;
+ tmp->r2chan = openr2_chan_new_from_fd(r2_link->protocol_context,
+ tmp->subs[SUB_REAL].dfd,
+ NULL, NULL);
+ if (!tmp->r2chan) {
+ ast_log(LOG_ERROR, "Cannot create OpenR2 channel.\n");
+ destroy_dahdi_pvt(&tmp);
+ return NULL;
+ }
+ tmp->mfcr2 = r2_link;
+ if (conf->mfcr2.call_files) {
+ openr2_chan_enable_call_files(tmp->r2chan);
+ }
+ openr2_chan_set_client_data(tmp->r2chan, tmp);
+ openr2_chan_set_logging_func(tmp->r2chan, dahdi_r2_on_chan_log);
+ openr2_chan_set_log_level(tmp->r2chan, conf->mfcr2.loglevel);
+ tmp->mfcr2_category = conf->mfcr2.category;
+ tmp->mfcr2_charge_calls = conf->mfcr2.charge_calls;
+ tmp->mfcr2_allow_collect_calls = conf->mfcr2.allow_collect_calls;
+ tmp->mfcr2_forced_release = conf->mfcr2.forced_release;
+ tmp->mfcr2call = 0;
+ tmp->mfcr2_dnis_index = 0;
+ tmp->mfcr2_ani_index = 0;
+ r2_link->monitored_count++;
}
#endif
#ifdef HAVE_PRI
More information about the asterisk-commits
mailing list