]> git.saurik.com Git - wxWidgets.git/blame - include/wx/protocol/protocol.h
Committing in .
[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
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
f4ada568
GL
16#pragma interface
17#endif
18
e3e717ec
VZ
19#include "wx/defs.h"
20
a5d46b73
VZ
21#if wxUSE_PROTOCOL
22
f4ada568
GL
23#include "wx/object.h"
24#include "wx/string.h"
25#include "wx/stream.h"
8a4df159
RR
26
27#if wxUSE_SOCKETS
8e907a13 28 #include "wx/socket.h"
8a4df159 29#endif
f4ada568 30
8e907a13
VZ
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
f4ada568 34
8e907a13
VZ
35typedef enum
36{
37 wxPROTO_NOERR = 0,
38 wxPROTO_NETERR,
39 wxPROTO_PROTERR,
40 wxPROTO_CONNERR,
41 wxPROTO_INVVAL,
42 wxPROTO_NOHNDLR,
43 wxPROTO_NOFILE,
44 wxPROTO_ABRT,
45 wxPROTO_RCNCT,
46 wxPROTO_STREAMING
47} wxProtocolError;
f4ada568 48
8e907a13
VZ
49// ----------------------------------------------------------------------------
50// wxProtocol: abstract base class for all protocols
51// ----------------------------------------------------------------------------
f4ada568 52
7c4728f6 53class WXDLLIMPEXP_NET wxProtocol
8a4df159 54#if wxUSE_SOCKETS
8e907a13 55 : public wxSocketClient
8a4df159 56#else
8e907a13 57 : public wxObject
8a4df159 58#endif
8e907a13 59{
f4ada568 60public:
8e907a13 61 wxProtocol();
f4ada568 62
8a4df159 63#if wxUSE_SOCKETS
8e907a13
VZ
64 bool Reconnect();
65 virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; }
66 virtual bool Connect( wxSockAddress& addr, bool WXUNUSED(wait) = TRUE) { return wxSocketClient::Connect(addr); }
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;
79 virtual wxProtocolError GetError() = 0;
80 virtual wxString GetContentType() { return wxEmptyString; }
81 virtual void SetUser(const wxString& WXUNUSED(user)) {}
82 virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
83
84private:
fc7a2a60 85 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
f4ada568
GL
86};
87
8a4df159 88#if wxUSE_SOCKETS
7c4728f6 89wxProtocolError WXDLLIMPEXP_NET GetLine(wxSocketBase *sock, wxString& result);
8a4df159 90#endif
e3e717ec 91
8e907a13
VZ
92// ----------------------------------------------------------------------------
93// macros for protocol classes
94// ----------------------------------------------------------------------------
95
96#define DECLARE_PROTOCOL(class) \
97public: \
98 static wxProtoInfo g_proto_##class;
99
100#define IMPLEMENT_PROTOCOL(class, name, serv, host) \
f92f546c
VS
101wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
102bool wxProtocolUse##class = TRUE;
103
104#define USE_PROTOCOL(class) \
105 extern bool wxProtocolUse##class ; \
106 static struct wxProtocolUserFor##class \
107 { \
108 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
109 } wxProtocolDoUse##class;
8e907a13 110
7c4728f6 111class WXDLLIMPEXP_NET wxProtoInfo : public wxObject
8e907a13
VZ
112{
113public:
114 wxProtoInfo(const wxChar *name,
115 const wxChar *serv_name,
116 const bool need_host1,
117 wxClassInfo *info);
118
119protected:
120 wxProtoInfo *next;
121 wxString m_protoname;
122 wxString prefix;
123 wxString m_servname;
124 wxClassInfo *m_cinfo;
125 bool m_needhost;
126
127 friend class wxURL;
128
129 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
22f3361e 130 DECLARE_NO_COPY_CLASS(wxProtoInfo)
8e907a13
VZ
131};
132
a5d46b73
VZ
133#endif // wxUSE_PROTOCOL
134
e3e717ec 135#endif // _WX_PROTOCOL_PROTOCOL_H