no real changes, just reformat before starting really modifying
[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_FWD_NET wxTCPServer;
53 class WXDLLIMPEXP_FWD_NET wxTCPClient;
54
55 class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase
56 {
57 public:
58 wxTCPConnection() { Init(); }
59 wxTCPConnection(void *buffer, size_t size)
60 : wxConnectionBase(buffer, size)
61 {
62 Init();
63 }
64
65 virtual ~wxTCPConnection();
66
67 // implement base class pure virtual methods
68 virtual const void *Request(const wxString& item,
69 size_t *size = NULL,
70 wxIPCFormat format = wxIPC_TEXT);
71 virtual bool StartAdvise(const wxString& item);
72 virtual bool StopAdvise(const wxString& item);
73 virtual bool Disconnect(void);
74
75 // Will be used in the future to enable the compression but does nothing
76 // for now.
77 void Compress(bool on);
78
79
80 protected:
81 virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
82 virtual bool DoPoke(const wxString& item, const void *data, size_t size,
83 wxIPCFormat format);
84 virtual bool DoAdvise(const wxString& item, const void *data, size_t size,
85 wxIPCFormat format);
86
87
88 wxSocketBase *m_sock;
89 wxSocketStream *m_sockstrm;
90 wxDataInputStream *m_codeci;
91 wxDataOutputStream *m_codeco;
92 wxString m_topic;
93
94 private:
95 // common part of both ctors
96 void Init();
97
98 friend class wxTCPServer;
99 friend class wxTCPClient;
100 friend class wxTCPEventHandler;
101
102 DECLARE_NO_COPY_CLASS(wxTCPConnection)
103 DECLARE_DYNAMIC_CLASS(wxTCPConnection)
104 };
105
106 class WXDLLIMPEXP_NET wxTCPServer : public wxServerBase
107 {
108 public:
109 wxTCPServer();
110 virtual ~wxTCPServer();
111
112 // Returns false on error (e.g. port number is already in use)
113 virtual bool Create(const wxString& serverName);
114
115 virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
116
117 protected:
118 wxSocketServer *m_server;
119
120 #ifdef __UNIX_LIKE__
121 // the name of the file associated to the Unix domain socket, may be empty
122 wxString m_filename;
123 #endif // __UNIX_LIKE__
124
125 DECLARE_NO_COPY_CLASS(wxTCPServer)
126 DECLARE_DYNAMIC_CLASS(wxTCPServer)
127 };
128
129 class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase
130 {
131 public:
132 wxTCPClient();
133
134 virtual bool ValidHost(const wxString& host);
135
136 // Call this to make a connection. Returns NULL if cannot.
137 virtual wxConnectionBase *MakeConnection(const wxString& host,
138 const wxString& server,
139 const wxString& topic);
140
141 // Callbacks to CLIENT - override at will
142 virtual wxConnectionBase *OnMakeConnection();
143
144 private:
145 DECLARE_DYNAMIC_CLASS(wxTCPClient)
146 };
147
148 #endif // wxUSE_SOCKETS && wxUSE_IPC
149
150 #endif // _WX_SCKIPC_H