]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/protocol.h
OS/2 Statusbar fixes
[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 license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROTOCOL_PROTOCOL_H
13 #define _WX_PROTOCOL_PROTOCOL_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "wx/defs.h"
20
21 #include "wx/object.h"
22 #include "wx/string.h"
23 #include "wx/stream.h"
24
25 #if wxUSE_SOCKETS
26 #include "wx/socket.h"
27 #endif
28
29 // ----------------------------------------------------------------------------
30 // constants
31 // ----------------------------------------------------------------------------
32
33 typedef 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;
46
47 // ----------------------------------------------------------------------------
48 // wxProtocol: abstract base class for all protocols
49 // ----------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxProtocol
52 #if wxUSE_SOCKETS
53 : public wxSocketClient
54 #else
55 : public wxObject
56 #endif
57 {
58 public:
59 wxProtocol();
60
61 #if wxUSE_SOCKETS
62 bool Reconnect();
63 virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; }
64 virtual bool Connect( wxSockAddress& addr, bool WXUNUSED(wait) = TRUE) { return wxSocketClient::Connect(addr); }
65
66 // read a '\r\n' terminated line from the given socket and put it in
67 // result (without the terminators)
68 static wxProtocolError ReadLine(wxSocketBase *socket, wxString& result);
69
70 // read a line from this socket - this one can be overridden in the
71 // derived classes if different line termination convention is to be used
72 virtual wxProtocolError ReadLine(wxString& result);
73 #endif // wxUSE_SOCKETS
74
75 virtual bool Abort() = 0;
76 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
77 virtual wxProtocolError GetError() = 0;
78 virtual wxString GetContentType() { return wxEmptyString; }
79 virtual void SetUser(const wxString& WXUNUSED(user)) {}
80 virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
81
82 private:
83 DECLARE_ABSTRACT_CLASS(wxProtocol)
84 };
85
86 #if wxUSE_SOCKETS
87 wxProtocolError WXDLLEXPORT GetLine(wxSocketBase *sock, wxString& result);
88 #endif
89
90 // ----------------------------------------------------------------------------
91 // macros for protocol classes
92 // ----------------------------------------------------------------------------
93
94 #define DECLARE_PROTOCOL(class) \
95 public: \
96 static wxProtoInfo g_proto_##class;
97
98 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
99 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class));
100
101 class WXDLLEXPORT wxProtoInfo : public wxObject
102 {
103 public:
104 wxProtoInfo(const wxChar *name,
105 const wxChar *serv_name,
106 const bool need_host1,
107 wxClassInfo *info);
108
109 protected:
110 wxProtoInfo *next;
111 wxString m_protoname;
112 wxString prefix;
113 wxString m_servname;
114 wxClassInfo *m_cinfo;
115 bool m_needhost;
116
117 friend class wxURL;
118
119 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
120 };
121
122 #endif // _WX_PROTOCOL_PROTOCOL_H