Version 0.1.8 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@312 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 25 years ago
parent 3dd98b5a1e
commit 188030b4d9

@ -141,7 +141,7 @@ static int phone_call(struct ast_channel *ast, char *dest, int timeout)
/* When we call, it just works, really, there's no destination... Just /* When we call, it just works, really, there's no destination... Just
ring the phone and wait for someone to answer */ ring the phone and wait for someone to answer */
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fd); ast_log(LOG_DEBUG, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fds[0]);
ioctl(p->fd, PHONE_RING_START); ioctl(p->fd, PHONE_RING_START);
ast->state = AST_STATE_RINGING; ast->state = AST_STATE_RINGING;
return 0; return 0;
@ -187,11 +187,11 @@ static int phone_hangup(struct ast_channel *ast)
p->dialtone = 0; p->dialtone = 0;
memset(p->ext, 0, sizeof(p->ext)); memset(p->ext, 0, sizeof(p->ext));
((struct phone_pvt *)(ast->pvt->pvt))->owner = NULL; ((struct phone_pvt *)(ast->pvt->pvt))->owner = NULL;
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt--; usecnt--;
if (usecnt < 0) if (usecnt < 0)
ast_log(LOG_WARNING, "Usecnt < 0???\n"); ast_log(LOG_WARNING, "Usecnt < 0???\n");
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
@ -534,7 +534,7 @@ static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *conte
if (tmp) { if (tmp) {
snprintf(tmp->name, sizeof(tmp->name), "Phone/%s", i->dev + 5); snprintf(tmp->name, sizeof(tmp->name), "Phone/%s", i->dev + 5);
tmp->type = type; tmp->type = type;
tmp->fd = i->fd; tmp->fds[0] = i->fd;
/* XXX Switching formats silently causes kernel panics XXX */ /* XXX Switching formats silently causes kernel panics XXX */
tmp->nativeformats = prefformat; tmp->nativeformats = prefformat;
tmp->state = state; tmp->state = state;
@ -554,13 +554,13 @@ static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *conte
if (strlen(i->language)) if (strlen(i->language))
strncpy(tmp->language, i->language, sizeof(tmp->language)); strncpy(tmp->language, i->language, sizeof(tmp->language));
i->owner = tmp; i->owner = tmp;
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt++; usecnt++;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
if (state != AST_STATE_DOWN) { if (state != AST_STATE_DOWN) {
if (state == AST_STATE_RING) { if (state == AST_STATE_RING) {
ioctl(tmp->fd, PHONE_RINGBACK); ioctl(tmp->fds[0], PHONE_RINGBACK);
} }
if (ast_pbx_start(tmp)) { if (ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
@ -608,9 +608,9 @@ static void phone_check_exception(struct phone_pvt *i)
phone_new(i, AST_STATE_RING, i->context); phone_new(i, AST_STATE_RING, i->context);
/* No need to restart monitor, we are the monitor */ /* No need to restart monitor, we are the monitor */
if (i->owner) { if (i->owner) {
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt--; usecnt--;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
} }
} else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1)) { } else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1)) {
@ -620,9 +620,9 @@ static void phone_check_exception(struct phone_pvt *i)
/* Check the default, too... */ /* Check the default, too... */
phone_new(i, AST_STATE_RING, "default"); phone_new(i, AST_STATE_RING, "default");
if (i->owner) { if (i->owner) {
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt--; usecnt--;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
} }
/* XXX This should probably be justified better XXX */ /* XXX This should probably be justified better XXX */
@ -644,9 +644,9 @@ static void phone_check_exception(struct phone_pvt *i)
if (i->mode == MODE_IMMEDIATE) { if (i->mode == MODE_IMMEDIATE) {
phone_new(i, AST_STATE_RING, i->context); phone_new(i, AST_STATE_RING, i->context);
} else if (i->mode == MODE_DIALTONE) { } else if (i->mode == MODE_DIALTONE) {
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt++; usecnt++;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
/* Reset the extension */ /* Reset the extension */
i->ext[0] = '\0'; i->ext[0] = '\0';
@ -659,9 +659,9 @@ static void phone_check_exception(struct phone_pvt *i)
} }
} else { } else {
if (i->dialtone) { if (i->dialtone) {
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
usecnt--; usecnt--;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
ast_update_use_count(); ast_update_use_count();
} }
memset(i->ext, 0, sizeof(i->ext)); memset(i->ext, 0, sizeof(i->ext));
@ -701,14 +701,14 @@ static void *do_monitor(void *data)
for(;;) { for(;;) {
/* Don't let anybody kill us right away. Nobody should lock the interface list /* Don't let anybody kill us right away. Nobody should lock the interface list
and wait for the monitor list, but the other way around is okay. */ and wait for the monitor list, but the other way around is okay. */
if (pthread_mutex_lock(&monlock)) { if (ast_pthread_mutex_lock(&monlock)) {
ast_log(LOG_ERROR, "Unable to grab monitor lock\n"); ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
return NULL; return NULL;
} }
/* Lock the interface list */ /* Lock the interface list */
if (pthread_mutex_lock(&iflock)) { if (ast_pthread_mutex_lock(&iflock)) {
ast_log(LOG_ERROR, "Unable to grab interface lock\n"); ast_log(LOG_ERROR, "Unable to grab interface lock\n");
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
return NULL; return NULL;
} }
/* Build the stuff we're going to select on, that is the socket of every /* Build the stuff we're going to select on, that is the socket of every
@ -742,10 +742,10 @@ static void *do_monitor(void *data)
i = i->next; i = i->next;
} }
/* Okay, now that we know what to do, release the interface lock */ /* Okay, now that we know what to do, release the interface lock */
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
/* And from now on, we're okay to be killed, so release the monitor lock as well */ /* And from now on, we're okay to be killed, so release the monitor lock as well */
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
/* Wait indefinitely for something to happen */ /* Wait indefinitely for something to happen */
if (dotone) { if (dotone) {
/* If we're ready to recycle the time, set it to 30 ms */ /* If we're ready to recycle the time, set it to 30 ms */
@ -774,7 +774,7 @@ static void *do_monitor(void *data)
continue; continue;
/* Alright, lock the interface list again, and let's look and see what has /* Alright, lock the interface list again, and let's look and see what has
happened */ happened */
if (pthread_mutex_lock(&iflock)) { if (ast_pthread_mutex_lock(&iflock)) {
ast_log(LOG_WARNING, "Unable to lock the interface list\n"); ast_log(LOG_WARNING, "Unable to lock the interface list\n");
continue; continue;
} }
@ -796,7 +796,7 @@ static void *do_monitor(void *data)
} }
i=i->next; i=i->next;
} }
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
} }
/* Never reached */ /* Never reached */
return NULL; return NULL;
@ -808,12 +808,12 @@ static int restart_monitor()
/* If we're supposed to be stopped -- stay stopped */ /* If we're supposed to be stopped -- stay stopped */
if (monitor_thread == -2) if (monitor_thread == -2)
return 0; return 0;
if (pthread_mutex_lock(&monlock)) { if (ast_pthread_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n"); ast_log(LOG_WARNING, "Unable to lock monitor\n");
return -1; return -1;
} }
if (monitor_thread == pthread_self()) { if (monitor_thread == pthread_self()) {
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
ast_log(LOG_WARNING, "Cannot kill myself\n"); ast_log(LOG_WARNING, "Cannot kill myself\n");
return -1; return -1;
} }
@ -825,11 +825,11 @@ static int restart_monitor()
} }
/* Start a new monitor */ /* Start a new monitor */
if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
return -1; return -1;
} }
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
return 0; return 0;
} }
@ -900,7 +900,7 @@ static struct ast_channel *phone_request(char *type, int format, void *data)
return NULL; return NULL;
} }
/* Search for an unowned channel */ /* Search for an unowned channel */
if (pthread_mutex_lock(&iflock)) { if (ast_pthread_mutex_lock(&iflock)) {
ast_log(LOG_ERROR, "Unable to lock interface list???\n"); ast_log(LOG_ERROR, "Unable to lock interface list???\n");
return NULL; return NULL;
} }
@ -914,7 +914,7 @@ static struct ast_channel *phone_request(char *type, int format, void *data)
} }
p = p->next; p = p->next;
} }
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
restart_monitor(); restart_monitor();
return tmp; return tmp;
} }
@ -932,7 +932,7 @@ int load_module()
ast_log(LOG_ERROR, "Unable to load config %s\n", config); ast_log(LOG_ERROR, "Unable to load config %s\n", config);
return -1; return -1;
} }
if (pthread_mutex_lock(&iflock)) { if (ast_pthread_mutex_lock(&iflock)) {
/* It's a little silly to lock it, but we mind as well just to be sure */ /* It's a little silly to lock it, but we mind as well just to be sure */
ast_log(LOG_ERROR, "Unable to lock interface list???\n"); ast_log(LOG_ERROR, "Unable to lock interface list???\n");
return -1; return -1;
@ -949,7 +949,7 @@ int load_module()
} else { } else {
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
ast_destroy(cfg); ast_destroy(cfg);
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
unload_module(); unload_module();
return -1; return -1;
} }
@ -973,6 +973,8 @@ int load_module()
prefformat = AST_FORMAT_G723_1; prefformat = AST_FORMAT_G723_1;
} else if (!strcasecmp(v->value, "slinear")) { } else if (!strcasecmp(v->value, "slinear")) {
prefformat = AST_FORMAT_SLINEAR; prefformat = AST_FORMAT_SLINEAR;
} else if (!strcasecmp(v->value, "ulaw")) {
prefformat = AST_FORMAT_ULAW;
} else } else
ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value); ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
} else if (!strcasecmp(v->name, "echocancel")) { } else if (!strcasecmp(v->name, "echocancel")) {
@ -989,7 +991,7 @@ int load_module()
} }
v = v->next; v = v->next;
} }
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
/* Make sure we can register our Adtranphone channel type */ /* Make sure we can register our Adtranphone channel type */
if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, phone_request)) { if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, phone_request)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
@ -1010,7 +1012,7 @@ int unload_module()
struct phone_pvt *p, *pl; struct phone_pvt *p, *pl;
/* First, take us out of the channel loop */ /* First, take us out of the channel loop */
ast_channel_unregister(type); ast_channel_unregister(type);
if (!pthread_mutex_lock(&iflock)) { if (!ast_pthread_mutex_lock(&iflock)) {
/* Hangup all interfaces if they have an owner */ /* Hangup all interfaces if they have an owner */
p = iflist; p = iflist;
while(p) { while(p) {
@ -1019,24 +1021,24 @@ int unload_module()
p = p->next; p = p->next;
} }
iflist = NULL; iflist = NULL;
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
} else { } else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n"); ast_log(LOG_WARNING, "Unable to lock the monitor\n");
return -1; return -1;
} }
if (!pthread_mutex_lock(&monlock)) { if (!ast_pthread_mutex_lock(&monlock)) {
if (monitor_thread > -1) { if (monitor_thread > -1) {
pthread_cancel(monitor_thread); pthread_cancel(monitor_thread);
pthread_join(monitor_thread, NULL); pthread_join(monitor_thread, NULL);
} }
monitor_thread = -2; monitor_thread = -2;
pthread_mutex_unlock(&monlock); ast_pthread_mutex_unlock(&monlock);
} else { } else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n"); ast_log(LOG_WARNING, "Unable to lock the monitor\n");
return -1; return -1;
} }
if (!pthread_mutex_lock(&iflock)) { if (!ast_pthread_mutex_lock(&iflock)) {
/* Destroy all the interfaces and free their memory */ /* Destroy all the interfaces and free their memory */
p = iflist; p = iflist;
while(p) { while(p) {
@ -1049,7 +1051,7 @@ int unload_module()
free(pl); free(pl);
} }
iflist = NULL; iflist = NULL;
pthread_mutex_unlock(&iflock); ast_pthread_mutex_unlock(&iflock);
} else { } else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n"); ast_log(LOG_WARNING, "Unable to lock the monitor\n");
return -1; return -1;
@ -1061,9 +1063,9 @@ int unload_module()
int usecount() int usecount()
{ {
int res; int res;
pthread_mutex_lock(&usecnt_lock); ast_pthread_mutex_lock(&usecnt_lock);
res = usecnt; res = usecnt;
pthread_mutex_unlock(&usecnt_lock); ast_pthread_mutex_unlock(&usecnt_lock);
return res; return res;
} }

Loading…
Cancel
Save