+ global_change = 1;
+}
+
+
+/* sending queue to asterisk */
+static int wake_event(struct lcr_fd *fd, unsigned int what, void *instance, int index)
+{
+ char byte;
+
+ read(wake_pipe[0], &byte, 1);
+
+ wake_global = 0;
+
+ return 0;
+}
+
+static void handle_queue()
+{
+ struct chan_call *call;
+ struct ast_channel *ast;
+ struct ast_frame fr;
+ char *p;
+
+again:
+ call = call_first;
+ while(call) {
+ p = call->queue_string;
+ ast = call->ast;
+ if (*p && ast) {
+ if (ast_channel_trylock(ast)) {
+ ast_mutex_unlock(&chan_lock);
+ usleep(1);
+ ast_mutex_lock(&chan_lock);
+ goto again;
+ }
+ while(*p) {
+ switch (*p) {
+ case 'T':
+ CDEBUG(call, ast, "Sending queued PROGRESS to Asterisk.\n");
+ ast_queue_control(ast, AST_CONTROL_PROGRESS);
+ break;
+ case 'P':
+ CDEBUG(call, ast, "Sending queued PROCEEDING to Asterisk.\n");
+ ast_queue_control(ast, AST_CONTROL_PROCEEDING);
+ break;
+ case 'R':
+ CDEBUG(call, ast, "Sending queued RINGING to Asterisk.\n");
+ ast_queue_control(ast, AST_CONTROL_RINGING);
+ ast_setstate(ast, AST_STATE_RINGING);
+ break;
+ case 'N':
+ CDEBUG(call, ast, "Sending queued ANSWER to Asterisk.\n");
+ ast_queue_control(ast, AST_CONTROL_ANSWER);
+ break;
+ case 'H':
+ CDEBUG(call, ast, "Sending queued HANGUP to Asterisk.\n");
+ ast_queue_hangup(ast);
+ break;
+ case '1': case '2': case '3': case 'A':
+ case '4': case '5': case '6': case 'B':
+ case '7': case '8': case '9': case 'C':
+ case '*': case '0': case '#': case 'D':
+ CDEBUG(call, ast, "Sending queued digit '%c' to Asterisk.\n", *p);
+ /* send digit to asterisk */
+ memset(&fr, 0, sizeof(fr));
+
+ #ifdef LCR_FOR_ASTERISK
+ fr.frametype = AST_FRAME_DTMF_BEGIN;
+ #endif
+
+ #ifdef LCR_FOR_CALLWEAVER
+ fr.frametype = AST_FRAME_DTMF;
+ #endif
+
+ fr.subclass = *p;
+ fr.delivery = ast_tv(0, 0);
+ ast_queue_frame(ast, &fr);
+
+ #ifdef LCR_FOR_ASTERISK
+ fr.frametype = AST_FRAME_DTMF_END;
+ ast_queue_frame(ast, &fr);
+ #endif
+
+ break;
+ default:
+ CDEBUG(call, ast, "Ignoring queued digit 0x%02x.\n", *p);
+ }
+ p++;
+ }
+ call->queue_string[0] = '\0';
+ ast_channel_unlock(ast);
+ }
+ call = call->next;
+ }
+}
+
+static int handle_retry(struct lcr_timer *timer, void *instance, int index)
+{
+ CDEBUG(NULL, NULL, "Retry to open socket.\n");
+ if (open_socket() < 0)
+ schedule_timer(&socket_retry, SOCKET_RETRY_TIMER, 0);
+
+ return 0;