add name to spans
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@565 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
056a3ec2ee
commit
cf7125c118
|
@ -1528,6 +1528,7 @@ static switch_status_t load_config(void)
|
||||||
if ((spans = switch_xml_child(cfg, "analog_spans"))) {
|
if ((spans = switch_xml_child(cfg, "analog_spans"))) {
|
||||||
for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) {
|
for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) {
|
||||||
char *id = (char *) switch_xml_attr_soft(myspan, "id");
|
char *id = (char *) switch_xml_attr_soft(myspan, "id");
|
||||||
|
char *name = (char *) switch_xml_attr(myspan, "name");
|
||||||
char *context = "default";
|
char *context = "default";
|
||||||
char *dialplan = "XML";
|
char *dialplan = "XML";
|
||||||
char *tonegroup = NULL;
|
char *tonegroup = NULL;
|
||||||
|
@ -1539,7 +1540,8 @@ static switch_status_t load_config(void)
|
||||||
uint32_t span_id = 0, to = 0, max = 0;
|
uint32_t span_id = 0, to = 0, max = 0;
|
||||||
zap_span_t *span = NULL;
|
zap_span_t *span = NULL;
|
||||||
analog_option_t analog_options = ANALOG_OPTION_NONE;
|
analog_option_t analog_options = ANALOG_OPTION_NONE;
|
||||||
|
zap_status_t zstatus = ZAP_FAIL;
|
||||||
|
|
||||||
for (param = switch_xml_child(myspan, "param"); param; param = param->next) {
|
for (param = switch_xml_child(myspan, "param"); param; param = param->next) {
|
||||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||||
|
@ -1570,7 +1572,7 @@ static switch_status_t load_config(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
span_id = atoi(id);
|
|
||||||
|
|
||||||
if (!tonegroup) {
|
if (!tonegroup) {
|
||||||
tonegroup = "us";
|
tonegroup = "us";
|
||||||
|
@ -1584,10 +1586,27 @@ static switch_status_t load_config(void)
|
||||||
max = atoi(max_digits);
|
max = atoi(max_digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zap_span_find(span_id, &span) != ZAP_SUCCESS) {
|
if (name) {
|
||||||
|
zstatus = zap_span_find_by_name(name, &span);
|
||||||
|
} else {
|
||||||
|
if (switch_is_number(id)) {
|
||||||
|
span_id = atoi(id);
|
||||||
|
zstatus = zap_span_find(span_id, &span);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zstatus != ZAP_SUCCESS) {
|
||||||
|
zstatus = zap_span_find_by_name(id, &span);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zstatus != ZAP_SUCCESS) {
|
||||||
zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id);
|
zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!span_id) {
|
||||||
|
span_id = span->span_id;
|
||||||
|
}
|
||||||
|
|
||||||
if (zap_configure_span("analog", span, on_analog_signal,
|
if (zap_configure_span("analog", span, on_analog_signal,
|
||||||
"tonemap", tonegroup,
|
"tonemap", tonegroup,
|
||||||
|
|
|
@ -466,6 +466,7 @@ struct zap_analog_data {
|
||||||
|
|
||||||
struct zap_span {
|
struct zap_span {
|
||||||
zap_data_type_t data_type;
|
zap_data_type_t data_type;
|
||||||
|
char *name;
|
||||||
uint32_t span_id;
|
uint32_t span_id;
|
||||||
uint32_t chan_count;
|
uint32_t chan_count;
|
||||||
uint32_t active_count;
|
uint32_t active_count;
|
||||||
|
@ -592,6 +593,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c
|
||||||
zap_status_t zap_span_start(zap_span_t *span);
|
zap_status_t zap_span_start(zap_span_t *span);
|
||||||
int zap_load_module(const char *name);
|
int zap_load_module(const char *name);
|
||||||
int zap_load_module_assume(const char *name);
|
int zap_load_module_assume(const char *name);
|
||||||
|
zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span);
|
||||||
|
|
||||||
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
|
ZIO_CODEC_FUNCTION(zio_slin2ulaw);
|
||||||
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
|
ZIO_CODEC_FUNCTION(zio_ulaw2slin);
|
||||||
|
|
|
@ -76,6 +76,7 @@ zap_time_t zap_current_time_in_ms(void)
|
||||||
static struct {
|
static struct {
|
||||||
zap_hash_t *interface_hash;
|
zap_hash_t *interface_hash;
|
||||||
zap_hash_t *module_hash;
|
zap_hash_t *module_hash;
|
||||||
|
zap_hash_t *span_hash;
|
||||||
zap_mutex_t *mutex;
|
zap_mutex_t *mutex;
|
||||||
struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1];
|
struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1];
|
||||||
uint32_t span_index;
|
uint32_t span_index;
|
||||||
|
@ -460,6 +461,19 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
|
||||||
return ZAP_FAIL;
|
return ZAP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span)
|
||||||
|
{
|
||||||
|
zap_status_t status = ZAP_FAIL;
|
||||||
|
|
||||||
|
zap_mutex_lock(globals.mutex);
|
||||||
|
if (!zap_strlen_zero(name) && (*span = hashtable_search(globals.span_hash, (void *)name))) {
|
||||||
|
status = ZAP_SUCCESS;
|
||||||
|
}
|
||||||
|
zap_mutex_unlock(globals.mutex);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
zap_status_t zap_span_find(uint32_t id, zap_span_t **span)
|
zap_status_t zap_span_find(uint32_t id, zap_span_t **span)
|
||||||
{
|
{
|
||||||
zap_span_t *fspan;
|
zap_span_t *fspan;
|
||||||
|
@ -1965,10 +1979,12 @@ static zap_status_t load_config(void)
|
||||||
if (!strncasecmp(cfg.category, "span", 4)) {
|
if (!strncasecmp(cfg.category, "span", 4)) {
|
||||||
if (cfg.catno != catno) {
|
if (cfg.catno != catno) {
|
||||||
char *type = cfg.category + 4;
|
char *type = cfg.category + 4;
|
||||||
|
char *name;
|
||||||
|
|
||||||
if (*type == ' ') {
|
if (*type == ' ') {
|
||||||
type++;
|
type++;
|
||||||
}
|
}
|
||||||
|
|
||||||
zap_log(ZAP_LOG_DEBUG, "found config for span\n");
|
zap_log(ZAP_LOG_DEBUG, "found config for span\n");
|
||||||
catno = cfg.catno;
|
catno = cfg.catno;
|
||||||
|
|
||||||
|
@ -1977,7 +1993,9 @@ static zap_status_t load_config(void)
|
||||||
span = NULL;
|
span = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name = strchr(type, ' ');
|
||||||
|
|
||||||
zap_mutex_lock(globals.mutex);
|
zap_mutex_lock(globals.mutex);
|
||||||
if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) {
|
if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) {
|
||||||
zap_load_module_assume(type);
|
zap_load_module_assume(type);
|
||||||
|
@ -2001,8 +2019,25 @@ static zap_status_t load_config(void)
|
||||||
|
|
||||||
if (zap_span_create(zio, &span) == ZAP_SUCCESS) {
|
if (zap_span_create(zio, &span) == ZAP_SUCCESS) {
|
||||||
span->type = strdup(type);
|
span->type = strdup(type);
|
||||||
zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type);
|
|
||||||
d = 0;
|
d = 0;
|
||||||
|
|
||||||
|
zap_mutex_lock(globals.mutex);
|
||||||
|
if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) {
|
||||||
|
zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", span->span_id);
|
||||||
|
name = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
char buf[128] = "";
|
||||||
|
snprintf(buf, sizeof(buf), "span%d", span->span_id);
|
||||||
|
name = buf;
|
||||||
|
}
|
||||||
|
span->name = strdup(name);
|
||||||
|
hashtable_insert(globals.span_hash, (void *)span->name, span);
|
||||||
|
zap_mutex_unlock(globals.mutex);
|
||||||
|
|
||||||
|
zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type);
|
zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type);
|
||||||
span = NULL;
|
span = NULL;
|
||||||
|
@ -2342,6 +2377,7 @@ zap_status_t zap_global_init(void)
|
||||||
memset(&interfaces, 0, sizeof(interfaces));
|
memset(&interfaces, 0, sizeof(interfaces));
|
||||||
globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
||||||
globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
||||||
|
globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys);
|
||||||
modcount = 0;
|
modcount = 0;
|
||||||
zap_mutex_create(&globals.mutex);
|
zap_mutex_create(&globals.mutex);
|
||||||
|
|
||||||
|
@ -2397,7 +2433,11 @@ zap_status_t zap_global_destroy(void)
|
||||||
zap_safe_free(cur_span->signal_data);
|
zap_safe_free(cur_span->signal_data);
|
||||||
zap_span_destroy(cur_span);
|
zap_span_destroy(cur_span);
|
||||||
}
|
}
|
||||||
|
zap_mutex_lock(globals.mutex);
|
||||||
|
hashtable_remove(globals.span_hash, (void *)cur_span->name);
|
||||||
|
zap_mutex_unlock(globals.mutex);
|
||||||
zap_safe_free(cur_span->type);
|
zap_safe_free(cur_span->type);
|
||||||
|
zap_safe_free(cur_span->name);
|
||||||
free(cur_span);
|
free(cur_span);
|
||||||
cur_span = NULL;
|
cur_span = NULL;
|
||||||
}
|
}
|
||||||
|
@ -2409,6 +2449,7 @@ zap_status_t zap_global_destroy(void)
|
||||||
zap_mutex_lock(globals.mutex);
|
zap_mutex_lock(globals.mutex);
|
||||||
hashtable_destroy(globals.interface_hash, 0, 0);
|
hashtable_destroy(globals.interface_hash, 0, 0);
|
||||||
hashtable_destroy(globals.module_hash, 0, 0);
|
hashtable_destroy(globals.module_hash, 0, 0);
|
||||||
|
hashtable_destroy(globals.span_hash, 0, 0);
|
||||||
zap_mutex_unlock(globals.mutex);
|
zap_mutex_unlock(globals.mutex);
|
||||||
zap_mutex_destroy(&globals.mutex);
|
zap_mutex_destroy(&globals.mutex);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue