]>
Commit | Line | Data |
---|---|---|
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 | |
8e907a13 VZ |
27 | // ---------------------------------------------------------------------------- |
28 | // constants | |
29 | // ---------------------------------------------------------------------------- | |
f4ada568 | 30 | |
8e907a13 VZ |
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; | |
f4ada568 | 44 | |
8e907a13 VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // wxProtocol: abstract base class for all protocols | |
47 | // ---------------------------------------------------------------------------- | |
f4ada568 | 48 | |
7c4728f6 | 49 | class WXDLLIMPEXP_NET wxProtocol |
8a4df159 | 50 | #if wxUSE_SOCKETS |
8e907a13 | 51 | : public wxSocketClient |
8a4df159 | 52 | #else |
8e907a13 | 53 | : public wxObject |
8a4df159 | 54 | #endif |
8e907a13 | 55 | { |
f4ada568 | 56 | public: |
8e907a13 | 57 | wxProtocol(); |
f4ada568 | 58 | |
8a4df159 | 59 | #if wxUSE_SOCKETS |
8e907a13 VZ |
60 | bool Reconnect(); |
61 | virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; } | |
62 | virtual bool Connect( wxSockAddress& addr, bool WXUNUSED(wait) = TRUE) { return wxSocketClient::Connect(addr); } | |
63 | ||
64 | // read a '\r\n' terminated line from the given socket and put it in | |
65 | // result (without the terminators) | |
66 | static wxProtocolError ReadLine(wxSocketBase *socket, wxString& result); | |
67 | ||
68 | // read a line from this socket - this one can be overridden in the | |
69 | // derived classes if different line termination convention is to be used | |
70 | virtual wxProtocolError ReadLine(wxString& result); | |
71 | #endif // wxUSE_SOCKETS | |
f4ada568 | 72 | |
8e907a13 VZ |
73 | virtual bool Abort() = 0; |
74 | virtual wxInputStream *GetInputStream(const wxString& path) = 0; | |
75 | virtual wxProtocolError GetError() = 0; | |
76 | virtual wxString GetContentType() { return wxEmptyString; } | |
77 | virtual void SetUser(const wxString& WXUNUSED(user)) {} | |
78 | virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {} | |
79 | ||
80 | private: | |
fc7a2a60 | 81 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol) |
f4ada568 GL |
82 | }; |
83 | ||
8e907a13 VZ |
84 | // ---------------------------------------------------------------------------- |
85 | // macros for protocol classes | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | #define DECLARE_PROTOCOL(class) \ | |
89 | public: \ | |
90 | static wxProtoInfo g_proto_##class; | |
91 | ||
92 | #define IMPLEMENT_PROTOCOL(class, name, serv, host) \ | |
f92f546c VS |
93 | wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \ |
94 | bool wxProtocolUse##class = TRUE; | |
95 | ||
96 | #define USE_PROTOCOL(class) \ | |
97 | extern bool wxProtocolUse##class ; \ | |
98 | static struct wxProtocolUserFor##class \ | |
99 | { \ | |
100 | wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \ | |
101 | } wxProtocolDoUse##class; | |
8e907a13 | 102 | |
7c4728f6 | 103 | class WXDLLIMPEXP_NET wxProtoInfo : public wxObject |
8e907a13 VZ |
104 | { |
105 | public: | |
106 | wxProtoInfo(const wxChar *name, | |
107 | const wxChar *serv_name, | |
108 | const bool need_host1, | |
109 | wxClassInfo *info); | |
110 | ||
111 | protected: | |
112 | wxProtoInfo *next; | |
113 | wxString m_protoname; | |
114 | wxString prefix; | |
115 | wxString m_servname; | |
116 | wxClassInfo *m_cinfo; | |
117 | bool m_needhost; | |
118 | ||
119 | friend class wxURL; | |
120 | ||
121 | DECLARE_DYNAMIC_CLASS(wxProtoInfo) | |
22f3361e | 122 | DECLARE_NO_COPY_CLASS(wxProtoInfo) |
8e907a13 VZ |
123 | }; |
124 | ||
a5d46b73 VZ |
125 | #endif // wxUSE_PROTOCOL |
126 | ||
e3e717ec | 127 | #endif // _WX_PROTOCOL_PROTOCOL_H |