Removing warnings
[wxWidgets.git] / include / wx / sckipc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sckipc.h
3 // Purpose: Interprocess communication implementation (wxSocket version)
4 // Author: Julian Smart
5 // Modified by: Guilhem Lavaux (big rewrite) May 1997, 1998
6 // Guillermo Rodriguez (updated for wxSocket v2) Jan 2000
7 // Created: 1993
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart 1993
10 // (c) Guilhem Lavaux 1997, 1998
11 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
14
15 #ifndef _WX_SCKIPC_H
16 #define _WX_SCKIPC_H
17
18 #ifdef __GNUG__
19 #pragma interface "sckipc.h"
20 #endif
21
22 #include "wx/defs.h"
23 #include "wx/setup.h"
24 #include "wx/ipcbase.h"
25 #include "wx/socket.h"
26 #include "wx/sckstrm.h"
27 #include "wx/datstrm.h"
28
29 /*
30 * Mini-DDE implementation
31
32 Most transactions involve a topic name and an item name (choose these
33 as befits your application).
34
35 A client can:
36
37 - ask the server to execute commands (data) associated with a topic
38 - request data from server by topic and item
39 - poke data into the server
40 - ask the server to start an advice loop on topic/item
41 - ask the server to stop an advice loop
42
43 A server can:
44
45 - respond to execute, request, poke and advice start/stop
46 - send advise data to client
47
48 Note that this limits the server in the ways it can send data to the
49 client, i.e. it can't send unsolicited information.
50 *
51 */
52
53 class WXDLLEXPORT wxTCPServer;
54 class WXDLLEXPORT wxTCPClient;
55
56 class WXDLLEXPORT wxTCPConnection: public wxConnectionBase
57 {
58 DECLARE_DYNAMIC_CLASS(wxTCPConnection)
59 public:
60 wxTCPConnection(char *buffer, int size);
61 wxTCPConnection();
62 virtual ~wxTCPConnection();
63
64 // Calls that CLIENT can make
65 virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
66 virtual bool Execute(const wxString& str) { return Execute(str, -1, wxIPC_TEXT); }
67 virtual char *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT);
68 virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
69 virtual bool StartAdvise(const wxString& item);
70 virtual bool StopAdvise(const wxString& item);
71
72 // Calls that SERVER can make
73 virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
74
75 // Calls that both can make
76 virtual bool Disconnect(void);
77
78 // Callbacks to SERVER - override at will
79 virtual bool OnExecute(const wxString& topic, char *data, int size, wxIPCFormat format)
80 { return wxConnectionBase::OnExecute(topic, data, size, format); };
81 virtual char *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format)
82 { return wxConnectionBase::OnRequest(topic, item, size, format); };
83 virtual bool OnPoke(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
84 { return wxConnectionBase::OnPoke(topic, item, data, size, format); };
85 virtual bool OnStartAdvise(const wxString& topic, const wxString& item)
86 { return wxConnectionBase::OnStartAdvise(topic, item); };
87 virtual bool OnStopAdvise(const wxString& topic, const wxString& item)
88 { return wxConnectionBase::OnStopAdvise(topic, item); };
89
90 // Callbacks to CLIENT - override at will
91 virtual bool OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
92 { return wxConnectionBase::OnAdvise(topic, item, data, size, format); };
93
94 // Callbacks to BOTH
95
96 // Default behaviour is to delete connection and return TRUE
97 virtual bool OnDisconnect(void) { delete this; return TRUE; }
98
99 // To enable the compressor
100 void Compress(bool on);
101
102 protected:
103 wxSocketBase *m_sock;
104 wxSocketStream *m_sockstrm;
105 wxDataInputStream *m_codeci;
106 wxDataOutputStream *m_codeco;
107 wxString m_topic;
108
109 friend class wxTCPServer;
110 friend class wxTCPClient;
111 friend void Client_OnRequest(wxSocketBase&,
112 wxSocketNotify, char *);
113 friend void Server_OnRequest(wxSocketServer&,
114 wxSocketNotify, char *);
115
116 private:
117 };
118
119 class wxTCPServer: public wxServerBase
120 {
121 DECLARE_DYNAMIC_CLASS(wxTCPServer)
122
123 public:
124 wxTCPConnection *topLevelConnection;
125
126 wxTCPServer();
127 virtual ~wxTCPServer();
128
129 // Returns FALSE if can't create server (e.g. port number is already in use)
130 virtual bool Create(const wxString& server_name);
131 virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
132 };
133
134 class wxTCPClient: public wxClientBase
135 {
136 DECLARE_DYNAMIC_CLASS(wxTCPClient)
137
138 public:
139 wxTCPClient();
140 virtual ~wxTCPClient();
141
142 virtual bool ValidHost(const wxString& host);
143 // Call this to make a connection.
144 // Returns NULL if cannot.
145 virtual wxConnectionBase *MakeConnection(const wxString& host,
146 const wxString& server,
147 const wxString& topic);
148
149 // Tailor this to return own connection.
150 virtual wxConnectionBase *OnMakeConnection();
151 };
152
153 #endif // ipcsock.h