Changeset 5029

Changes to match the revised interfaces in Unicall 0.0.6

Committed by:  coppice
Date:  Jul 06 2008 * 13:40 (4 months ago)

Affected files:

callweaver/branches/rel/1.2/channels/chan_unicall.c (unified diff)

r4800r5029
197197 typedef struct unicall_uc_s
198198 {
199199 pthread_t master; /* Thread of master */
200 cw_mutex_t lock; /* Mutex */
201 char idleext[CW_MAX_EXTENSION]; /* Where to idle extra calls */
202 char idlecontext[CW_MAX_EXTENSION]; /* What context to use for idle */
203 char idledial[CW_MAX_EXTENSION]; /* What to dial before dumping */
200 cw_mutex_t lock; /* Mutex */
201 char idleext[CW_MAX_EXTENSION]; /* Where to idle extra calls */
202 char idlecontext[CW_MAX_EXTENSION]; /* What context to use for idle */
203 char idledial[CW_MAX_EXTENSION]; /* What to dial before dumping */
204204 int min_unused; /* Min # of channels to keep empty */
205205 int min_idle; /* Min # of "idling" calls to keep active */
206206 int num_channels; /* Num of chans in group (say, 31 or 24) */
------
217217 struct unicall_channel *chan[32]; /* Channels on each line */
218218 } unicall_uc_t;
219219
220 #define SUB_REAL 0 /* Active call */
221 #define SUB_CALLWAIT 1 /* Call-waiting call on hold */
222 #define SUB_THREEWAY 2 /* Three-way call */
220 #define SUB_REAL 0 /* Active call */
221 #define SUB_CALLWAIT 1 /* Call-waiting call on hold */
222 #define SUB_THREEWAY 2 /* Three-way call */
223223
224224 static char *subnames[] =
225225 {
------
583583 return 0;
584584 }
585585
586 #if 0
587 static char *zt_events[] =
588 {
589 "No event",
590 "On hook",
591 "Ring/Answered",
592 "Wink/Flash",
593 "Alarm",
594 "No more alarm",
595 "HDLC Abort",
596 "HDLC Overrun",
597 "HDLC Bad FCS",
598 "Dial Complete",
599 "Ringer On",
600 "Ringer Off",
601 "Hook Transition Complete",
602 "Bits Changed",
603 "Pulse Start"
604 };
605
606 static char *zt_event2str(int event)
607 {
608 static char buf[256];
609
610 if (-1 < event && event < 15)
611 return zt_events[event];
612 /*endif*/
613 sprintf(buf, "Event %d", event);
614 return buf;
615 }
616 #endif
617
618586 static char *alarm2str(int alarm)
619587 {
620588 static const struct
------
643611 return (alarm) ? "Unknown Alarm" : "No Alarm";
644612 }
645613
646 static void unicall_message(char *s)
614 static void unicall_message(int level, const char *s)
647615 {
648616 cw_verbose(s);
649617 }
650618
651 static void unicall_report(char *s)
619 static void unicall_report(const char *s)
652620 {
653621 cw_log(LOG_WARNING, s);
654622 }
------
11001068 makecall.crn = 0;
11011069 if ((ret = uc_call_control(p->uc, UC_OP_MAKECALL, 0, &makecall)) != UC_RET_OK)
11021070 {
1103 cw_log(LOG_WARNING, "Make call failed - %s\n", uc_ret2str(ret));
1071 cw_log(LOG_WARNING, "Make call failed - %s\n", uc_ret_to_str(ret));
11041072 return -1;
11051073 }
11061074 /*endif*/
------
14081376 if (p->crn)
14091377 {
14101378 if ((ret = uc_call_control(p->uc, UC_OP_DROPCALL, p->crn, (void *) (intptr_t) hangup_cause2uc(cw->hangupcause))) < 0)
1411 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
1379 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
14121380 /*endif*/
14131381 if (p->alreadyhungup)
14141382 p->alreadyhungup = FALSE;
------
14781446 {
14791447 cw_log(LOG_WARNING, "Answer Call\n");
14801448 if ((ret = uc_call_control(p->uc, UC_OP_ANSWERCALL, p->crn, NULL)))
1481 cw_log(LOG_WARNING, "Answer call failed on %s - %s\n", cw->name, uc_ret2str(ret));
1449 cw_log(LOG_WARNING, "Answer call failed on %s - %s\n", cw->name, uc_ret_to_str(ret));
14821450 /*endif*/
14831451 }
14841452 else
------
20732041 return &p->subs[index].f;
20742042 }
20752043
2076 void handle_uc_read(uc_t *uc, int ch, void *user_data, uint8_t *buf, int len)
2044 void handle_uc_read(uc_t *uc, int ch, void *user_data, const uint8_t *buf, int len)
20772045 {
20782046 void *readbuf;
20792047 unicall_pvt_t *p;
------
25002468 case CW_CONTROL_RINGING:
25012469 //super_tone(&p->subs[index], ST_TYPE_RINGBACK);
25022470 //if ((ret = uc_call_control(p->uc, UC_OP_ACCEPTCALL, ev->offered.crn, NULL)) < 0)
2503 // cw_log(LOG_WARNING, "Accept call failed - %s\n", uc_ret2str(ret));
2471 // cw_log(LOG_WARNING, "Accept call failed - %s\n", uc_ret_to_str(ret));
25042472 if (chan->_state != CW_STATE_UP)
25052473 {
25062474 if (chan->_state != CW_STATE_RING)
------
25162484 if (p->radio)
25172485 {
25182486 if ((ret = uc_call_control(p->uc, UC_OP_DROPCALL, p->crn, (void *) UC_CAUSE_NORMAL_CLEARING)) < 0)
2519 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2487 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
25202488 /*endif*/
25212489 }
25222490 /*endif*/
------
25262494 if (p->radio)
25272495 {
25282496 if ((ret = uc_call_control(p->uc, UC_OP_DROPCALL, p->crn, (void *) UC_CAUSE_NORMAL_CLEARING)) < 0)
2529 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2497 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
25302498 /*endif*/
25312499 }
25322500 /*endif*/
------
26922660 /*endif*/
26932661 /* Handle an event on a given channel for the monitor thread. */
26942662
2695 cw_log(LOG_WARNING, "UniCall/%d event %s\n", i->channel, uc_event2str(ev->e));
2663 cw_log(LOG_WARNING, "UniCall/%d event %s\n", i->channel, uc_event_to_str(ev->e));
26962664 switch (ev->e)
26972665 {
26982666 case UC_EVENT_PROTOCOLFAIL:
------
27742742 reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER;
27752743 reqmoreinfo.minimum = -1;
27762744 if ((ret = uc_call_control(i->uc, UC_OP_REQUESTMOREINFO, ev->offered.crn, &reqmoreinfo)) < 0)
2777 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret2str(ret));
2745 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret_to_str(ret));
27782746 /*endif*/
27792747 }
27802748 else
------
27852753 reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER;
27862754 reqmoreinfo.minimum = strlen(ev->offered.parms.destination_number) + 1;
27872755 if ((ret = uc_call_control(i->uc, UC_OP_REQUESTMOREINFO, ev->offered.crn, &reqmoreinfo)) < 0)
2788 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret2str(ret));
2756 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret_to_str(ret));
27892757 /*endif*/
27902758 }
27912759 else
------
27942762 reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER;
27952763 reqmoreinfo.minimum = -1;
27962764 if ((ret = uc_call_control(i->uc, UC_OP_REQUESTMOREINFO, ev->offered.crn, &reqmoreinfo)) < 0)
2797 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret2str(ret));
2765 cw_log(LOG_WARNING, "Request more info failed - %s\n", uc_ret_to_str(ret));
27982766 /*endif*/
27992767 }
28002768 /*endif*/
------
28502818 i->law = UC_CODEC_ULAW;
28512819 /*endif*/
28522820 if ((ret = uc_call_control(i->uc, UC_OP_ACCEPTCALL, ev->offered.crn, NULL)) < 0)
2853 cw_log(LOG_WARNING, "Accept call failed - %s\n", uc_ret2str(ret));
2821 cw_log(LOG_WARNING, "Accept call failed - %s\n", uc_ret_to_str(ret));
28542822 /*endif*/
28552823 }
28562824 else
------
28742842 }
28752843 /*endif*/
28762844 if ((ret = uc_call_control(i->uc, UC_OP_DROPCALL, ev->offered.crn, (void *) UC_CAUSE_UNASSIGNED_NUMBER)) < 0)
2877 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2845 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
28782846 /*endif*/
28792847 }
28802848 /*endif*/
------
28842852 else
28852853 {
28862854 if ((ret = uc_call_control(i->uc, UC_OP_DROPCALL, ev->offered.crn, (void *) UC_CAUSE_CHANNEL_UNACCEPTABLE)) < 0)
2887 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2855 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
28882856 /*endif*/
28892857 }
28902858 /*endif*/
------
29012869 {
29022870 cw_log(LOG_WARNING, "UniCall/%d unable to start PBX\n", i->channel);
29032871 if ((ret = uc_call_control(i->uc, UC_OP_DROPCALL, ev->offered.crn, (void *) UC_CAUSE_NETWORK_CONGESTION)) < 0)
2904 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2872 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
29052873 /*endif*/
29062874 }
29072875 /*endif*/
------
29642932 case UC_EVENT_FARDISCONNECTED:
29652933 if ((ch = ev->fardisconnected.channel) >= 0)
29662934 {
2967 cw_log(LOG_WARNING, "CRN %d - far disconnected cause=%s [%d]\n", ev->fardisconnected.crn, uc_cause2str(ev->fardisconnected.cause), ev->fardisconnected.cause);
2935 cw_log(LOG_WARNING, "CRN %d - far disconnected cause=%s [%d]\n", ev->fardisconnected.crn, uc_cause_to_str(ev->fardisconnected.cause), ev->fardisconnected.cause);
29682936 if (i->owner)
29692937 {
29702938 i->alreadyhungup = TRUE;
------
29762944 else
29772945 {
29782946 if ((ret = uc_call_control(i->uc, UC_OP_DROPCALL, ev->fardisconnected.crn, (void *) UC_CAUSE_NORMAL_CLEARING)) < 0)
2979 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
2947 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
29802948 /*endif*/
29812949 }
29822950 /*endif*/
------
30142982 {
30152983 cw_log(LOG_DEBUG, "CRN %d - Doing a release call\n", ev->gen.crn);
30162984 if ((ret = uc_call_control(i->uc, UC_OP_RELEASECALL, ev->gen.crn, NULL)) < 0)
3017 cw_log(LOG_WARNING, "Release call failed - %s\n", uc_ret2str(ret));
2985 cw_log(LOG_WARNING, "Release call failed - %s\n", uc_ret_to_str(ret));
30182986 /*endif*/
30192987 }
30202988 else
------
30593027 cw_log(LOG_WARNING,
30603028 "UniCall/%d Don't know how to handle signalling event %s\n",
30613029 i->channel,
3062 uc_event2str(ev->e));
3030 uc_event_to_str(ev->e));
30633031 break;
30643032 }
30653033 /*endswitch*/
------
33103278 {
33113279 if ((ret = uc_call_control(p->uc, UC_OP_DROPCALL, p->crn, (void *) UC_CAUSE_NORMAL_CLEARING)))
33123280 {
3313 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret2str(ret));
3281 cw_log(LOG_WARNING, "Drop call failed - %s\n", uc_ret_to_str(ret));
33143282 cw_log(LOG_ERROR, "Unable to hangup chan_unicall channel %d\n", p->channel);
33153283 return -1;
33163284 }
------
34453413 tmp->protocol_class = protocol_class;
34463414 tmp->protocol_variant = protocol_variant;
34473415 tmp->protocol_end = (protocol_end == NULL || strcasecmp(protocol_end, "co") == 0) ? UC_MODE_CO : UC_MODE_CPE;
3448 if (!here)
3449 {
3450 tmp->subs[SUB_REAL].fd = uc_channel_open(tmp->protocol_class,
3451 tmp->protocol_variant,
3452 tmp->protocol_end,
3453 fn);
3454 }
3416 if (here)
3417 uc_delete(tmp->uc);
34553418 /*endif*/
3456 if (tmp->subs[SUB_REAL].fd < 0)
3419 if ((tmp->subs[SUB_REAL].fd = uc_channel_open(tmp->protocol_class,
3420 tmp->protocol_variant,
3421 tmp->protocol_end,
3422 fn)) < 0)
34573423 {
34583424 cw_log(LOG_ERROR, "Unable to open channel %d: %s\nhere = %d, tmp->channel = %d, channel = %d\n", channel, strerror(errno), here, tmp->channel, channel);
34593425 destroy_unicall_pvt_s(&tmp);
------
34863452 //uc_set_channel_error_callback(tmp->uc, channel_error, (void *) tmp);
34873453 dtmf_tx_init(&tmp->subs[SUB_REAL].dtmf_tx_state);
34883454 if ((ret = uc_call_control(tmp->uc, UC_OP_UNBLOCK, 0, (void *) -1)) < 0)
3489 cw_log(LOG_WARNING, "Unblock failed - %s\n", uc_ret2str(ret));
3455 cw_log(LOG_WARNING, "Unblock failed - %s\n", uc_ret_to_str(ret));
34903456 /*endif*/
34913457 tmp->immediate = immediate;
34923458 tmp->protocol_class = protocol_class;
------
45474513 msg.message = (unsigned char *) text;
45484514 if ((ret = uc_call_control(p->uc, UC_OP_USERTOUSER, 0, &msg)) < 0)
45494515 {
4550 cw_log(LOG_WARNING, "User to user failed - %s\n", uc_ret2str(ret));
4516 cw_log(LOG_WARNING, "User to user failed - %s\n", uc_ret_to_str(ret));
45514517 return -1;
45524518 }
45534519 /*endif*/