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)
| r4800 | r5029 | |
|---|---|---|
| 197 | 197 | typedef struct unicall_uc_s |
| 198 | 198 | { |
| 199 | 199 | 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 */ | |
| 204 | 204 | int min_unused; /* Min # of channels to keep empty */ |
| 205 | 205 | int min_idle; /* Min # of "idling" calls to keep active */ |
| 206 | 206 | int num_channels; /* Num of chans in group (say, 31 or 24) */ |
| --- | --- | |
| 217 | 217 | struct unicall_channel *chan[32]; /* Channels on each line */ |
| 218 | 218 | } unicall_uc_t; |
| 219 | 219 | |
| 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 */ | |
| 223 | 223 | |
| 224 | 224 | static char *subnames[] = |
| 225 | 225 | { |
| --- | --- | |
| 583 | 583 | return 0; |
| 584 | 584 | } |
| 585 | 585 | |
| 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 | ||
| 618 | 586 | static char *alarm2str(int alarm) |
| 619 | 587 | { |
| 620 | 588 | static const struct |
| --- | --- | |
| 643 | 611 | return (alarm) ? "Unknown Alarm" : "No Alarm"; |
| 644 | 612 | } |
| 645 | 613 | |
| 646 | static void unicall_message(char *s) | |
| 614 | static void unicall_message(int level, const char *s) | |
| 647 | 615 | { |
| 648 | 616 | cw_verbose(s); |
| 649 | 617 | } |
| 650 | 618 | |
| 651 | static void unicall_report(char *s) | |
| 619 | static void unicall_report(const char *s) | |
| 652 | 620 | { |
| 653 | 621 | cw_log(LOG_WARNING, s); |
| 654 | 622 | } |
| --- | --- | |
| 1100 | 1068 | makecall.crn = 0; |
| 1101 | 1069 | if ((ret = uc_call_control(p->uc, UC_OP_MAKECALL, 0, &makecall)) != UC_RET_OK) |
| 1102 | 1070 | { |
| 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)); | |
| 1104 | 1072 | return -1; |
| 1105 | 1073 | } |
| 1106 | 1074 | /*endif*/ |
| --- | --- | |
| 1408 | 1376 | if (p->crn) |
| 1409 | 1377 | { |
| 1410 | 1378 | 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)); | |
| 1412 | 1380 | /*endif*/ |
| 1413 | 1381 | if (p->alreadyhungup) |
| 1414 | 1382 | p->alreadyhungup = FALSE; |
| --- | --- | |
| 1478 | 1446 | { |
| 1479 | 1447 | cw_log(LOG_WARNING, "Answer Call\n"); |
| 1480 | 1448 | 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)); | |
| 1482 | 1450 | /*endif*/ |
| 1483 | 1451 | } |
| 1484 | 1452 | else |
| --- | --- | |
| 2073 | 2041 | return &p->subs[index].f; |
| 2074 | 2042 | } |
| 2075 | 2043 | |
| 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) | |
| 2077 | 2045 | { |
| 2078 | 2046 | void *readbuf; |
| 2079 | 2047 | unicall_pvt_t *p; |
| --- | --- | |
| 2500 | 2468 | case CW_CONTROL_RINGING: |
| 2501 | 2469 | //super_tone(&p->subs[index], ST_TYPE_RINGBACK); |
| 2502 | 2470 | //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)); | |
| 2504 | 2472 | if (chan->_state != CW_STATE_UP) |
| 2505 | 2473 | { |
| 2506 | 2474 | if (chan->_state != CW_STATE_RING) |
| --- | --- | |
| 2516 | 2484 | if (p->radio) |
| 2517 | 2485 | { |
| 2518 | 2486 | 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)); | |
| 2520 | 2488 | /*endif*/ |
| 2521 | 2489 | } |
| 2522 | 2490 | /*endif*/ |
| --- | --- | |
| 2526 | 2494 | if (p->radio) |
| 2527 | 2495 | { |
| 2528 | 2496 | 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)); | |
| 2530 | 2498 | /*endif*/ |
| 2531 | 2499 | } |
| 2532 | 2500 | /*endif*/ |
| --- | --- | |
| 2692 | 2660 | /*endif*/ |
| 2693 | 2661 | /* Handle an event on a given channel for the monitor thread. */ |
| 2694 | 2662 | |
| 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)); | |
| 2696 | 2664 | switch (ev->e) |
| 2697 | 2665 | { |
| 2698 | 2666 | case UC_EVENT_PROTOCOLFAIL: |
| --- | --- | |
| 2774 | 2742 | reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER; |
| 2775 | 2743 | reqmoreinfo.minimum = -1; |
| 2776 | 2744 | 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)); | |
| 2778 | 2746 | /*endif*/ |
| 2779 | 2747 | } |
| 2780 | 2748 | else |
| --- | --- | |
| 2785 | 2753 | reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER; |
| 2786 | 2754 | reqmoreinfo.minimum = strlen(ev->offered.parms.destination_number) + 1; |
| 2787 | 2755 | 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)); | |
| 2789 | 2757 | /*endif*/ |
| 2790 | 2758 | } |
| 2791 | 2759 | else |
| --- | --- | |
| 2794 | 2762 | reqmoreinfo.type = UC_REQUESTMOREINFO_DESTINATION_NUMBER; |
| 2795 | 2763 | reqmoreinfo.minimum = -1; |
| 2796 | 2764 | 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)); | |
| 2798 | 2766 | /*endif*/ |
| 2799 | 2767 | } |
| 2800 | 2768 | /*endif*/ |
| --- | --- | |
| 2850 | 2818 | i->law = UC_CODEC_ULAW; |
| 2851 | 2819 | /*endif*/ |
| 2852 | 2820 | 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)); | |
| 2854 | 2822 | /*endif*/ |
| 2855 | 2823 | } |
| 2856 | 2824 | else |
| --- | --- | |
| 2874 | 2842 | } |
| 2875 | 2843 | /*endif*/ |
| 2876 | 2844 | 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)); | |
| 2878 | 2846 | /*endif*/ |
| 2879 | 2847 | } |
| 2880 | 2848 | /*endif*/ |
| --- | --- | |
| 2884 | 2852 | else |
| 2885 | 2853 | { |
| 2886 | 2854 | 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)); | |
| 2888 | 2856 | /*endif*/ |
| 2889 | 2857 | } |
| 2890 | 2858 | /*endif*/ |
| --- | --- | |
| 2901 | 2869 | { |
| 2902 | 2870 | cw_log(LOG_WARNING, "UniCall/%d unable to start PBX\n", i->channel); |
| 2903 | 2871 | 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)); | |
| 2905 | 2873 | /*endif*/ |
| 2906 | 2874 | } |
| 2907 | 2875 | /*endif*/ |
| --- | --- | |
| 2964 | 2932 | case UC_EVENT_FARDISCONNECTED: |
| 2965 | 2933 | if ((ch = ev->fardisconnected.channel) >= 0) |
| 2966 | 2934 | { |
| 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); | |
| 2968 | 2936 | if (i->owner) |
| 2969 | 2937 | { |
| 2970 | 2938 | i->alreadyhungup = TRUE; |
| --- | --- | |
| 2976 | 2944 | else |
| 2977 | 2945 | { |
| 2978 | 2946 | 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)); | |
| 2980 | 2948 | /*endif*/ |
| 2981 | 2949 | } |
| 2982 | 2950 | /*endif*/ |
| --- | --- | |
| 3014 | 2982 | { |
| 3015 | 2983 | cw_log(LOG_DEBUG, "CRN %d - Doing a release call\n", ev->gen.crn); |
| 3016 | 2984 | 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)); | |
| 3018 | 2986 | /*endif*/ |
| 3019 | 2987 | } |
| 3020 | 2988 | else |
| --- | --- | |
| 3059 | 3027 | cw_log(LOG_WARNING, |
| 3060 | 3028 | "UniCall/%d Don't know how to handle signalling event %s\n", |
| 3061 | 3029 | i->channel, |
| 3062 | uc_event2str(ev->e)); | |
| 3030 | uc_event_to_str(ev->e)); | |
| 3063 | 3031 | break; |
| 3064 | 3032 | } |
| 3065 | 3033 | /*endswitch*/ |
| --- | --- | |
| 3310 | 3278 | { |
| 3311 | 3279 | if ((ret = uc_call_control(p->uc, UC_OP_DROPCALL, p->crn, (void *) UC_CAUSE_NORMAL_CLEARING))) |
| 3312 | 3280 | { |
| 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)); | |
| 3314 | 3282 | cw_log(LOG_ERROR, "Unable to hangup chan_unicall channel %d\n", p->channel); |
| 3315 | 3283 | return -1; |
| 3316 | 3284 | } |
| --- | --- | |
| 3445 | 3413 | tmp->protocol_class = protocol_class; |
| 3446 | 3414 | tmp->protocol_variant = protocol_variant; |
| 3447 | 3415 | 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); | |
| 3455 | 3418 | /*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) | |
| 3457 | 3423 | { |
| 3458 | 3424 | 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); |
| 3459 | 3425 | destroy_unicall_pvt_s(&tmp); |
| --- | --- | |
| 3486 | 3452 | //uc_set_channel_error_callback(tmp->uc, channel_error, (void *) tmp); |
| 3487 | 3453 | dtmf_tx_init(&tmp->subs[SUB_REAL].dtmf_tx_state); |
| 3488 | 3454 | 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)); | |
| 3490 | 3456 | /*endif*/ |
| 3491 | 3457 | tmp->immediate = immediate; |
| 3492 | 3458 | tmp->protocol_class = protocol_class; |
| --- | --- | |
| 4547 | 4513 | msg.message = (unsigned char *) text; |
| 4548 | 4514 | if ((ret = uc_call_control(p->uc, UC_OP_USERTOUSER, 0, &msg)) < 0) |
| 4549 | 4515 | { |
| 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)); | |
| 4551 | 4517 | return -1; |
| 4552 | 4518 | } |
| 4553 | 4519 | /*endif*/ |
![Home changeset 5029 [home]](/images/logo.png?1180520111)
RSS Feeds