home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / connection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  2.8 KB  |  101 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef CONNECTION_H
  24. #define CONNECTION_H
  25.  
  26. #include "arts_export.h"
  27. #include "buffer.h"
  28.  
  29. /*
  30.  * BC - Status (2002-03-08): Connection.
  31.  *
  32.  * None of these classes is considered part of the public API. However, they
  33.  * NEED to be kept binary compatible as the DO interact with generated code.
  34.  *
  35.  * Especially virtual functions and stuff can't be added, if you need to,
  36.  * you need to add classes parallel to the Connection hierarchy.
  37.  */
  38.  
  39. namespace Arts {
  40.  
  41. class ConnectionPrivate;
  42.  
  43. class ARTS_EXPORT Connection {
  44. private:
  45.     ConnectionPrivate *d;        // unused
  46. public:
  47.     enum ConnectionState {
  48.         unknown = 0,
  49.         expectServerHello = 1,
  50.         expectClientHello = 2,
  51.         expectAuthAccept = 3,
  52.         established = 4
  53.     };
  54. protected:
  55.     Buffer *rcbuf;
  56.     bool receiveHeader;
  57.     long remaining;
  58.     long messageType;
  59.     ConnectionState _connState;
  60.     std::string serverID;
  61.     std::string _cookie;
  62.  
  63.     long _refCnt;
  64.  
  65.     /**
  66.      * If you don't want to handle message fragmentation yourself:
  67.      * 
  68.      * Call initReceive in your derived Connection constructor, ald
  69.      * receive as soon as you receive some data - the connection object
  70.      * will handle the rest (put the messages into buffers and send them
  71.      * to the dispatcher)
  72.      */
  73.     void initReceive();
  74.     void receive(unsigned char *data, long len);
  75.  
  76.     virtual ~Connection();
  77. public:
  78.     Connection();
  79.  
  80.     inline void setServerID(const std::string& _serverID) { serverID = _serverID; }
  81.     inline bool isConnected(const std::string& s) { return (serverID == s); } 
  82.     inline void setConnState(ConnectionState cs) { _connState = cs; };
  83.  
  84.     inline std::string cookie() { return _cookie; }
  85.     void setCookie(const std::string& c) { _cookie = c; }
  86.     void setHints(const std::vector<std::string>& hints);
  87.     std::string findHint(const std::string& name);
  88.  
  89.     inline ConnectionState connState() { return _connState; };
  90.     virtual void drop() = 0;
  91.     virtual bool broken() = 0;
  92.     virtual void qSendBuffer(Buffer *buffer) = 0;
  93.  
  94.     void _release();
  95.     void _copy();
  96. };
  97.  
  98. }
  99.  
  100. #endif
  101.