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( const wxSockAddress
& addr
, bool WXUNUSED(wait
) = true)
63 { return wxSocketClient::Connect(addr
); }
65 // read a '\r\n' terminated line from the given socket and put it in
66 // result (without the terminators)
67 static wxProtocolError
ReadLine(wxSocketBase
*socket
, wxString
& result
);
69 // read a line from this socket - this one can be overridden in the
70 // derived classes if different line termination convention is to be used
71 virtual wxProtocolError
ReadLine(wxString
& result
);
72 #endif // wxUSE_SOCKETS
74 virtual bool Abort() = 0;
75 virtual wxInputStream
*GetInputStream(const wxString
& path
) = 0;
76 virtual wxString
GetContentType() const = 0;
79 virtual wxProtocolError
GetError() const { return m_lastError
; }
81 void SetUser(const wxString
& user
) { m_username
= user
; }
82 void SetPassword(const wxString
& passwd
) { m_password
= passwd
; }
84 virtual void SetDefaultTimeout(wxUint32 Value
);
86 // override wxSocketBase::SetTimeout function to avoid that the internal
87 // m_uiDefaultTimeout goes out-of-sync:
88 virtual void SetTimeout(long seconds
)
89 { SetDefaultTimeout(seconds
); }
93 // the timeout associated with the protocol:
94 wxUint32 m_uiDefaultTimeout
;
99 // this must be always updated by the derived classes!
100 wxProtocolError m_lastError
;
103 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol
)
106 // ----------------------------------------------------------------------------
107 // macros for protocol classes
108 // ----------------------------------------------------------------------------
110 #define DECLARE_PROTOCOL(class) \
112 static wxProtoInfo g_proto_##class;
114 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
115 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
116 bool wxProtocolUse##class = TRUE;
118 #define USE_PROTOCOL(class) \
119 extern bool wxProtocolUse##class ; \
120 static struct wxProtocolUserFor##class \
122 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
123 } wxProtocolDoUse##class;
125 class WXDLLIMPEXP_NET wxProtoInfo
: public wxObject
128 wxProtoInfo(const wxChar
*name
,
129 const wxChar
*serv_name
,
130 const bool need_host1
,
135 wxString m_protoname
;
138 wxClassInfo
*m_cinfo
;
143 DECLARE_DYNAMIC_CLASS(wxProtoInfo
)
144 wxDECLARE_NO_COPY_CLASS(wxProtoInfo
);
147 #endif // wxUSE_PROTOCOL
149 #endif // _WX_PROTOCOL_PROTOCOL_H