1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/protocol/protocol.h 
   3 // Purpose:     Protocol base class 
   4 // Author:      Guilhem Lavaux 
   8 // Copyright:   (c) 1997, 1998 Guilhem Lavaux 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #ifndef _WX_PROTOCOL_PROTOCOL_H 
  13 #define _WX_PROTOCOL_PROTOCOL_H 
  19 #include "wx/object.h" 
  20 #include "wx/string.h" 
  21 #include "wx/stream.h" 
  24     #include "wx/socket.h" 
  27 // ---------------------------------------------------------------------------- 
  29 // ---------------------------------------------------------------------------- 
  45 // ---------------------------------------------------------------------------- 
  46 // wxProtocol: abstract base class for all protocols 
  47 // ---------------------------------------------------------------------------- 
  49 class WXDLLIMPEXP_NET wxProtocol
 
  51  : public wxSocketClient
 
  61     virtual bool Connect( const wxString
& WXUNUSED(host
) ) { return FALSE
; } 
  62     virtual bool Connect( wxSockAddress
& addr
, bool WXUNUSED(wait
) = TRUE
) { return wxSocketClient::Connect(addr
); } 
  64     // read a '\r\n' terminated line from the given socket and put it in 
  65     // result (without the terminators) 
  66     static wxProtocolError 
ReadLine(wxSocketBase 
*socket
, wxString
& result
); 
  68     // read a line from this socket - this one can be overridden in the 
  69     // derived classes if different line termination convention is to be used 
  70     virtual wxProtocolError 
ReadLine(wxString
& result
); 
  71 #endif // wxUSE_SOCKETS 
  73     virtual bool Abort() = 0; 
  74     virtual wxInputStream 
*GetInputStream(const wxString
& path
) = 0; 
  75     virtual wxProtocolError 
GetError() = 0; 
  76     virtual wxString 
GetContentType() { return wxEmptyString
; } 
  77     virtual void SetUser(const wxString
& WXUNUSED(user
)) {} 
  78     virtual void SetPassword(const wxString
& WXUNUSED(passwd
) ) {} 
  81     DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol
) 
  85 wxProtocolError WXDLLIMPEXP_NET 
GetLine(wxSocketBase 
*sock
, wxString
& result
); 
  88 // ---------------------------------------------------------------------------- 
  89 // macros for protocol classes 
  90 // ---------------------------------------------------------------------------- 
  92 #define DECLARE_PROTOCOL(class) \ 
  94   static wxProtoInfo g_proto_##class; 
  96 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \ 
  97 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \ 
  98 bool wxProtocolUse##class = TRUE; 
 100 #define USE_PROTOCOL(class) \ 
 101     extern bool wxProtocolUse##class ; \ 
 102     static struct wxProtocolUserFor##class \ 
 104         wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \ 
 105     } wxProtocolDoUse##class; 
 107 class WXDLLIMPEXP_NET wxProtoInfo 
: public wxObject
 
 110     wxProtoInfo(const wxChar 
*name
, 
 111                 const wxChar 
*serv_name
, 
 112                 const bool need_host1
, 
 117     wxString m_protoname
; 
 120     wxClassInfo 
*m_cinfo
; 
 125     DECLARE_DYNAMIC_CLASS(wxProtoInfo
) 
 126     DECLARE_NO_COPY_CLASS(wxProtoInfo
) 
 129 #endif // wxUSE_PROTOCOL 
 131 #endif // _WX_PROTOCOL_PROTOCOL_H