"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/drivers/vpb/sleep.cpp" (8 Sep 2003, 4619 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 "sleep.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 #include "driver.h"
   18 
   19 #ifdef  CCXX_NAMESPACES
   20 using namespace std;
   21 namespace ost {
   22 #endif
   23 
   24 bool VPBTrunk::sleepHandler(TrunkEvent *event)
   25 {
   26     timeout_t wakeup;
   27     char buffer[16];
   28     char *cp, *sp, *value;
   29 
   30     switch(event->id)
   31     {
   32     case TRUNK_EXIT_SHELL:
   33         if(!tgi.pid)
   34             return true;
   35 
   36         tgi.pid = 0;
   37         endTimer();
   38         sprintf(buffer, "exit-%d", event->parm.status);
   39         setSymbol(SYM_ERROR, buffer);
   40         if(event->parm.status)
   41             trunkSignal(TRUNK_SIGNAL_ERROR);
   42         else
   43             trunkSignal(TRUNK_SIGNAL_STEP);
   44         handler = &VPBTrunk::stepHandler;
   45         return true;    
   46     case TRUNK_DTMF_KEYUP:
   47         if(tgi.pid)
   48         {
   49             kill(tgi.pid, SIGINT);
   50             tgi.pid = 0;
   51         }
   52         return false;
   53     case TRUNK_RINGING_OFF:
   54         if(rings > 1)
   55             flags.dsp = DSP_MODE_INACTIVE;
   56         if(!data.sleep.rings)
   57             return true;
   58         if(rings < data.sleep.rings)
   59             return true;
   60         endTimer();
   61     case TRUNK_TIMER_EXPIRED:
   62         if(--data.sleep.loops)
   63         {
   64             setTimer(data.sleep.wakeup);
   65             return true;
   66         }
   67         if(tgi.pid || data.sleep.save)
   68         {
   69             if(tgi.pid)
   70                 kill(tgi.pid, SIGALRM);
   71             tgi.pid = 0;
   72             if(!trunkSignal(TRUNK_SIGNAL_TIMEOUT))
   73                 trunkSignal(TRUNK_SIGNAL_STEP);
   74         }
   75         else
   76             trunkSignal(TRUNK_SIGNAL_STEP);
   77         handler = &VPBTrunk::stepHandler;
   78         return true;
   79         case TRUNK_CHILD_FAIL:
   80                 setSymbol(SYM_ERROR, "start-failed");
   81                 if(!trunkSignal(TRUNK_SIGNAL_FAIL))
   82                         trunkSignal(TRUNK_SIGNAL_STEP);
   83                 handler = &VPBTrunk::stepHandler;
   84                 return true;
   85         case TRUNK_CHILD_START:
   86         cp = event->parm.trunk->getSymbol(SYM_GID);
   87         if(cp)
   88             cp = strchr(cp, '-');
   89         if(cp)
   90             setVariable(data.sleep.save, 16, cp);
   91                 trunkSignal(TRUNK_SIGNAL_STEP);
   92                 handler = &VPBTrunk::stepHandler;
   93                 return true;
   94 
   95     case TRUNK_SERVICE_LOOKUP:
   96         if(event->parm.lookup.seq != tgi.seq)
   97             return false;
   98         if(event->parm.lookup.result)
   99         {
  100             tgi.data = event->parm.lookup.data;
  101             cp = strtok_r(event->parm.lookup.data, "&", &sp);
  102             while(cp)
  103             {
  104                 value = strchr(cp, '=');
  105                 if(value)
  106                 {
  107                     *(value++) = 0;
  108                     setVariable(cp, 0, value);
  109                 }
  110                 cp = strtok_r(NULL, "&", &sp);
  111             }
  112             trunkSignal(TRUNK_SIGNAL_STEP);
  113         }
  114         else
  115         {
  116             setSymbol(SYM_ERROR, event->parm.lookup.data);
  117             trunkSignal(TRUNK_SIGNAL_ERROR);
  118         }
  119         handler = &VPBTrunk::stepHandler;
  120         return true;
  121     case TRUNK_ENTER_STATE:
  122         enterState("sleep");
  123         endTimer();
  124         setDTMFDetect();
  125         wakeup = data.sleep.wakeup;
  126         if(data.sleep.rings)
  127             if(rings >= data.sleep.rings)
  128                 wakeup = 0;
  129 
  130     
  131         if(!wakeup)
  132         {
  133             trunkSignal(TRUNK_SIGNAL_STEP);
  134             handler = &VPBTrunk::stepHandler;
  135             return true;
  136         }
  137 
  138         setTimer(wakeup);
  139         return true;
  140     }
  141     return false;
  142 }
  143 
  144 bool VPBTrunk::threadHandler(TrunkEvent *event)
  145 {
  146     switch(event->id)
  147     {
  148     case TRUNK_STOP_STATE:
  149         stopped = true;
  150         exitThread();
  151         return true;
  152     case TRUNK_EXIT_STATE:
  153         endTimer();
  154         stopServices();
  155         handler = &VPBTrunk::stepHandler;
  156         return true;
  157     case TRUNK_TIMER_EXPIRED:
  158                 if(!stopped)
  159                 {
  160                         setSymbol(SYM_ERROR, "thread-timeout");
  161             if(!trunkSignal(TRUNK_SIGNAL_TIMEOUT))
  162                             trunkSignal(TRUNK_SIGNAL_ERROR);
  163                         exitThread();
  164                         stopped = true;
  165                 }
  166                 return true;
  167     case TRUNK_SERVICE_FAILURE:
  168         if(!stopped)
  169         {
  170             setSymbol(SYM_ERROR, "thread-error");
  171             trunkSignal(TRUNK_SIGNAL_ERROR);
  172             exitThread();
  173             stopped = true;
  174         }
  175         return true;
  176     case TRUNK_SERVICE_SUCCESS:
  177         if(!stopped)
  178         {
  179             trunkSignal(TRUNK_SIGNAL_STEP);
  180             stopped = true;
  181             exitThread();
  182         }
  183         return true;
  184     case TRUNK_ENTER_STATE:
  185         stopped = false;
  186         enterState("thread");
  187         endTimer();
  188         setDTMFDetect();
  189         setTimer(data.sleep.wakeup);
  190         thread->start();
  191         return true;
  192     }
  193     return false;
  194 }
  195 
  196 #ifdef  CCXX_NAMESPACES
  197 };
  198 #endif