faxGettyApp.h
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:5k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /* $Id: faxGettyApp.h,v 1.9 2007/08/17 14:54:27 faxguy Exp $ */
  2. /*
  3.  * Copyright (c) 1990-1996 Sam Leffler
  4.  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
  5.  * HylaFAX is a trademark of Silicon Graphics
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and 
  8.  * its documentation for any purpose is hereby granted without fee, provided
  9.  * that (i) the above copyright notices and this permission notice appear in
  10.  * all copies of the software and related documentation, and (ii) the names of
  11.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  12.  * publicity relating to the software without the specific, prior written
  13.  * permission of Sam Leffler and Silicon Graphics.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18.  * 
  19.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24.  * OF THIS SOFTWARE.
  25.  */
  26. #ifndef _faxGettyApp_
  27. #define _faxGettyApp_
  28. /*
  29.  * HylaFAX Modem Handler.
  30.  */
  31. #include "faxApp.h"
  32. #include "FaxServer.h"
  33. class UUCPLock;
  34. class Getty;
  35. class AnswerTimeoutHandler : public IOHandler {
  36. public:
  37.     AnswerTimeoutHandler();
  38.     ~AnswerTimeoutHandler();
  39.     void timerExpired(long, long);
  40. };
  41. class faxGettyApp : public FaxServer, public faxApp {
  42. public:
  43.     struct stringtag {
  44. const char*  name;
  45. fxStr faxGettyApp::* p;
  46. const char*  def; // NULL is shorthand for ""
  47.     };
  48.     struct numbertag {
  49. const char*  name;
  50. u_int faxGettyApp::*p;
  51. u_int  def;
  52.     };
  53.     struct booltag {
  54. const char*  name;
  55. bool faxGettyApp::*p;
  56. u_int  def;
  57.     };
  58. private:
  59. // runtime state
  60.     fxStr readyState; // modem ready state to send queuer
  61.     int devfifo; // fifo device interface
  62.     UUCPLock* modemLock; // UUCP interlock
  63.     AnswerTimeoutHandler answerHandler; // for timing out inbound calls
  64.     u_short ringsBeforeAnswer; // # rings to wait
  65.     u_short ringsHeard; // # rings received
  66.     CallID received_callid; // non-null received CNID
  67.     fxStr gettyArgs; // getty arguments
  68.     fxStr vgettyArgs; // voice getty arguments
  69.     fxStr egettyArgs; // extern getty arguments
  70.     bool adaptiveAnswer; // answer as data if fax answer fails
  71.     bool lockDataCalls; // hold uucp lock for getty
  72.     bool lockVoiceCalls; // hold uucp lock for vgetty
  73.     bool lockExternCalls; // hold uucp lock for egetty
  74.     u_int answerBias; // rotor bias applied after good calls
  75.     u_short answerRotor; // rotor into possible selections
  76.     u_short answerRotorSize; // rotor table size
  77.     AnswerType answerRotary[3]; // rotary selection of answer types
  78.     fxStr faxRcvdCmd; // fax received command
  79.     fxStr dynamicConfig; // command to dynamically alter configuration
  80.     fxStr tsiRecvdCmd; // command to check TSI
  81.     u_int modemPriority; // modem priority passed to faxq
  82.     bool logCalls; // Log all calls for FaxAcctInfo
  83.     bool rejectCall;
  84.     static faxGettyApp* _instance;
  85.     static stringtag strings[];
  86.     static numbertag numbers[];
  87.     static booltag booleans[];
  88.     static const fxStr recvDir;
  89. // configuration support
  90.     void setupConfig();
  91.     void resetConfig();
  92.     bool setConfigItem(const char* tag, const char* value);
  93.     void setAnswerRotary(const fxStr& value);
  94. // modem handling
  95.     bool isModemLocked();
  96.     bool canLockModem();
  97.     bool lockModem();
  98.     void unlockModem();
  99.     bool setupModem(bool isSend);
  100.     void discardModem(bool dropDTR);
  101. // inbound call handling
  102.     bool processCall(CallType ctype, FaxMachineInfo info, fxStr& emsg, CallID& callid);
  103.     CallType runGetty(const char* what,
  104.     Getty* (*newgetty)(const fxStr&, const fxStr&),
  105.     const char* args, fxStr &emsg, int& status,
  106.                     bool keepLock, const CallID& callid, 
  107.     bool keepModem = false);
  108.     void setRingsBeforeAnswer(int rings);
  109.     void listenBegin();
  110.     void listenForRing();
  111.     void answerPhoneCmd(AnswerType, const char* dialnumber = NULL);
  112.     void answerPhone(AnswerType, CallType, CallID& callid, const char* dialnumber = NULL);
  113.     void answerCleanup();
  114.     bool answerCall(AnswerType atype, CallType& ctype, FaxMachineInfo info, fxStr& emsg, CallID& callid, const char* dialnumber = NULL);
  115.     friend void AnswerTimeoutHandler::timerExpired(long, long);
  116. // miscellaneous stuff
  117.     bool sendModemStatus(const char* msg);
  118.     void scriptedConfig(fxStr& cmd, fxStr& emsg);
  119. // FIFO-related stuff
  120.     void openFIFOs();
  121.     void closeFIFOs();
  122.     void FIFOMessage(const char* mesage);
  123. // Dispatcher hooks
  124.     int inputReady(int);
  125. // notification interfaces used by FaxServer
  126.     void notifyModemReady();
  127.     void notifyModemWedged();
  128.     void notifyRecvBegun(FaxRecvInfo&);
  129.     void notifyPageRecvd(TIFF* tif, FaxRecvInfo&, int ppm);
  130.     void notifyDocumentRecvd(FaxRecvInfo&);
  131.     void notifyRecvDone(FaxRecvInfo&);
  132.     bool processTSIRecvdCmd(FaxRecvInfo&, fxStr&);
  133. public:
  134.     faxGettyApp(const fxStr& device, const fxStr& devID);
  135.     ~faxGettyApp();
  136.     static faxGettyApp& instance();
  137.     void initialize(int argc, char** argv);
  138.     void open();
  139.     void close();
  140. };
  141. #endif