]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/protocol.h
For clarity, moved includes to the top of the file. Also added #include wx/dialog.h.
[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 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROTOCOL_PROTOCOL_H
13 #define _WX_PROTOCOL_PROTOCOL_H
14
15 #include "wx/defs.h"
16
17 #if wxUSE_PROTOCOL
18
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/stream.h"
22
23 #if wxUSE_SOCKETS
24 #include "wx/socket.h"
25 #endif
26
27 // ----------------------------------------------------------------------------
28 // constants
29 // ----------------------------------------------------------------------------
30
31 typedef enum
32 {
33 wxPROTO_NOERR = 0,
34 wxPROTO_NETERR,
35 wxPROTO_PROTERR,
36 wxPROTO_CONNERR,
37 wxPROTO_INVVAL,
38 wxPROTO_NOHNDLR,
39 wxPROTO_NOFILE,
40 wxPROTO_ABRT,
41 wxPROTO_RCNCT,
42 wxPROTO_STREAMING
43 } wxProtocolError;
44
45 // ----------------------------------------------------------------------------
46 // wxProtocol: abstract base class for all protocols
47 // ----------------------------------------------------------------------------
48
49 class WXDLLIMPEXP_NET wxProtocol
50 #if wxUSE_SOCKETS
51 : public wxSocketClient
52 #else
53 : public wxObject
54 #endif
55 {
56 public:
57 wxProtocol();
58
59 #if wxUSE_SOCKETS
60 bool Reconnect();
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); }
64
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);
68
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
73
74 virtual bool Abort() = 0;
75 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
76 virtual wxProtocolError GetError() = 0;
77 virtual wxString GetContentType() { return wxEmptyString; }
78 virtual void SetUser(const wxString& WXUNUSED(user)) {}
79 virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
80
81 private:
82 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
83 };
84
85 // ----------------------------------------------------------------------------
86 // macros for protocol classes
87 // ----------------------------------------------------------------------------
88
89 #define DECLARE_PROTOCOL(class) \
90 public: \
91 static wxProtoInfo g_proto_##class;
92
93 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
94 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
95 bool wxProtocolUse##class = TRUE;
96
97 #define USE_PROTOCOL(class) \
98 extern bool wxProtocolUse##class ; \
99 static struct wxProtocolUserFor##class \
100 { \
101 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
102 } wxProtocolDoUse##class;
103
104 class WXDLLIMPEXP_NET wxProtoInfo : public wxObject
105 {
106 public:
107 wxProtoInfo(const wxChar *name,
108 const wxChar *serv_name,
109 const bool need_host1,
110 wxClassInfo *info);
111
112 protected:
113 wxProtoInfo *next;
114 wxString m_protoname;
115 wxString prefix;
116 wxString m_servname;
117 wxClassInfo *m_cinfo;
118 bool m_needhost;
119
120 friend class wxURL;
121
122 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
123 DECLARE_NO_COPY_CLASS(wxProtoInfo)
124 };
125
126 #endif // wxUSE_PROTOCOL
127
128 #endif // _WX_PROTOCOL_PROTOCOL_H