home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / IrDA / IrConnection.h < prev    next >
C/C++ Source or Header  |  2000-06-06  |  3KB  |  130 lines

  1. //
  2. //  $Id: IrConnection.h,v 1.3 2000/06/06 09:30:54 sergey Exp $
  3. //
  4.  
  5. #ifndef _IrConnection_h_
  6. #define _IrConnection_h_
  7.  
  8. #include "IrConstants.h"
  9. #include "Util/MemBuffer.h"
  10.  
  11.  
  12. namespace IrDA
  13. {
  14.     class Callback;
  15.  
  16.     class Connection
  17.     {
  18.     public:
  19.         Connection();
  20.         ~Connection();
  21.  
  22.     private:
  23.         Connection(const Connection&);
  24.         Connection& operator =(const Connection&);
  25.  
  26.     // operations
  27.     public:
  28.         bool init(Word refNum, Callback* callback);
  29.         void shutdown();
  30.  
  31.         bool connect();
  32.         void disconnect();
  33.  
  34.         bool sendData(const Byte* data, int size);
  35.  
  36.         // Blocks until the channel not ready to accept this portion of data.
  37.         bool blockingSendData(const Byte* data, int size);
  38.  
  39.     // attributes
  40.  
  41.         bool ready() const          { return _ready; }
  42.         bool dataSendReady() const  { return _dataSendReady; }
  43.  
  44.         int getMaxTxSize() const;
  45.         int getMaxRxSize() const;
  46.  
  47.     // implementation
  48.     private:
  49.  
  50.         // protocol commands
  51.  
  52.         bool bind();
  53.         void unbind();
  54.         bool discovery();
  55.         bool connectLap();
  56.         bool disconnectLap();
  57.         bool connectComm();
  58.         bool connectLmp(Byte remoteLsap);
  59.         bool connectTinyTp(Byte remoteLsap);
  60.  
  61.         bool setDeviceInfo();
  62.  
  63.         void initServiceTypePacket();
  64.         void initDataPacket(const Byte* data, int size);
  65.  
  66.         // utilities
  67.  
  68.         bool waitUntilMediaReady() const;
  69.         bool waitUntilDataSendReady() const;
  70.         bool waitForResult() const;
  71.  
  72.         // callback handling
  73.  
  74.         static void irCallback(IrConnect* conn, IrCallBackParms* params);
  75.  
  76.         void discovered(IrDeviceList* devices);
  77.         void connectedLap();
  78.         void requestedLapConnection();
  79.         void disconnectedLap();
  80.         void connectedLm();
  81.         void requestedLmConnection();
  82.         void disconnectedLm();
  83.         void packetHandled();
  84.         void dataReceived(const Byte* data, int size);
  85.         void statusChanged(IrStatus status);
  86.  
  87.         // debug
  88.  
  89.         #ifdef IR_DEBUG
  90.         void debugPrintStatus(IrStatus status);
  91.         void debugPrintEvent(IrEvent event);
  92.         void debugPrintDeviceInfo(IrDeviceInfo& deviceInfo);
  93.         #endif
  94.  
  95.     // data members
  96.     private:
  97.         static Connection*  _this;
  98.  
  99.         Word _refNum;
  100.         bool _bound;
  101.         bool _ready;
  102.         bool _dataSendReady;
  103.         bool _cookedProtocol;
  104.  
  105.         enum CommandType
  106.         {
  107.             NoCommand,
  108.             DiscoveryCommand,
  109.             ConnectLapCommand,
  110.             DisconnectLapCommand,
  111.             ConnectLmCommand,
  112.             SendDataCommand
  113.         };
  114.  
  115.         CommandType _pendingCommand;
  116.         bool _commandSucceed;
  117.  
  118.         IrDeviceInfo _deviceInfo;
  119.         IrPacket _packet;
  120.         IrConnect _connect;
  121.  
  122.         Util::MemBuffer _packetBuffer;
  123.  
  124.         Callback* _callback;
  125.     };
  126. }
  127. // namespace IrDA
  128.  
  129. #endif // _IrConnection_h_
  130.