]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sckipc.h | |
0834112f GRG |
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 | |
cdc59bb6 | 7 | // (callbacks deprecated) Mar 2000 |
f4ada568 GL |
8 | // Created: 1993 |
9 | // RCS-ID: $Id$ | |
0834112f GRG |
10 | // Copyright: (c) Julian Smart 1993 |
11 | // (c) Guilhem Lavaux 1997, 1998 | |
12 | // (c) 2000 Guillermo Rodriguez <guille@iies.es> | |
65571936 | 13 | // Licence: wxWindows licence |
f4ada568 | 14 | ///////////////////////////////////////////////////////////////////////////// |
07e829dc | 15 | |
f4ada568 GL |
16 | #ifndef _WX_SCKIPC_H |
17 | #define _WX_SCKIPC_H | |
18 | ||
f4ada568 | 19 | #include "wx/defs.h" |
26dfedc4 | 20 | |
cdc59bb6 | 21 | #if wxUSE_SOCKETS && wxUSE_IPC |
26dfedc4 | 22 | |
f4ada568 GL |
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 | ||
b5dbe15d VS |
52 | class WXDLLIMPEXP_FWD_NET wxTCPServer; |
53 | class WXDLLIMPEXP_FWD_NET wxTCPClient; | |
07e829dc | 54 | |
50c549b9 | 55 | class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase |
f4ada568 | 56 | { |
f4ada568 | 57 | public: |
50c549b9 | 58 | wxTCPConnection(void *buffer, size_t size); |
f4ada568 GL |
59 | wxTCPConnection(); |
60 | virtual ~wxTCPConnection(); | |
61 | ||
50c549b9 VZ |
62 | // To enable the compressor (NOTE: not implemented!) |
63 | void Compress(bool on); | |
f4ada568 | 64 | |
f4ada568 | 65 | |
50c549b9 VZ |
66 | // implement base class pure virtual methods |
67 | virtual const void *Request(const wxString& item, | |
68 | size_t *size = NULL, | |
69 | wxIPCFormat format = wxIPC_TEXT); | |
70 | virtual bool StartAdvise(const wxString& item); | |
71 | virtual bool StopAdvise(const wxString& item); | |
0834112f | 72 | virtual bool Disconnect(void); |
f4ada568 | 73 | |
50c549b9 VZ |
74 | protected: |
75 | virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format); | |
76 | virtual bool DoPoke(const wxString& item, const void *data, size_t size, | |
77 | wxIPCFormat format); | |
78 | virtual bool DoAdvise(const wxString& item, const void *data, size_t size, | |
79 | wxIPCFormat format); | |
0834112f | 80 | |
f784a2a9 | 81 | |
f6bcfd97 BP |
82 | wxSocketBase *m_sock; |
83 | wxSocketStream *m_sockstrm; | |
84 | wxDataInputStream *m_codeci; | |
07e829dc | 85 | wxDataOutputStream *m_codeco; |
f6bcfd97 | 86 | wxString m_topic; |
07e829dc GRG |
87 | |
88 | friend class wxTCPServer; | |
89 | friend class wxTCPClient; | |
cdc59bb6 | 90 | friend class wxTCPEventHandler; |
07e829dc | 91 | |
f784a2a9 | 92 | DECLARE_NO_COPY_CLASS(wxTCPConnection) |
50c549b9 | 93 | DECLARE_DYNAMIC_CLASS(wxTCPConnection) |
f4ada568 GL |
94 | }; |
95 | ||
50c549b9 | 96 | class WXDLLIMPEXP_NET wxTCPServer : public wxServerBase |
f4ada568 | 97 | { |
f4ada568 | 98 | public: |
f4ada568 GL |
99 | wxTCPServer(); |
100 | virtual ~wxTCPServer(); | |
54da4255 | 101 | |
d775fa82 | 102 | // Returns false on error (e.g. port number is already in use) |
f6bcfd97 BP |
103 | virtual bool Create(const wxString& serverName); |
104 | ||
f4ada568 | 105 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); |
f6bcfd97 | 106 | |
50c549b9 VZ |
107 | wxTCPConnection *topLevelConnection; |
108 | ||
f6bcfd97 BP |
109 | protected: |
110 | wxSocketServer *m_server; | |
0dbfd66d VZ |
111 | |
112 | #ifdef __UNIX_LIKE__ | |
113 | // the name of the file associated to the Unix domain socket, may be empty | |
114 | wxString m_filename; | |
115 | #endif // __UNIX_LIKE__ | |
22f3361e | 116 | |
f784a2a9 VZ |
117 | DECLARE_NO_COPY_CLASS(wxTCPServer) |
118 | DECLARE_DYNAMIC_CLASS(wxTCPServer) | |
f4ada568 GL |
119 | }; |
120 | ||
50c549b9 | 121 | class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase |
f4ada568 | 122 | { |
54da4255 | 123 | public: |
f4ada568 GL |
124 | wxTCPClient(); |
125 | virtual ~wxTCPClient(); | |
126 | ||
127 | virtual bool ValidHost(const wxString& host); | |
f6bcfd97 BP |
128 | |
129 | // Call this to make a connection. Returns NULL if cannot. | |
f4ada568 GL |
130 | virtual wxConnectionBase *MakeConnection(const wxString& host, |
131 | const wxString& server, | |
132 | const wxString& topic); | |
54da4255 | 133 | |
f6bcfd97 | 134 | // Callbacks to CLIENT - override at will |
f4ada568 | 135 | virtual wxConnectionBase *OnMakeConnection(); |
f784a2a9 VZ |
136 | |
137 | private: | |
138 | DECLARE_DYNAMIC_CLASS(wxTCPClient) | |
f4ada568 GL |
139 | }; |
140 | ||
cdc59bb6 | 141 | #endif // wxUSE_SOCKETS && wxUSE_IPC |
26dfedc4 | 142 | |
cdc59bb6 | 143 | #endif // _WX_SCKIPC_H |