Apply reverse for future debugging.
modified: chan_lcr.c
modified: select.c
static struct ast_channel_tech lcr_tech;
static struct ast_channel_tech lcr_tech;
-void lock_debug(char *text)
-{
- pthread_t tid = pthread_self();
-// printf("%s|%03x\n", text, ((tid>>6) | (tid>>3) | tid) & 0xfff); fflush(stdout);
- printf(" %s(%x) ", text, (int)tid); fflush(stdout);
-}
-
char ast_text[128] = "NULL";
va_list args;
char ast_text[128] = "NULL";
va_list args;
ast_mutex_lock(&log_lock);
ast_mutex_lock(&log_lock);
va_start(args,fmt);
vsnprintf(buffer,sizeof(buffer)-1,fmt,args);
va_start(args,fmt);
vsnprintf(buffer,sizeof(buffer)-1,fmt,args);
// ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
ast_mutex_unlock(&log_lock);
// ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
ast_mutex_unlock(&log_lock);
if (message_type == MESSAGE_BCHANNEL) {
switch(param->bchannel.type) {
case BCHANNEL_ASSIGN:
if (message_type == MESSAGE_BCHANNEL) {
switch(param->bchannel.type) {
case BCHANNEL_ASSIGN:
CDEBUG(NULL, NULL, "Received BCHANNEL_ASSIGN message. (handle=%08lx) for ref %d\n", param->bchannel.handle, ref);
if ((bchannel = find_bchannel_handle(param->bchannel.handle))) {
CERROR(NULL, NULL, "bchannel handle %x already assigned.\n", (int)param->bchannel.handle);
CDEBUG(NULL, NULL, "Received BCHANNEL_ASSIGN message. (handle=%08lx) for ref %d\n", param->bchannel.handle, ref);
if ((bchannel = find_bchannel_handle(param->bchannel.handle))) {
CERROR(NULL, NULL, "bchannel handle %x already assigned.\n", (int)param->bchannel.handle);
struct admin_list *admin;
struct admin_message msg;
struct admin_list *admin;
struct admin_message msg;
if ((what & LCR_FD_READ)) {
/* read from socket */
if ((what & LCR_FD_READ)) {
/* read from socket */
len = read(lcr_sock, &msg, sizeof(msg));
len = read(lcr_sock, &msg, sizeof(msg));
if (len == 0) {
CERROR(NULL, NULL, "Socket closed.\n");
error:
CERROR(NULL, NULL, "Handling of socket failed - closing for some seconds.\n");
if (len == 0) {
CERROR(NULL, NULL, "Socket closed.\n");
error:
CERROR(NULL, NULL, "Handling of socket failed - closing for some seconds.\n");
schedule_timer(&socket_retry, SOCKET_RETRY_TIMER, 0);
schedule_timer(&socket_retry, SOCKET_RETRY_TIMER, 0);
return 0;
}
if (len > 0) {
return 0;
}
if (len > 0) {
CERROR(NULL, NULL, "Socket received illegal message %d.\n", msg.message);
goto error;
}
CERROR(NULL, NULL, "Socket received illegal message %d.\n", msg.message);
goto error;
}
receive_message(msg.u.msg.type, msg.u.msg.ref, &msg.u.msg.param);
receive_message(msg.u.msg.type, msg.u.msg.ref, &msg.u.msg.param);
} else {
CERROR(NULL, NULL, "Socket failed (errno %d).\n", errno);
goto error;
} else {
CERROR(NULL, NULL, "Socket failed (errno %d).\n", errno);
goto error;
/* write to socket */
if (!admin_first) {
socket_fd.when &= ~LCR_FD_WRITE;
/* write to socket */
if (!admin_first) {
socket_fd.when &= ~LCR_FD_WRITE;
admin = admin_first;
len = write(lcr_sock, &admin->msg, sizeof(msg));
admin = admin_first;
len = write(lcr_sock, &admin->msg, sizeof(msg));
if (len == 0) {
CERROR(NULL, NULL, "Socket closed.\n");
goto error;
if (len == 0) {
CERROR(NULL, NULL, "Socket closed.\n");
goto error;
goto error;
}
/* free head */
goto error;
}
/* free head */
admin_first = admin->next;
free(admin);
global_change = 1;
admin_first = admin->next;
free(admin);
global_change = 1;
read(wake_pipe[0], &byte, 1);
wake_global = 0;
read(wake_pipe[0], &byte, 1);
wake_global = 0;
p = call->queue_string;
ast = call->ast;
if (*p && ast) {
p = call->queue_string;
ast = call->ast;
if (*p && ast) {
if (ast_channel_trylock(ast)) {
if (ast_channel_trylock(ast)) {
- lock_debug("<trylock failed>");
ast_mutex_unlock(&chan_lock);
usleep(1000);
ast_mutex_unlock(&chan_lock);
usleep(1000);
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
while(*p) {
switch (*p) {
case 'T':
while(*p) {
switch (*p) {
case 'T':
}
call->queue_string[0] = '\0';
ast_channel_unlock(ast);
}
call->queue_string[0] = '\0';
ast_channel_unlock(ast);
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
}
void unlock_chan(void)
{
ast_mutex_unlock(&chan_lock);
}
void unlock_chan(void)
{
ast_mutex_unlock(&chan_lock);
/* open socket the first time */
handle_retry(NULL, NULL, 0);
/* open socket the first time */
handle_retry(NULL, NULL, 0);
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
while(!quit) {
handle_queue();
while(!quit) {
handle_queue();
CERROR(NULL, NULL, "Thread exit.\n");
ast_mutex_unlock(&chan_lock);
CERROR(NULL, NULL, "Thread exit.\n");
ast_mutex_unlock(&chan_lock);
struct ast_channel *ast;
struct chan_call *call;
struct ast_channel *ast;
struct chan_call *call;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
CDEBUG(NULL, NULL, "Received request from Asterisk. (data=%s)\n", (char *)data);
/* if socket is closed */
if (lcr_sock < 0) {
CERROR(NULL, NULL, "Rejecting call from Asterisk, because LCR not running.\n");
ast_mutex_unlock(&chan_lock);
CDEBUG(NULL, NULL, "Received request from Asterisk. (data=%s)\n", (char *)data);
/* if socket is closed */
if (lcr_sock < 0) {
CERROR(NULL, NULL, "Rejecting call from Asterisk, because LCR not running.\n");
ast_mutex_unlock(&chan_lock);
if (!call) {
/* failed to create instance */
ast_mutex_unlock(&chan_lock);
if (!call) {
/* failed to create instance */
ast_mutex_unlock(&chan_lock);
free_call(call);
/* failed to create instance */
ast_mutex_unlock(&chan_lock);
free_call(call);
/* failed to create instance */
ast_mutex_unlock(&chan_lock);
return NULL;
}
ast->tech = &lcr_tech;
return NULL;
}
ast->tech = &lcr_tech;
apply_opt(call, (char *)opt);
ast_mutex_unlock(&chan_lock);
apply_opt(call, (char *)opt);
ast_mutex_unlock(&chan_lock);
union parameter newparam;
struct chan_call *call;
union parameter newparam;
struct chan_call *call;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
#ifdef LCR_FOR_CALLWEAVER
call = ast->tech_pvt;
#ifdef LCR_FOR_CALLWEAVER
if (!call) {
CERROR(NULL, ast, "Received call from Asterisk, but call instance does not exist.\n");
ast_mutex_unlock(&chan_lock);
if (!call) {
CERROR(NULL, ast, "Received call from Asterisk, but call instance does not exist.\n");
ast_mutex_unlock(&chan_lock);
sizeof(call->cid_rdnis)-1);
ast_mutex_unlock(&chan_lock);
sizeof(call->cid_rdnis)-1);
ast_mutex_unlock(&chan_lock);
if (digit > 126 || digit < 32)
return 0;
if (digit > 126 || digit < 32)
return 0;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received digit from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received digit from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
}
ast_mutex_unlock(&chan_lock);
}
ast_mutex_unlock(&chan_lock);
#ifdef LCR_FOR_ASTERISK
return 0;
#ifdef LCR_FOR_ASTERISK
return 0;
struct chan_call *call;
#endif
struct chan_call *call;
#endif
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
"Received digit from Asterisk, "
"but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
"Received digit from Asterisk, "
"but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
}
ast_mutex_unlock(&chan_lock);
}
ast_mutex_unlock(&chan_lock);
if (inband_dtmf) {
CDEBUG(call, ast, "-> sending '%c' inband.\n", digit);
if (inband_dtmf) {
CDEBUG(call, ast, "-> sending '%c' inband.\n", digit);
union parameter newparam;
struct chan_call *call;
union parameter newparam;
struct chan_call *call;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received answer from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received answer from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
// send_message(MESSAGE_ENABLEKEYPAD, call->ref, &newparam);
ast_mutex_unlock(&chan_lock);
// send_message(MESSAGE_ENABLEKEYPAD, call->ref, &newparam);
ast_mutex_unlock(&chan_lock);
pthread_t tid = pthread_self();
if (!pthread_equal(tid, chan_tid)) {
pthread_t tid = pthread_self();
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
}
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received hangup from Asterisk, but no call instance exists.\n");
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
}
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received hangup from Asterisk, but no call instance exists.\n");
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
free_call(call);
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
free_call(call);
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
}
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
}
if (!pthread_equal(tid, chan_tid)) {
ast_mutex_unlock(&chan_lock);
if (!(f->subclass & ast->nativeformats))
CDEBUG(NULL, ast, "Unexpected format.\n");
if (!(f->subclass & ast->nativeformats))
CDEBUG(NULL, ast, "Unexpected format.\n");
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
ast_mutex_unlock(&chan_lock);
return -1;
}
if (call->bchannel && f->samples)
bchannel_transmit(call->bchannel, *((unsigned char **)&(f->data)), f->samples);
ast_mutex_unlock(&chan_lock);
return -1;
}
if (call->bchannel && f->samples)
bchannel_transmit(call->bchannel, *((unsigned char **)&(f->data)), f->samples);
ast_mutex_unlock(&chan_lock);
struct chan_call *call;
int len;
struct chan_call *call;
int len;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
ast_mutex_unlock(&chan_lock);
return NULL;
}
if (call->pipe[0] > -1) {
if (call->rebuffer && !call->hdlc) {
/* Make sure we have a complete 20ms (160byte) frame */
return NULL;
}
if (call->pipe[0] > -1) {
if (call->rebuffer && !call->hdlc) {
/* Make sure we have a complete 20ms (160byte) frame */
len=read(call->pipe[0],call->read_buff + call->framepos, 160 - call->framepos);
if (len > 0) {
call->framepos += len;
}
} else {
len=read(call->pipe[0],call->read_buff + call->framepos, 160 - call->framepos);
if (len > 0) {
call->framepos += len;
}
} else {
len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
}
len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
}
if (len < 0 && errno == EAGAIN) {
ast_mutex_unlock(&chan_lock);
if (len < 0 && errno == EAGAIN) {
ast_mutex_unlock(&chan_lock);
#ifdef LCR_FOR_ASTERISK
return &ast_null_frame;
#ifdef LCR_FOR_ASTERISK
return &ast_null_frame;
call->pipe[0] = -1;
global_change = 1;
ast_mutex_unlock(&chan_lock);
call->pipe[0] = -1;
global_change = 1;
ast_mutex_unlock(&chan_lock);
return NULL;
} else if (call->rebuffer && call->framepos < 160) {
/* Not a complete frame, so we send a null-frame */
ast_mutex_unlock(&chan_lock);
return NULL;
} else if (call->rebuffer && call->framepos < 160) {
/* Not a complete frame, so we send a null-frame */
ast_mutex_unlock(&chan_lock);
return &ast_null_frame;
}
}
return &ast_null_frame;
}
}
call->read_fr.delivery = ast_tv(0,0);
*((unsigned char **)&(call->read_fr.data)) = call->read_buff;
ast_mutex_unlock(&chan_lock);
call->read_fr.delivery = ast_tv(0,0);
*((unsigned char **)&(call->read_fr.data)) = call->read_buff;
ast_mutex_unlock(&chan_lock);
struct chan_call *call;
const struct tone_zone_sound *ts = NULL;
struct chan_call *call;
const struct tone_zone_sound *ts = NULL;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received indicate from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received indicate from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
/* return */
ast_mutex_unlock(&chan_lock);
/* return */
ast_mutex_unlock(&chan_lock);
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
return -1;
}
CDEBUG(call, ast, "Received fixup from Asterisk.\n");
call->ast = ast;
ast_mutex_unlock(&chan_lock);
return -1;
}
CDEBUG(call, ast, "Received fixup from Asterisk.\n");
call->ast = ast;
ast_mutex_unlock(&chan_lock);
struct chan_call *call;
union parameter newparam;
struct chan_call *call;
union parameter newparam;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received send_text from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
call = ast->tech_pvt;
if (!call) {
CERROR(NULL, ast, "Received send_text from Asterisk, but no call instance exists.\n");
ast_mutex_unlock(&chan_lock);
strncpy(newparam.notifyinfo.display, text, sizeof(newparam.notifyinfo.display)-1);
send_message(MESSAGE_NOTIFY, call->ref, &newparam);
ast_mutex_unlock(&chan_lock);
strncpy(newparam.notifyinfo.display, text, sizeof(newparam.notifyinfo.display)-1);
send_message(MESSAGE_NOTIFY, call->ref, &newparam);
ast_mutex_unlock(&chan_lock);
carr[1] = ast2;
/* join via dsp (if the channels are currently open) */
carr[1] = ast2;
/* join via dsp (if the channels are currently open) */
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call1 = ast1->tech_pvt;
call2 = ast2->tech_pvt;
if (!call1 || !call2) {
CDEBUG(NULL, NULL, "Bridge, but we don't have two call instances, exitting.\n");
ast_mutex_unlock(&chan_lock);
call1 = ast1->tech_pvt;
call2 = ast2->tech_pvt;
if (!call1 || !call2) {
CDEBUG(NULL, NULL, "Bridge, but we don't have two call instances, exitting.\n");
ast_mutex_unlock(&chan_lock);
return AST_BRIDGE_COMPLETE;
}
return AST_BRIDGE_COMPLETE;
}
}
ast_mutex_unlock(&chan_lock);
}
ast_mutex_unlock(&chan_lock);
CDEBUG(NULL, NULL, "Releasing bridge.\n");
/* split channels */
CDEBUG(NULL, NULL, "Releasing bridge.\n");
/* split channels */
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
call1 = ast1->tech_pvt;
call2 = ast2->tech_pvt;
if (call1 && call1->bridge_id) {
call1 = ast1->tech_pvt;
call2 = ast2->tech_pvt;
if (call1 && call1->bridge_id) {
call2->bridge_call = NULL;
ast_mutex_unlock(&chan_lock);
call2->bridge_call = NULL;
ast_mutex_unlock(&chan_lock);
return AST_BRIDGE_COMPLETE;
}
static struct ast_channel_tech lcr_tech = {
return AST_BRIDGE_COMPLETE;
}
static struct ast_channel_tech lcr_tech = {
{
struct chan_call *call;
{
struct chan_call *call;
ast_mutex_lock(&chan_lock);
ast_mutex_lock(&chan_lock);
#ifdef LCR_FOR_ASTERISK
CDEBUG(NULL, ast, "Received lcr_config (data=%s)\n", (char *)data);
#ifdef LCR_FOR_ASTERISK
CDEBUG(NULL, ast, "Received lcr_config (data=%s)\n", (char *)data);
CERROR(NULL, ast, "lcr_config app not called by chan_lcr channel.\n");
ast_mutex_unlock(&chan_lock);
CERROR(NULL, ast, "lcr_config app not called by chan_lcr channel.\n");
ast_mutex_unlock(&chan_lock);
ast_mutex_lock(&usecnt_lock);
ast_mutex_lock(&usecnt_lock);
res = usecnt;
ast_mutex_unlock(&usecnt_lock);
res = usecnt;
ast_mutex_unlock(&usecnt_lock);
* if no future timeout exists, select will wait infinit.
*/
* if no future timeout exists, select will wait infinit.
*/
-printf("-"); fflush(stdout);
-printf("1"); fflush(stdout);
/* process all work events */
if (next_work()) {
/* process all work events */
if (next_work()) {
-printf("2"); fflush(stdout);
/* process timer events and get timeout for next timer event */
temp = 0;
timer = nearest_timer(&select_timer, &temp);
/* process timer events and get timeout for next timer event */
temp = 0;
timer = nearest_timer(&select_timer, &temp);
-printf("3"); fflush(stdout);
-printf("4"); fflush(stdout);
FD_ZERO(&writeset);
FD_ZERO(&exceptset);
FD_ZERO(&writeset);
FD_ZERO(&exceptset);
-printf("5"); fflush(stdout);
/* prepare read and write fdsets */
lcr_fd = fd_first;
while(lcr_fd) {
/* prepare read and write fdsets */
lcr_fd = fd_first;
while(lcr_fd) {
FD_SET(lcr_fd->fd, &exceptset);
lcr_fd = lcr_fd->next;
}
FD_SET(lcr_fd->fd, &exceptset);
lcr_fd = lcr_fd->next;
}
-printf("6"); fflush(stdout);
*global_change = 0;
return 1;
}
*global_change = 0;
return 1;
}
-printf("7"); fflush(stdout);
/* call registered callback functions */
restart:
/* call registered callback functions */
restart:
-printf("8"); fflush(stdout);
unregistered = 0;
lcr_fd = fd_first;
while(lcr_fd) {
unregistered = 0;
lcr_fd = fd_first;
while(lcr_fd) {
FD_CLR(lcr_fd->fd, &exceptset);
}
if (flags) {
FD_CLR(lcr_fd->fd, &exceptset);
}
if (flags) {
-printf("9"); fflush(stdout);
work = 1;
lcr_fd->cb(lcr_fd, flags, lcr_fd->cb_instance, lcr_fd->cb_index);
work = 1;
lcr_fd->cb(lcr_fd, flags, lcr_fd->cb_instance, lcr_fd->cb_index);
-printf("0"); fflush(stdout);
if (unregistered)
goto restart;
if (unregistered)
goto restart;
-printf("-"); fflush(stdout);
return 1;
}
lcr_fd = lcr_fd->next;
return 1;
}
lcr_fd = lcr_fd->next;