"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/drivers/globalcall/dial.cpp" (27 May 2006, 7331 Bytes) of package /linux/misc/old/bayonne-1.2.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dial.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2000 Open Source Telecom Corporation.
    2 //  
    3 // This program is free software; you can redistribute it and/or modify
    4 // it under the terms of the GNU General Public License as published by
    5 // the Free Software Foundation; either version 2 of the License, or
    6 // (at your option) any later version.
    7 // 
    8 // This program is distributed in the hope that it will be useful,
    9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 // GNU General Public License for more details.
   12 // 
   13 // You should have received a copy of the GNU General Public License
   14 // along with this program; if not, write to the Free Software 
   15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   16 //
   17 // As a special exception to the GNU General Public License, permission is
   18 // granted for additional uses of the text contained in its release
   19 // of Bayonne as noted here.
   20 //
   21 // This exception is that permission is hereby granted to link Bayonne 
   22 // with the Dialogic runtime libraries to produce a executable image
   23 // without requiring Dialogic's sources to be supplied so long as each
   24 // source file so linked contains this exclusion.
   25 //
   26 // This exception does not however invalidate any other reasons why
   27 // the resulting executable file might be covered by the GNU General
   28 // public license or invalidate the licensing requirements of any
   29 // other component or library.
   30 //
   31 // This exception applies only to the code released by OST under the
   32 // name Bayonne.  If you copy code from other releases into a copy of
   33 // Bayonne, as the General Public License permits, the exception does not
   34 // apply to the code that you add in this way.  To avoid misleading
   35 // anyone as to the status of such modified files, you must delete
   36 // this exception notice from them.
   37 //
   38 // If you write modifications of your own to Bayonne, it is your choice
   39 // whether to permit this exception to apply to your modifications.
   40 // If you do not wish that, delete this exception notice, at which
   41 // point the terms of your modification would be covered under the GPL
   42 // as explicitly stated in "COPYING".
   43 
   44 #include "driver.h"
   45 
   46 #ifdef CCXX_NAMESPACES
   47 namespace ost {
   48 using namespace std;
   49 #endif
   50 
   51 bool DialogicTrunk::dialHandler(TrunkEvent *event)
   52 {
   53     char dialstr[40];
   54     const char *dp;
   55 
   56     switch(event->id)
   57     {
   58     case TRUNK_CALL_RELEASE:
   59         setSymbol(SYM_TONE, "fail");
   60         if(!trunkSignal(TRUNK_SIGNAL_HANGUP))
   61             if(!trunkSignal(TRUNK_SIGNAL_CANCEL))
   62                 if(!trunkSignal(TRUNK_SIGNAL_TONE))
   63                     trunkSignal(TRUNK_SIGNAL_STEP);
   64         handler = &DialogicTrunk::stepHandler;
   65         return true;
   66     case TRUNK_TIMER_EXPIRED:
   67         stopChannel(EV_ASYNC);
   68         if(data.dialxfer.exit)
   69             trunkSignal(TRUNK_SIGNAL_HANGUP);
   70         else if(!trunkSignal(TRUNK_SIGNAL_TIMEOUT))
   71             if(!trunkSignal(TRUNK_SIGNAL_CANCEL))
   72                 trunkSignal(TRUNK_SIGNAL_STEP);
   73         handler = &DialogicTrunk::stepHandler;
   74         return true;
   75     case TRUNK_CPA_BUSYTONE:
   76         setSymbol(SYM_TONE, "busy");
   77         stopChannel(EV_ASYNC);
   78         if(!trunkSignal(TRUNK_SIGNAL_BUSY))
   79             if(!trunkSignal(TRUNK_SIGNAL_TONE))
   80             {
   81                 if(data.dialxfer.exit)
   82                     trunkSignal(TRUNK_SIGNAL_HANGUP);
   83                 else
   84                     trunkSignal(TRUNK_SIGNAL_STEP);
   85             }
   86         handler = &DialogicTrunk::hangupHandler;
   87         return true;        
   88     case TRUNK_CPA_NOANSWER:
   89         setSymbol(SYM_TONE, "ring");
   90         if(trunkSignal(TRUNK_SIGNAL_NOANSWER))
   91         {
   92             handler = &DialogicTrunk::stepHandler;
   93             return true;
   94         }
   95         trunkSignal(TRUNK_SIGNAL_STEP);
   96         event->id = TRUNK_TIMER_EXPIRED;
   97         handler = &DialogicTrunk::hangupHandler;
   98         return true;
   99     case TRUNK_CPA_NORINGBACK:
  100         setSymbol(SYM_TONE, "silence");
  101         stopChannel(EV_ASYNC);
  102         if(trunkSignal(TRUNK_SIGNAL_SILENCE))
  103         {
  104             handler = &DialogicTrunk::stepHandler;
  105             return true;
  106         }
  107         trunkSignal(TRUNK_SIGNAL_STEP);
  108         event->id = TRUNK_TIMER_EXPIRED;
  109         handler = &DialogicTrunk::hangupHandler;
  110         return true;
  111     case TRUNK_CPA_FAILURE:
  112     case TRUNK_CPA_NODIALTONE:
  113         setSymbol(SYM_TONE, "fail");
  114         if(_stopping_state)
  115         {
  116             handler = &DialogicTrunk::stepHandler;
  117             return true;
  118         }
  119         if(trunkSignal(TRUNK_SIGNAL_CANCEL))
  120         {
  121             handler = &DialogicTrunk::stepHandler;
  122             return true;
  123         }
  124         if(trunkSignal(TRUNK_SIGNAL_TONE))
  125         {
  126             handler = &DialogicTrunk::stepHandler;
  127             return true;
  128         }
  129         trunkSignal(TRUNK_SIGNAL_STEP);
  130         event->id = TRUNK_TIMER_EXPIRED;
  131         handler = &DialogicTrunk::hangupHandler;
  132         return true;
  133     case TRUNK_CALL_CONNECT:
  134         if(dxcap.ca_intflg == DX_PAMDOPTEN)
  135             return true;
  136         stopChannel(EV_ASYNC);
  137         return true;
  138     case TRUNK_CPA_STOPPED:
  139     case TRUNK_CPA_CONNECT:
  140         if(_stopping_state)
  141         {
  142             handler = &DialogicTrunk::stepHandler;
  143             return true;
  144         }
  145         if(data.dialxfer.exit)
  146             trunkSignal(TRUNK_SIGNAL_HANGUP);
  147         else
  148             trunkSignal(TRUNK_SIGNAL_STEP);
  149         handler = &DialogicTrunk::stepHandler;
  150         return true;
  151     case TRUNK_STOP_STATE:
  152         _stopping_state = true;
  153         stopChannel(EV_ASYNC);
  154         TimerPort::endTimer();
  155         handler = &DialogicTrunk::hangupHandler;
  156         return true;
  157     case TRUNK_ENTER_STATE:
  158         enterState("dial");
  159         _stopping_state = false;
  160         TimerPort::endTimer();
  161         setSymbol(SYM_TONE, "none");
  162         Trunk::flags.offhook = true;
  163 
  164         if(status[id] == 'd')
  165             return true;
  166         status[id] = 'd';
  167         if(strlen(data.dialxfer.digit) < 1)
  168         {
  169             setSymbol(SYM_ERROR, "dial-no-number");
  170             trunkSignal(TRUNK_SIGNAL_ERROR);
  171             handler = &DialogicTrunk::stepHandler;
  172             return true;
  173         }
  174         dp = group->getLast("dialmode");
  175         if(!dp)
  176             dp = "T";
  177 
  178         switch(*dp)
  179         {
  180         case 't':
  181         case 'T':
  182         case 'd':
  183         case 'D':
  184             dp = "T";
  185             break;
  186         case 'm':
  187         case 'M':
  188             dp = "M";
  189             break;
  190         case 'p':
  191         case 'P':
  192             dp = "P";
  193             break;
  194         default:
  195             dp = "";
  196         }
  197 
  198         strcpy(dialstr, dp);
  199         strcat(dialstr, data.dialxfer.digit);
  200 
  201                 if(data.dialxfer.timeout)
  202                 {
  203                         dx_clrcap(&dxcap);
  204 
  205             // Enable only basic CPA, not PVD & PAMD, by default.
  206             // PVD & PAMD introduce a silent delay in dialing after
  207             // answer.
  208             dxcap.ca_intflg = DX_OPTEN;
  209 
  210                         // rings before concluding no answer
  211 
  212                         dp = group->getLast("cprings");
  213                         if(dp)
  214                                 dxcap.ca_nbrdna = atoi(dp);
  215 
  216                         dp = group->getLast("noanswer");
  217                         if(dp)
  218                                 dxcap.ca_noanswer = getMSTimeout(dp) / 10;
  219 
  220                         // silence on ringback
  221 
  222                         dp = group->getLast("nosignal");
  223                         if(dp)
  224                                 dxcap.ca_cnosig = getMSTimeout(dp) / 10;
  225 
  226                         dp = group->getLast("nosilence");
  227                         if(dp)
  228                                 dxcap.ca_cnosil = getMSTimeout(dp) / 10;
  229 
  230             dp = group->getLast("intercept");
  231             if(dp)
  232             {
  233                 if(!strnicmp(dp, "pam", 3))
  234                     dxcap.ca_intflg = DX_PAMDOPTEN;
  235             }
  236                 }
  237         if(!makeCall(data.dialxfer.digit, data.dialxfer.timeout))
  238         {
  239                         setSymbol(SYM_ERROR, "dial-failed");
  240                         trunkSignal(TRUNK_SIGNAL_ERROR);
  241                         handler = &DialogicTrunk::stepHandler;
  242             return true;
  243         }
  244 
  245         if(dx_dial(chdev, "", &dxcap, EV_ASYNC | DX_CALLP) < 0)
  246             postError(chdev, "dx_dial");
  247 
  248         return true;
  249 
  250     case TRUNK_LINE_WINK:
  251             return true;
  252     }
  253 
  254     return false;
  255 }
  256 
  257 #ifdef CCXX_NAMESPACES
  258 };
  259 #endif
  260