]> git.saurik.com Git - wxWidgets.git/blame - include/wx/protocol/protocol.h
Use correct reload flags on all platforms to avoid compilation errors
[wxWidgets.git] / include / wx / protocol / protocol.h
CommitLineData
f4ada568 1/////////////////////////////////////////////////////////////////////////////
8e907a13 2// Name: wx/protocol/protocol.h
f4ada568
GL
3// Purpose: Protocol base class
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 10/07/1997
7// RCS-ID: $Id$
8// Copyright: (c) 1997, 1998 Guilhem Lavaux
65571936 9// Licence: wxWindows licence
f4ada568 10/////////////////////////////////////////////////////////////////////////////
8e907a13 11
f4ada568
GL
12#ifndef _WX_PROTOCOL_PROTOCOL_H
13#define _WX_PROTOCOL_PROTOCOL_H
14
e3e717ec
VZ
15#include "wx/defs.h"
16
a5d46b73
VZ
17#if wxUSE_PROTOCOL
18
f4ada568
GL
19#include "wx/object.h"
20#include "wx/string.h"
21#include "wx/stream.h"
8a4df159
RR
22
23#if wxUSE_SOCKETS
8e907a13 24 #include "wx/socket.h"
8a4df159 25#endif
f4ada568 26
0576cd9e
VZ
27class WXDLLIMPEXP_FWD_NET wxProtocolLog;
28
8e907a13
VZ
29// ----------------------------------------------------------------------------
30// constants
31// ----------------------------------------------------------------------------
f4ada568 32
8e907a13
VZ
33typedef enum
34{
35 wxPROTO_NOERR = 0,
36 wxPROTO_NETERR,
37 wxPROTO_PROTERR,
38 wxPROTO_CONNERR,
39 wxPROTO_INVVAL,
40 wxPROTO_NOHNDLR,
41 wxPROTO_NOFILE,
42 wxPROTO_ABRT,
43 wxPROTO_RCNCT,
44 wxPROTO_STREAMING
45} wxProtocolError;
f4ada568 46
8e907a13
VZ
47// ----------------------------------------------------------------------------
48// wxProtocol: abstract base class for all protocols
49// ----------------------------------------------------------------------------
f4ada568 50
7c4728f6 51class WXDLLIMPEXP_NET wxProtocol
8a4df159 52#if wxUSE_SOCKETS
8e907a13 53 : public wxSocketClient
8a4df159 54#else
8e907a13 55 : public wxObject
8a4df159 56#endif
8e907a13 57{
f4ada568 58public:
8e907a13 59 wxProtocol();
0576cd9e 60 virtual ~wxProtocol();
f4ada568 61
8a4df159 62#if wxUSE_SOCKETS
8e907a13 63 bool Reconnect();
730b772b
FM
64 virtual bool Connect( const wxString& WXUNUSED(host) ) { return false; }
65 virtual bool Connect( const wxSockAddress& addr, bool WXUNUSED(wait) = true)
ddc7f0c9 66 { return wxSocketClient::Connect(addr); }
8e907a13
VZ
67
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);
71
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
f4ada568 76
8e907a13
VZ
77 virtual bool Abort() = 0;
78 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
730b772b
FM
79 virtual wxString GetContentType() const = 0;
80
81 // the error code
82 virtual wxProtocolError GetError() const { return m_lastError; }
83
84 void SetUser(const wxString& user) { m_username = user; }
85 void SetPassword(const wxString& passwd) { m_password = passwd; }
86
87 virtual void SetDefaultTimeout(wxUint32 Value);
88
89 // override wxSocketBase::SetTimeout function to avoid that the internal
90 // m_uiDefaultTimeout goes out-of-sync:
91 virtual void SetTimeout(long seconds)
92 { SetDefaultTimeout(seconds); }
93
94
0576cd9e
VZ
95 // logging support: each wxProtocol object may have the associated logger
96 // (by default there is none) which is used to log network requests and
97 // responses
98
99 // set the logger, deleting the old one and taking ownership of this one
100 void SetLog(wxProtocolLog *log);
101
102 // return the current logger, may be NULL
103 wxProtocolLog *GetLog() const { return m_log; }
104
105 // detach the existing logger without deleting it, the caller is
106 // responsible for deleting the returned pointer if it's non-NULL
107 wxProtocolLog *DetachLog()
108 {
109 wxProtocolLog * const log = m_log;
110 m_log = NULL;
111 return log;
112 }
113
114 // these functions forward to the same functions with the same names in
115 // wxProtocolLog if we have a valid logger and do nothing otherwise
116 void LogRequest(const wxString& str);
117 void LogResponse(const wxString& str);
118
730b772b
FM
119protected:
120 // the timeout associated with the protocol:
121 wxUint32 m_uiDefaultTimeout;
122
123 wxString m_username;
124 wxString m_password;
125
126 // this must be always updated by the derived classes!
127 wxProtocolError m_lastError;
8e907a13
VZ
128
129private:
0576cd9e
VZ
130 wxProtocolLog *m_log;
131
fc7a2a60 132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
f4ada568
GL
133};
134
8e907a13
VZ
135// ----------------------------------------------------------------------------
136// macros for protocol classes
137// ----------------------------------------------------------------------------
138
139#define DECLARE_PROTOCOL(class) \
140public: \
141 static wxProtoInfo g_proto_##class;
142
143#define IMPLEMENT_PROTOCOL(class, name, serv, host) \
b19b28c8 144wxProtoInfo class::g_proto_##class(name, serv, host, wxCLASSINFO(class)); \
8e6efd1f 145bool wxProtocolUse##class = true;
f92f546c
VS
146
147#define USE_PROTOCOL(class) \
148 extern bool wxProtocolUse##class ; \
149 static struct wxProtocolUserFor##class \
150 { \
8e6efd1f 151 wxProtocolUserFor##class() { wxProtocolUse##class = true; } \
f92f546c 152 } wxProtocolDoUse##class;
8e907a13 153
7c4728f6 154class WXDLLIMPEXP_NET wxProtoInfo : public wxObject
8e907a13
VZ
155{
156public:
157 wxProtoInfo(const wxChar *name,
158 const wxChar *serv_name,
159 const bool need_host1,
160 wxClassInfo *info);
161
162protected:
163 wxProtoInfo *next;
164 wxString m_protoname;
165 wxString prefix;
166 wxString m_servname;
167 wxClassInfo *m_cinfo;
168 bool m_needhost;
169
170 friend class wxURL;
171
172 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
c0c133e1 173 wxDECLARE_NO_COPY_CLASS(wxProtoInfo);
8e907a13
VZ
174};
175
a5d46b73
VZ
176#endif // wxUSE_PROTOCOL
177
e3e717ec 178#endif // _WX_PROTOCOL_PROTOCOL_H