mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-08 10:58:15 +00:00
Version 0.1.8 from FTP
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@312 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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
|
||||
ring the phone and wait for someone to answer */
|
||||
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);
|
||||
ast->state = AST_STATE_RINGING;
|
||||
return 0;
|
||||
@@ -187,11 +187,11 @@ static int phone_hangup(struct ast_channel *ast)
|
||||
p->dialtone = 0;
|
||||
memset(p->ext, 0, sizeof(p->ext));
|
||||
((struct phone_pvt *)(ast->pvt->pvt))->owner = NULL;
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt--;
|
||||
if (usecnt < 0)
|
||||
ast_log(LOG_WARNING, "Usecnt < 0???\n");
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
if (option_verbose > 2)
|
||||
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) {
|
||||
snprintf(tmp->name, sizeof(tmp->name), "Phone/%s", i->dev + 5);
|
||||
tmp->type = type;
|
||||
tmp->fd = i->fd;
|
||||
tmp->fds[0] = i->fd;
|
||||
/* XXX Switching formats silently causes kernel panics XXX */
|
||||
tmp->nativeformats = prefformat;
|
||||
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))
|
||||
strncpy(tmp->language, i->language, sizeof(tmp->language));
|
||||
i->owner = tmp;
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt++;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
if (state != AST_STATE_DOWN) {
|
||||
if (state == AST_STATE_RING) {
|
||||
ioctl(tmp->fd, PHONE_RINGBACK);
|
||||
ioctl(tmp->fds[0], PHONE_RINGBACK);
|
||||
}
|
||||
if (ast_pbx_start(tmp)) {
|
||||
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);
|
||||
/* No need to restart monitor, we are the monitor */
|
||||
if (i->owner) {
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt--;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
}
|
||||
} 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... */
|
||||
phone_new(i, AST_STATE_RING, "default");
|
||||
if (i->owner) {
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt--;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
}
|
||||
/* 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) {
|
||||
phone_new(i, AST_STATE_RING, i->context);
|
||||
} else if (i->mode == MODE_DIALTONE) {
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt++;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
/* Reset the extension */
|
||||
i->ext[0] = '\0';
|
||||
@@ -659,9 +659,9 @@ static void phone_check_exception(struct phone_pvt *i)
|
||||
}
|
||||
} else {
|
||||
if (i->dialtone) {
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
usecnt--;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_update_use_count();
|
||||
}
|
||||
memset(i->ext, 0, sizeof(i->ext));
|
||||
@@ -701,14 +701,14 @@ static void *do_monitor(void *data)
|
||||
for(;;) {
|
||||
/* 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. */
|
||||
if (pthread_mutex_lock(&monlock)) {
|
||||
if (ast_pthread_mutex_lock(&monlock)) {
|
||||
ast_log(LOG_ERROR, "Unable to grab monitor lock\n");
|
||||
return NULL;
|
||||
}
|
||||
/* 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");
|
||||
pthread_mutex_unlock(&monlock);
|
||||
ast_pthread_mutex_unlock(&monlock);
|
||||
return NULL;
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
/* 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 */
|
||||
pthread_mutex_unlock(&monlock);
|
||||
ast_pthread_mutex_unlock(&monlock);
|
||||
/* Wait indefinitely for something to happen */
|
||||
if (dotone) {
|
||||
/* If we're ready to recycle the time, set it to 30 ms */
|
||||
@@ -774,7 +774,7 @@ static void *do_monitor(void *data)
|
||||
continue;
|
||||
/* Alright, lock the interface list again, and let's look and see what has
|
||||
happened */
|
||||
if (pthread_mutex_lock(&iflock)) {
|
||||
if (ast_pthread_mutex_lock(&iflock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock the interface list\n");
|
||||
continue;
|
||||
}
|
||||
@@ -796,7 +796,7 @@ static void *do_monitor(void *data)
|
||||
}
|
||||
i=i->next;
|
||||
}
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
}
|
||||
/* Never reached */
|
||||
return NULL;
|
||||
@@ -808,12 +808,12 @@ static int restart_monitor()
|
||||
/* If we're supposed to be stopped -- stay stopped */
|
||||
if (monitor_thread == -2)
|
||||
return 0;
|
||||
if (pthread_mutex_lock(&monlock)) {
|
||||
if (ast_pthread_mutex_lock(&monlock)) {
|
||||
ast_log(LOG_WARNING, "Unable to lock monitor\n");
|
||||
return -1;
|
||||
}
|
||||
if (monitor_thread == pthread_self()) {
|
||||
pthread_mutex_unlock(&monlock);
|
||||
ast_pthread_mutex_unlock(&monlock);
|
||||
ast_log(LOG_WARNING, "Cannot kill myself\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -825,11 +825,11 @@ static int restart_monitor()
|
||||
}
|
||||
/* Start a new monitor */
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
pthread_mutex_unlock(&monlock);
|
||||
ast_pthread_mutex_unlock(&monlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -900,7 +900,7 @@ static struct ast_channel *phone_request(char *type, int format, void *data)
|
||||
return NULL;
|
||||
}
|
||||
/* 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");
|
||||
return NULL;
|
||||
}
|
||||
@@ -914,7 +914,7 @@ static struct ast_channel *phone_request(char *type, int format, void *data)
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
restart_monitor();
|
||||
return tmp;
|
||||
}
|
||||
@@ -932,7 +932,7 @@ int load_module()
|
||||
ast_log(LOG_ERROR, "Unable to load config %s\n", config);
|
||||
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 */
|
||||
ast_log(LOG_ERROR, "Unable to lock interface list???\n");
|
||||
return -1;
|
||||
@@ -949,7 +949,7 @@ int load_module()
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value);
|
||||
ast_destroy(cfg);
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
unload_module();
|
||||
return -1;
|
||||
}
|
||||
@@ -973,7 +973,9 @@ int load_module()
|
||||
prefformat = AST_FORMAT_G723_1;
|
||||
} else if (!strcasecmp(v->value, "slinear")) {
|
||||
prefformat = AST_FORMAT_SLINEAR;
|
||||
} else
|
||||
} else if (!strcasecmp(v->value, "ulaw")) {
|
||||
prefformat = AST_FORMAT_ULAW;
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value);
|
||||
} else if (!strcasecmp(v->name, "echocancel")) {
|
||||
if (!strcasecmp(v->value, "off")) {
|
||||
@@ -989,7 +991,7 @@ int load_module()
|
||||
}
|
||||
v = v->next;
|
||||
}
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
/* Make sure we can register our Adtranphone channel type */
|
||||
if (ast_channel_register(type, tdesc, AST_FORMAT_G723_1, phone_request)) {
|
||||
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
|
||||
@@ -1010,7 +1012,7 @@ int unload_module()
|
||||
struct phone_pvt *p, *pl;
|
||||
/* First, take us out of the channel loop */
|
||||
ast_channel_unregister(type);
|
||||
if (!pthread_mutex_lock(&iflock)) {
|
||||
if (!ast_pthread_mutex_lock(&iflock)) {
|
||||
/* Hangup all interfaces if they have an owner */
|
||||
p = iflist;
|
||||
while(p) {
|
||||
@@ -1019,24 +1021,24 @@ int unload_module()
|
||||
p = p->next;
|
||||
}
|
||||
iflist = NULL;
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||
return -1;
|
||||
}
|
||||
if (!pthread_mutex_lock(&monlock)) {
|
||||
if (!ast_pthread_mutex_lock(&monlock)) {
|
||||
if (monitor_thread > -1) {
|
||||
pthread_cancel(monitor_thread);
|
||||
pthread_join(monitor_thread, NULL);
|
||||
}
|
||||
monitor_thread = -2;
|
||||
pthread_mutex_unlock(&monlock);
|
||||
ast_pthread_mutex_unlock(&monlock);
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!pthread_mutex_lock(&iflock)) {
|
||||
if (!ast_pthread_mutex_lock(&iflock)) {
|
||||
/* Destroy all the interfaces and free their memory */
|
||||
p = iflist;
|
||||
while(p) {
|
||||
@@ -1049,7 +1051,7 @@ int unload_module()
|
||||
free(pl);
|
||||
}
|
||||
iflist = NULL;
|
||||
pthread_mutex_unlock(&iflock);
|
||||
ast_pthread_mutex_unlock(&iflock);
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
||||
return -1;
|
||||
@@ -1061,9 +1063,9 @@ int unload_module()
|
||||
int usecount()
|
||||
{
|
||||
int res;
|
||||
pthread_mutex_lock(&usecnt_lock);
|
||||
ast_pthread_mutex_lock(&usecnt_lock);
|
||||
res = usecnt;
|
||||
pthread_mutex_unlock(&usecnt_lock);
|
||||
ast_pthread_mutex_unlock(&usecnt_lock);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user