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