]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckipc.h
wxDialogBase only has one ctor, so just do initialization in ctor instead of Init()
[wxWidgets.git] / include / wx / sckipc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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 // Copyright: (c) Julian Smart 1993
10 // (c) Guilhem Lavaux 1997, 1998
11 // (c) 2000 Guillermo Rodriguez <guille@iies.es>
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
14
15 #ifndef _WX_SCKIPC_H
16 #define _WX_SCKIPC_H
17
18 #include "wx/defs.h"
19
20 #if wxUSE_SOCKETS && wxUSE_IPC
21
22 #include "wx/ipcbase.h"
23 #include "wx/socket.h"
24 #include "wx/sckstrm.h"
25 #include "wx/datstrm.h"
26
27 /*
28 * Mini-DDE implementation
29
30 Most transactions involve a topic name and an item name (choose these
31 as befits your application).
32
33 A client can:
34
35 - ask the server to execute commands (data) associated with a topic
36 - request data from server by topic and item
37 - poke data into the server
38 - ask the server to start an advice loop on topic/item
39 - ask the server to stop an advice loop
40
41 A server can:
42
43 - respond to execute, request, poke and advice start/stop
44 - send advise data to client
45
46 Note that this limits the server in the ways it can send data to the
47 client, i.e. it can't send unsolicited information.
48 *
49 */
50
51 class WXDLLIMPEXP_FWD_NET wxTCPServer;
52 class WXDLLIMPEXP_FWD_NET wxTCPClient;
53
54 class wxIPCSocketStreams;
55
56 class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase
57 {
58 public:
59 wxTCPConnection() { Init(); }
60 wxTCPConnection(void *buffer, size_t size)
61 : wxConnectionBase(buffer, size)
62 {
63 Init();
64 }
65
66 virtual ~wxTCPConnection();
67
68 // implement base class pure virtual methods
69 virtual const void *Request(const wxString& item,
70 size_t *size = NULL,
71 wxIPCFormat format = wxIPC_TEXT);
72 virtual bool StartAdvise(const wxString& item);
73 virtual bool StopAdvise(const wxString& item);
74 virtual bool Disconnect(void);
75
76 // Will be used in the future to enable the compression but does nothing
77 // for now.
78 void Compress(bool on);
79
80
81 protected:
82 virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
83 virtual bool DoPoke(const wxString& item, const void *data, size_t size,
84 wxIPCFormat format);
85 virtual bool DoAdvise(const wxString& item, const void *data, size_t size,
86 wxIPCFormat format);
87
88
89 // notice that all the members below are only initialized once the
90 // connection is made, i.e. in MakeConnection() for the client objects and
91 // after OnAcceptConnection() in the server ones
92
93 // the underlying socket (wxSocketClient for IPC client and wxSocketServer
94 // for IPC server)
95 wxSocketBase *m_sock;
96
97 // various streams that we use
98 wxIPCSocketStreams *m_streams;
99
100 // the topic of this connection
101 wxString m_topic;
102
103 private:
104 // common part of both ctors
105 void Init();
106
107 friend class wxTCPServer;
108 friend class wxTCPClient;
109 friend class wxTCPEventHandler;
110
111 wxDECLARE_NO_COPY_CLASS(wxTCPConnection);
112 DECLARE_DYNAMIC_CLASS(wxTCPConnection)
113 };
114
115 class WXDLLIMPEXP_NET wxTCPServer : public wxServerBase
116 {
117 public:
118 wxTCPServer();
119 virtual ~wxTCPServer();
120
121 // Returns false on error (e.g. port number is already in use)
122 virtual bool Create(const wxString& serverName);
123
124 virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
125
126 protected:
127 wxSocketServer *m_server;
128
129 #ifdef __UNIX_LIKE__
130 // the name of the file associated to the Unix domain socket, may be empty
131 wxString m_filename;
132 #endif // __UNIX_LIKE__
133
134 wxDECLARE_NO_COPY_CLASS(wxTCPServer);
135 DECLARE_DYNAMIC_CLASS(wxTCPServer)
136 };
137
138 class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase
139 {
140 public:
141 wxTCPClient();
142
143 virtual bool ValidHost(const wxString& host);
144
145 // Call this to make a connection. Returns NULL if cannot.
146 virtual wxConnectionBase *MakeConnection(const wxString& host,
147 const wxString& server,
148 const wxString& topic);
149
150 // Callbacks to CLIENT - override at will
151 virtual wxConnectionBase *OnMakeConnection();
152
153 private:
154 DECLARE_DYNAMIC_CLASS(wxTCPClient)
155 };
156
157 #endif // wxUSE_SOCKETS && wxUSE_IPC
158
159 #endif // _WX_SCKIPC_H