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
15 #if defined(__GNUG__) && !defined(__APPLE__)
23 #include "wx/object.h"
24 #include "wx/string.h"
25 #include "wx/stream.h"
28 #include "wx/socket.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
50 // wxProtocol: abstract base class for all protocols
51 // ----------------------------------------------------------------------------
53 class WXDLLEXPORT wxProtocol
55 : public wxSocketClient
65 virtual bool Connect( const wxString
& WXUNUSED(host
) ) { return FALSE
; }
66 virtual bool Connect( wxSockAddress
& addr
, bool WXUNUSED(wait
) = TRUE
) { return wxSocketClient::Connect(addr
); }
68 // read a '\r\n' terminated line from the given socket and put it in
69 // result (without the terminators)
70 static wxProtocolError
ReadLine(wxSocketBase
*socket
, wxString
& result
);
72 // read a line from this socket - this one can be overridden in the
73 // derived classes if different line termination convention is to be used
74 virtual wxProtocolError
ReadLine(wxString
& result
);
75 #endif // wxUSE_SOCKETS
77 virtual bool Abort() = 0;
78 virtual wxInputStream
*GetInputStream(const wxString
& path
) = 0;
79 virtual wxProtocolError
GetError() = 0;
80 virtual wxString
GetContentType() { return wxEmptyString
; }
81 virtual void SetUser(const wxString
& WXUNUSED(user
)) {}
82 virtual void SetPassword(const wxString
& WXUNUSED(passwd
) ) {}
85 DECLARE_ABSTRACT_CLASS(wxProtocol
)
89 wxProtocolError WXDLLEXPORT
GetLine(wxSocketBase
*sock
, wxString
& result
);
92 // ----------------------------------------------------------------------------
93 // macros for protocol classes
94 // ----------------------------------------------------------------------------
96 #define DECLARE_PROTOCOL(class) \
98 static wxProtoInfo g_proto_##class;
100 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
101 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
102 bool wxProtocolUse##class = TRUE;
104 #define USE_PROTOCOL(class) \
105 extern bool wxProtocolUse##class ; \
106 static struct wxProtocolUserFor##class \
108 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
109 } wxProtocolDoUse##class;
111 class WXDLLEXPORT wxProtoInfo
: public wxObject
114 wxProtoInfo(const wxChar
*name
,
115 const wxChar
*serv_name
,
116 const bool need_host1
,
121 wxString m_protoname
;
124 wxClassInfo
*m_cinfo
;
129 DECLARE_DYNAMIC_CLASS(wxProtoInfo
)
130 DECLARE_NO_COPY_CLASS(wxProtoInfo
)
133 #endif // wxUSE_PROTOCOL
135 #endif // _WX_PROTOCOL_PROTOCOL_H