"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/drivers/phonedev/driver.h" (12 Dec 2002, 4997 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 "driver.h" 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 <ivrconfig.h>
   18 #include <server.h>
   19 #include <cc++/audio.h>
   20 
   21 #ifdef  HAVE_LINUX_TELEPHONY_H
   22 #include <linux/telephony.h>
   23 #ifdef  HAVE_LINUX_IXJUSER_H
   24 #include <linux/ixjuser.h>
   25 #endif
   26 #endif
   27 
   28 #ifdef HAVE_SYS_TELEPHONY_H
   29 #include <sys/telephony.h>
   30 #ifdef HAVE_SYS_IXJUSER_H
   31 #include <sys/ixjuser.h>
   32 #endif
   33 #endif
   34 
   35 #ifdef  CCXX_NAMESPACES
   36 namespace ost {
   37 #endif
   38 
   39 typedef enum
   40 {
   41     ECHO_OFF = 0,
   42     ECHO_LOW,
   43     ECHO_MEDIUM,
   44     ECHO_HIGH
   45 } aeclevel_t;
   46 
   47 typedef enum
   48 {
   49     CPA_DIALTONE = 0,
   50     CPA_BUSYTONE
   51 } cpatone_t;
   52 
   53 class PhonedevTrunk;
   54 
   55 typedef union
   56 {
   57 #ifdef  IXJ_PHONEDEV
   58     PHONE_CID   ixjcid;
   59 #endif
   60 }   cid_t;
   61 
   62 typedef enum
   63 {
   64     generic_driver,
   65     ixj_driver
   66 }   driver_t;
   67 
   68 typedef bool (PhonedevTrunk::*trunkhandler_t)(TrunkEvent *event);
   69 
   70 class PhonedevTrunk : private TimerPort, private Trunk
   71 {
   72 private:
   73     friend class PhonedevDriver;
   74     friend class PhonedevService;
   75     friend class PhonedevPlay;
   76     
   77     static char status[240];
   78 
   79     time_t lastring;
   80     trunkhandler_t handler;
   81     struct phone_capability *cap_list;
   82     PhonedevTrunk *next, *prev;
   83     PhonedevService *service;
   84     driver_t driver;
   85     int cap_count;
   86     int dev;
   87 
   88 #ifdef  IXJ_PHONEDEV
   89     IXJ_FILTER cpatone[4];
   90 #endif
   91 
   92     PhonedevTrunk(int fd, int ts);
   93     ~PhonedevTrunk();
   94 
   95     void initSyms(void);
   96     void setEcho(aeclevel_t level);
   97     void setCPADetect(cpatone_t tone, bool flag);
   98     void getName(char *buffer);
   99     unsigned long getIdleTime(void);
  100     void setHookState(bool offhook);
  101 
  102     bool stepHandler(TrunkEvent *event);
  103     bool busyHandler(TrunkEvent *event);
  104     bool idleHandler(TrunkEvent *event);
  105     bool seizeHandler(TrunkEvent *event);
  106     bool ringHandler(TrunkEvent *event);
  107     bool waitHandler(TrunkEvent *event);
  108     bool loadHandler(TrunkEvent *event);
  109     bool dialHandler(TrunkEvent *event);
  110     bool playHandler(TrunkEvent *event);
  111     bool playwaitHandler(TrunkEvent *event);
  112     bool recordHandler(TrunkEvent *event);
  113     bool threadHandler(TrunkEvent *event);
  114     bool sleepHandler(TrunkEvent *event);
  115     bool hangupHandler(TrunkEvent *event);
  116     bool answerHandler(TrunkEvent *event);
  117     bool collectHandler(TrunkEvent *event);
  118     bool flashonHandler(TrunkEvent *event);
  119     bool flashoffHandler(TrunkEvent *event);
  120 
  121     struct phone_capability *getCapability(phone_cap id, int sub = -1);
  122     bool postEvent(TrunkEvent *event);
  123     void getEvents(void);
  124     void setTimer(timeout_t timeout = 0);
  125     void incTimer(timeout_t timeout);
  126     void exit(void);
  127     void trunkStep(trunkstep_t step);
  128 
  129 public:
  130     inline int getDevice(void)
  131         {return dev;};
  132 
  133     inline driver_t getDriver(void)
  134         {return driver;};
  135 };
  136 
  137 class PhonedevRecord : private AudioFile, public Service
  138 {
  139 private:
  140     int dev;
  141     bool reset;
  142     driver_t driver;
  143     size_t bufsize, samples;
  144 
  145 public:
  146     PhonedevRecord(PhonedevTrunk *trunk);
  147     ~PhonedevRecord();
  148     void initial(void);
  149     void run(void);
  150 };
  151 
  152 class PhonedevPlay : private URLAudio, public Service
  153 {
  154 private:
  155     int dev, id;
  156     bool reset;
  157     driver_t driver;
  158     size_t bufsize, samples;
  159     void initial(void);
  160     void run(void);
  161     char *getContinuation(void);
  162 
  163 public:
  164     PhonedevPlay(PhonedevTrunk *trunk);
  165     ~PhonedevPlay();
  166 };
  167 
  168 class PhonedevService : public Thread, private Mutex
  169 {
  170 private:
  171     friend class PhonedevDriver;
  172     friend class PhonedevTrunk;
  173 
  174     fd_set connect;
  175     int iosync[2];
  176     int hiwater;
  177     int count;
  178     PhonedevTrunk *first, *last;
  179 
  180     void attach(PhonedevTrunk *trunk);
  181     void detach(PhonedevTrunk *trunk);
  182     void run(void);
  183     void update(unsigned char id = 0xff);
  184 
  185     PhonedevService();
  186     ~PhonedevService();
  187 };  
  188 
  189 class PhonedevConfig : public Keydata
  190 {
  191 public:
  192     PhonedevConfig();
  193 
  194     inline int getDevices(void)
  195         {return atoi(getLast("devices"));};
  196 
  197     inline int getWinkDuration(void)
  198         {return atoi(getLast("wink"));};
  199 
  200     inline int getAudioBuffers(void)
  201         {return atoi(getLast("buffers"));};
  202 
  203     size_t getStack(void);
  204 };
  205 
  206 class PhonedevDriver : public Driver, public PhonedevConfig
  207 {
  208 private:
  209     PhonedevService *threads;
  210     int thread_count;
  211     int thread_select;
  212 
  213     PhonedevTrunk **ports;
  214     int port_count;
  215 
  216     int start(void);
  217     void stop(void);
  218 
  219 public:
  220     PhonedevDriver();
  221     ~PhonedevDriver();
  222 
  223     unsigned getTrunkCount(void)
  224         {return port_count;};
  225 
  226     Trunk *getTrunkPort(int id);
  227     PhonedevService *getService(void);
  228     aaScript *getScript(void);
  229     void notify(unsigned char id);    // ALWAYS trunk + 1
  230 };
  231 
  232 extern PhonedevDriver phivr;
  233 
  234 #ifdef  CCXX_NAMESPACES
  235 };
  236 #endif