home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / COMBASE.H < prev    next >
C/C++ Source or Header  |  1998-05-12  |  9KB  |  324 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef _COMBASE_H
  20. #define _COMBASE_H
  21.  
  22. #if defined(__OS2__)
  23. #include <types.h>
  24. #include <netinet\in.h>
  25. #include <sys\socket.h>
  26. #include <netdb.h>
  27. #include <sys\ioctl.h>
  28. #elif defined(__NT__)
  29. #elif defined(__LINUX__)
  30. #include <netdb.h>
  31. #include <sys/socket.h>
  32. #include <sys/ioctl.h>
  33. #include <netinet/in.h>
  34. #else
  35. extern "C" {
  36. #include <sys\types.h>
  37. #include <netdb.h>
  38. #include <sys/socket.h>
  39. #include <sys/ioctl.h>
  40. #include <netinet/in.h>
  41. #include <pctcp/types.h>
  42. #include <pctcp/rwconf.h>
  43. #include <pctcp/pctcp.h>
  44. #include <pctcp/syscalls.h>
  45. };
  46. #endif
  47.  
  48. #if defined(__DOS__) || (defined(__BORLANDC__) && !defined(__OS2__))
  49. #if defined(__386__)
  50. #define DOS4G
  51. #endif
  52. #include "commlib.h"
  53. #include "ibmkeys.h"
  54. #endif
  55.  
  56. #include "cxl.h"
  57.  
  58. #if defined(__LINUX__)
  59. #include <signal.h>
  60. #include <termios.h>
  61. #include <sys/ioctl.h>
  62. #include <linux/kd.h>      /* RAW mode stuff, etc. */
  63. #include <linux/keyboard.h>   /* mainly for NR_KEYS */
  64. #include <linux/vt.h>       /* for VT stuff - nah, really? :) */
  65. #endif
  66.  
  67. #define RSIZE        2048
  68. #define TSIZE        512
  69.  
  70. class DLL_EXPORT TCom
  71. {
  72. public:
  73.    TCom (void) {};
  74.    virtual ~TCom (void) {};
  75.  
  76.    USHORT  EndRun;
  77.    USHORT  RxBytes, TxBytes;
  78.  
  79.    virtual USHORT BytesReady (VOID) = 0;
  80.    virtual VOID   BufferByte (UCHAR byte) = 0;
  81.    virtual VOID   BufferBytes (UCHAR *bytes, USHORT len) = 0;
  82.    virtual USHORT Carrier (VOID) = 0;
  83.    virtual VOID   ClearOutbound (VOID) = 0;
  84.    virtual VOID   ClearInbound (VOID) = 0;
  85.    virtual UCHAR  ReadByte (VOID) = 0;
  86.    virtual USHORT ReadBytes (UCHAR *bytes, USHORT len) = 0;
  87.    virtual VOID   SendByte (UCHAR byte) = 0;
  88.    virtual VOID   SendBytes (UCHAR *bytes, USHORT len) = 0;
  89.    virtual VOID   UnbufferBytes (VOID) = 0;
  90.  
  91.    virtual VOID   SetName (PSZ name) = 0;
  92.    virtual VOID   SetCity (PSZ name) = 0;
  93.    virtual VOID   SetLevel (PSZ level) = 0;
  94.    virtual VOID   SetTimeLeft (ULONG seconds) = 0;
  95.    virtual VOID   SetTime (ULONG seconds) = 0;
  96.  
  97. protected:
  98.    UCHAR  RxBuffer[RSIZE], TxBuffer[TSIZE];
  99.    UCHAR  *NextByte;
  100. };
  101.  
  102. #define DTR                1
  103. #define RTS                2
  104. #define CTS                16
  105. #define DSR                32
  106. #define RI                 64
  107. #define DCD                128
  108. #define DATA_READY         0x0100
  109. #define TX_SHIFT_EMPTY     0x4000
  110.  
  111. class DLL_EXPORT TSerial : public TCom
  112. {
  113. public:
  114.    TSerial (void);
  115.    ~TSerial (void);
  116.  
  117. #if defined(__OS2__) || defined(__NT__) || defined(__LINUX__)
  118.    CHAR   Device[32];
  119. #elif defined(__DOS__)
  120.    USHORT Com;
  121. #endif
  122.    ULONG  Speed;
  123.    USHORT DataBits, StopBits;
  124.    CHAR   Parity;
  125. #if defined(__OS2__)
  126.    HFILE  hFile;
  127. #elif defined(__NT__)
  128.    HANDLE hFile;
  129. #elif defined(__LINUX__)
  130.    int    hFile;
  131.    struct termios tty;
  132. #endif
  133.  
  134.    USHORT BytesReady (VOID);
  135.    VOID   BufferByte (UCHAR byte);
  136.    VOID   BufferBytes (UCHAR *bytes, USHORT len);
  137.    USHORT Carrier (VOID);
  138.    VOID   ClearOutbound (VOID);
  139.    VOID   ClearInbound (VOID);
  140.    USHORT Initialize (VOID);
  141.    UCHAR  ReadByte (VOID);
  142.    USHORT ReadBytes (UCHAR *bytes, USHORT len);
  143.    VOID   SendByte (UCHAR byte);
  144.    VOID   SendBytes (UCHAR *bytes, USHORT len);
  145.    VOID   SetDTR (USHORT fStatus);
  146.    VOID   SetRTS (USHORT fStatus);
  147.    VOID   SetParameters (ULONG ulSpeed, USHORT nData, UCHAR nParity, USHORT nStop);
  148.    VOID   UnbufferBytes (VOID);
  149.  
  150.    VOID   SetName (PSZ name);
  151.    VOID   SetCity (PSZ name);
  152.    VOID   SetLevel (PSZ level);
  153.    VOID   SetTimeLeft (ULONG seconds);
  154.    VOID   SetTime (ULONG seconds);
  155.  
  156. private:
  157. #if defined(__DOS__)
  158.    PORT   *hPort;
  159. #elif defined(__LINUX__)
  160.    struct termios new_termio;
  161.    struct termios old_termio;
  162. #endif
  163. };
  164.  
  165. class DLL_EXPORT TScreen : public TCom
  166. {
  167. public:
  168.    TScreen (void);
  169.    ~TScreen (void);
  170.  
  171.    USHORT BytesReady (VOID);
  172.    VOID   BufferByte (UCHAR byte);
  173.    VOID   BufferBytes (UCHAR *bytes, USHORT len);
  174.    USHORT Carrier (VOID);
  175.    VOID   ClearOutbound (VOID);
  176.    VOID   ClearInbound (VOID);
  177.    USHORT Initialize (VOID);
  178.    UCHAR  ReadByte (VOID);
  179.    USHORT ReadBytes (UCHAR *bytes, USHORT len);
  180.    VOID   SendByte (UCHAR byte);
  181.    VOID   SendBytes (UCHAR *bytes, USHORT len);
  182.    VOID   UnbufferBytes (VOID);
  183.  
  184.    VOID   SetName (PSZ name);
  185.    VOID   SetCity (PSZ name);
  186.    VOID   SetLevel (PSZ level);
  187.    VOID   SetTimeLeft (ULONG seconds);
  188.    VOID   SetTime (ULONG seconds);
  189.  
  190. private:
  191.    CXLWIN wh;
  192.    USHORT Running;
  193.    USHORT RxPosition, Counter;
  194.    USHORT Attr, Count, Params[10];
  195.    CHAR   Prec, Ansi;
  196. };
  197.  
  198. class DLL_EXPORT TTcpip : public TCom
  199. {
  200. public:
  201.    TTcpip (void);
  202.    ~TTcpip (void);
  203.  
  204.    CHAR   ClientIP[16];
  205.    CHAR   ClientName[128];
  206.    CHAR   HostIP[16];
  207.    ULONG  HostID;
  208.  
  209.    USHORT BytesReady (VOID);
  210.    VOID   BufferByte (UCHAR byte);
  211.    VOID   BufferBytes (UCHAR *bytes, USHORT len);
  212.    USHORT Carrier (VOID);
  213.    VOID   ClearOutbound (VOID);
  214.    VOID   ClearInbound (VOID);
  215.    VOID   ClosePort (VOID);
  216.    USHORT ConnectServer (PSZ pszServerName, USHORT usPort);
  217.    USHORT Initialize (USHORT usPort, USHORT usSocket = 0, USHORT usProtocol = IPPROTO_TCP);
  218.    UCHAR  ReadByte (VOID);
  219.    USHORT ReadBytes (UCHAR *bytes, USHORT len);
  220.    VOID   SendByte (UCHAR byte);
  221.    VOID   SendBytes (UCHAR *bytes, USHORT len);
  222.    VOID   UnbufferBytes (VOID);
  223.    USHORT WaitClient (VOID);
  224.  
  225.    USHORT GetPacket (PVOID lpBuffer, USHORT usSize);
  226.    USHORT PeekPacket (PVOID lpBuffer, USHORT usSize);
  227.    USHORT SendPacket (PVOID lpBuffer, USHORT usSize);
  228.  
  229.    VOID   SetName (PSZ name);
  230.    VOID   SetCity (PSZ name);
  231.    VOID   SetLevel (PSZ level);
  232.    VOID   SetTimeLeft (ULONG seconds);
  233.    VOID   SetTime (ULONG seconds);
  234.  
  235. private:
  236.    int    Sock, Accepted;
  237.    int    LSock;
  238.    USHORT fCarrierDown;
  239.    USHORT RxPosition;
  240.    struct sockaddr_in udp_client;
  241.  
  242. #if defined(__OS2__)
  243.    friend VOID WaitThread (PVOID Args);
  244. #endif
  245. };
  246.  
  247. class DLL_EXPORT TStdio : public TCom
  248. {
  249. public:
  250.    TStdio (void);
  251.    ~TStdio (void);
  252.  
  253.    USHORT BytesReady (VOID);
  254.    VOID   BufferByte (UCHAR byte);
  255.    VOID   BufferBytes (UCHAR *bytes, USHORT len);
  256.    USHORT Carrier (VOID);
  257.    VOID   ClearOutbound (VOID);
  258.    VOID   ClearInbound (VOID);
  259.    USHORT Initialize (VOID);
  260.    UCHAR  ReadByte (VOID);
  261.    USHORT ReadBytes (UCHAR *bytes, USHORT len);
  262.    VOID   SendByte (UCHAR byte);
  263.    VOID   SendBytes (UCHAR *bytes, USHORT len);
  264.    VOID   UnbufferBytes (VOID);
  265.  
  266.    VOID   SetName (PSZ name);
  267.    VOID   SetCity (PSZ name);
  268.    VOID   SetLevel (PSZ level);
  269.    VOID   SetTimeLeft (ULONG seconds);
  270.    VOID   SetTime (ULONG seconds);
  271.  
  272. private:
  273.    USHORT RxPosition;
  274. #if defined(__LINUX__)
  275.    int tty_fd;
  276.    struct termios new_termio, old_termio;
  277. #endif
  278. };
  279.  
  280. #if defined(__OS2__) || defined(__NT__)
  281. class DLL_EXPORT TPipe : public TCom
  282. {
  283. public:
  284.    TPipe (void);
  285.    ~TPipe (void);
  286.  
  287.    CHAR   Name[64], City[64], Level[64];
  288.    ULONG  TimeLeft, Time;
  289.  
  290.    USHORT BytesReady (VOID);
  291.    VOID   BufferByte (UCHAR byte);
  292.    VOID   BufferBytes (UCHAR *bytes, USHORT len);
  293.    USHORT Carrier (VOID);
  294.    VOID   ClearOutbound (VOID);
  295.    VOID   ClearInbound (VOID);
  296.    USHORT Initialize (PSZ pszPipeName, PSZ pszCtlName, USHORT usInstances);
  297.    USHORT ConnectServer (PSZ pszPipeName, PSZ pszCtlName);
  298.    UCHAR  ReadByte (VOID);
  299.    USHORT ReadBytes (UCHAR *bytes, USHORT len);
  300.    VOID   SendByte (UCHAR byte);
  301.    VOID   SendBytes (UCHAR *bytes, USHORT len);
  302.    VOID   UnbufferBytes (VOID);
  303.    USHORT WaitClient (VOID);
  304.  
  305.    VOID   SetName (PSZ name);
  306.    VOID   SetCity (PSZ name);
  307.    VOID   SetLevel (PSZ level);
  308.    VOID   SetTimeLeft (ULONG seconds);
  309.    VOID   SetTime (ULONG seconds);
  310.  
  311. private:
  312.    USHORT CtlConnect, PipeConnect;
  313. #if defined(__OS2__)
  314.    HFILE  hFile, hFileCtl;
  315. #elif defined(__NT__)
  316.    HANDLE hFile, hFileCtl;
  317. #endif
  318. };
  319. #endif
  320.  
  321. #endif
  322.  
  323.  
  324.