]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckipc.h
corrected code to really skip stack frames in the beginning and to number the remaini...
[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 // (callbacks deprecated) Mar 2000
8 // Created: 1993
9 // RCS-ID: $Id$
10 // Copyright: (c) Julian Smart 1993
11 // (c) Guilhem Lavaux 1997, 1998
12 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
13 // Licence: wxWindows licence
14 /////////////////////////////////////////////////////////////////////////////
15
16 #ifndef _WX_SCKIPC_H
17 #define _WX_SCKIPC_H
18
19 #include "wx/defs.h"
20
21 #if wxUSE_SOCKETS && wxUSE_IPC
22
23 #include "wx/ipcbase.h"
24 #include "wx/socket.h"
25 #include "wx/sckstrm.h"
26 #include "wx/datstrm.h"
27
28 /*
29 * Mini-DDE implementation
30
31 Most transactions involve a topic name and an item name (choose these
32 as befits your application).
33
34 A client can:
35
36 - ask the server to execute commands (data) associated with a topic
37 - request data from server by topic and item
38 - poke data into the server
39 - ask the server to start an advice loop on topic/item
40 - ask the server to stop an advice loop
41
42 A server can:
43
44 - respond to execute, request, poke and advice start/stop
45 - send advise data to client
46
47 Note that this limits the server in the ways it can send data to the
48 client, i.e. it can't send unsolicited information.
49 *
50 */
51
52 class WXDLLIMPEXP_NET wxTCPServer;
53 class WXDLLIMPEXP_NET wxTCPClient;
54
55 class WXDLLIMPEXP_NET wxTCPConnection: public wxConnectionBase
56 {
57 DECLARE_DYNAMIC_CLASS(wxTCPConnection)
58
59 public:
60 wxTCPConnection(wxChar *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 wxChar *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT);
67 virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
68 virtual bool StartAdvise(const wxString& item);
69 virtual bool StopAdvise(const wxString& item);
70
71 // Calls that SERVER can make
72 virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
73
74 // Calls that both can make
75 virtual bool Disconnect(void);
76
77 // Callbacks to BOTH - override at will
78 // Default behaviour is to delete connection and return true
79 virtual bool OnDisconnect(void) { delete this; return true; }
80
81 // To enable the compressor (NOTE: not implemented!)
82 void Compress(bool on);
83
84 protected:
85 wxSocketBase *m_sock;
86 wxSocketStream *m_sockstrm;
87 wxDataInputStream *m_codeci;
88 wxDataOutputStream *m_codeco;
89 wxString m_topic;
90
91 friend class wxTCPServer;
92 friend class wxTCPClient;
93 friend class wxTCPEventHandler;
94
95 private:
96 //
97 // We're hiding an Execute method in ConnectionBase
98 //
99 virtual bool Execute(const wxString& str)
100 { return Execute(str, -1, wxIPC_TEXT); }
101
102 DECLARE_NO_COPY_CLASS(wxTCPConnection)
103 };
104
105 class WXDLLIMPEXP_NET wxTCPServer: public wxServerBase
106 {
107 DECLARE_DYNAMIC_CLASS(wxTCPServer)
108
109 public:
110 wxTCPConnection *topLevelConnection;
111
112 wxTCPServer();
113 virtual ~wxTCPServer();
114
115 // Returns false on error (e.g. port number is already in use)
116 virtual bool Create(const wxString& serverName);
117
118 // Callbacks to SERVER - override at will
119 virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
120
121 protected:
122 wxSocketServer *m_server;
123
124 #ifdef __UNIX_LIKE__
125 // the name of the file associated to the Unix domain socket, may be empty
126 wxString m_filename;
127 #endif // __UNIX_LIKE__
128
129 DECLARE_NO_COPY_CLASS(wxTCPServer)
130 };
131
132 class WXDLLIMPEXP_NET wxTCPClient: public wxClientBase
133 {
134 DECLARE_DYNAMIC_CLASS(wxTCPClient)
135
136 public:
137 wxTCPClient();
138 virtual ~wxTCPClient();
139
140 virtual bool ValidHost(const wxString& host);
141
142 // Call this to make a connection. Returns NULL if cannot.
143 virtual wxConnectionBase *MakeConnection(const wxString& host,
144 const wxString& server,
145 const wxString& topic);
146
147 // Callbacks to CLIENT - override at will
148 virtual wxConnectionBase *OnMakeConnection();
149 };
150
151 #endif // wxUSE_SOCKETS && wxUSE_IPC
152
153 #endif // _WX_SCKIPC_H