#define kSPAN_ID "span"
#define kCHAN_ID "chan"
+#define kSPAN_NAME "span_name"
static struct {
switch_memory_pool_t *pool;
switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
{
const char *szspanid = switch_event_get_header(var_event, kSPAN_ID),
- *szchanid = switch_event_get_header(var_event, kCHAN_ID);
+ *szchanid = switch_event_get_header(var_event, kCHAN_ID),
+ *span_name = switch_event_get_header(var_event, kSPAN_NAME);
int chan_id;
int span_id;
ctdm_private_t *tech_pvt = NULL;
- if (zstr(szchanid) || zstr(szspanid)) {
+ if (zstr(szchanid) || (zstr(szspanid) && zstr(span_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Both ["kSPAN_ID"] and ["kCHAN_ID"] have to be set.\n");
goto fail;
}
chan_id = atoi(szchanid);
span_id = atoi(szspanid);
+
+ if (!span_id) {
+ if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) {
+ span_id = ftdm_span_get_id(span);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n");
+ }
+ }
if (!(*new_session = switch_core_session_request(ctdm.endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, 0, pool))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't request session.\n");
} else if (term->type == MG_TERM_TDM) {
switch_snprintf(dialstring, sizeof dialstring, "tdm/%s", term->name);
- switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kSPAN_ID, "%d", term->u.tdm.span);
+ switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, kSPAN_NAME, term->u.tdm.span_name);
switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kCHAN_ID, "%d", term->u.tdm.channel);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session));
+ switch_set_flag(term, MGT_ACTIVE);
+
done:
if (session) {
switch_core_session_rwunlock(session);
mg_termination_t *term = NULL;
char name[100];
int term_id;
+ size_t prefixlen = strlen(prefix);
/* Check the termination type by prefix */
if (strncasecmp(prefix, profile->rtp_termination_id_prefix, strlen(profile->rtp_termination_id_prefix)) == 0) {
term_id = mg_rtp_request_id(profile);
switch_snprintf(name, sizeof name, "%s/%d", profile->rtp_termination_id_prefix, term_id);
} else {
+ for (term = profile->physical_terminations; term; term = term->next) {
+ if (!strncasecmp(prefix, term->name, prefixlen) && !switch_test_flag(term, MGT_ALLOCATED)) {
+ switch_set_flag(term, MGT_ALLOCATED);
+ return term;
+ }
+ }
- return term;
+ return NULL;
}
switch_core_new_memory_pool(&pool);
term->type = termtype;
term->active_events = NULL;
term->profile = profile;
+ switch_set_flag(term, MGT_ALLOCATED);
if (termtype == MG_TERM_RTP) {
/* Fill in local address and reserve an rtp port */
term->active_events = NULL;
}
+ switch_clear_flag(term, MGT_ALLOCATED);
+ switch_clear_flag(term, MGT_ACTIVE);
+
if (term->type == MG_TERM_RTP) {
switch_core_hash_delete_wrlock(term->profile->terminations, term->name, term->profile->terminations_rwlock);
switch_core_destroy_memory_pool(&term->pool);
//const char *tech = switch_xml_attr(mg_term, "tech");
const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix");
const char *channel_map = switch_xml_attr(mg_term, "channel-map");
- const char *szspan_id = switch_xml_attr(mg_term, "span-id");
- const int span_id = !zstr(szspan_id) ? atoi(szspan_id) : 0;
if (!zstr(channel_map)) {
term->type = MG_TERM_TDM;
term->profile = profile;
term->name = switch_core_sprintf(pool, "%s%d", prefix, j);
- term->u.tdm.span = span_id;
term->u.tdm.channel = j;
+ term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix);
switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock);
+ term->next = profile->physical_terminations;
+ profile->physical_terminations = term;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %d chan: %d\n", term->name, term->u.tdm.span, term->u.tdm.channel);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %s chan: %d\n", term->name, term->u.tdm.span_name, term->u.tdm.channel);
}
}
}
/* TDM parameters understood by the controllable channel */
#define kSPAN_ID "span"
#define kCHAN_ID "chan"
+#define kSPAN_NAME "span_name"
typedef struct mg_termination_s mg_termination_t;
+enum {
+ MGT_ALLOCATED = (1 << 0),
+ MGT_ACTIVE = (1 << 1),
+
+} mg_termination_flags;
+
struct mg_termination_s {
switch_memory_pool_t *pool;
mg_termination_type_t type;
megaco_profile_t *profile; /*!< Parent MG profile */
MgMgcoReqEvtDesc *active_events; /* !< active megaco events */
mg_termination_t *next; /*!< List for physical terminations */
+ uint32_t flags;
union {
struct {
} rtp;
struct {
- int span;
int channel;
+ const char *span_name;
} tdm;
} u;
};
uint8_t rtpid_bitmap[MG_MAX_CONTEXTS/8];
uint32_t rtpid_next;
+
+ mg_termination_t *physical_terminations;
+
switch_hash_t *terminations;
switch_thread_rwlock_t *terminations_rwlock;
};