]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | #if wxUSE_SOCKETS | |
25 | ||
26 | #include "wx/ipcbase.h" | |
27 | #include "wx/socket.h" | |
28 | #include "wx/sckstrm.h" | |
29 | #include "wx/datstrm.h" | |
30 | ||
31 | /* | |
32 | * Mini-DDE implementation | |
33 | ||
34 | Most transactions involve a topic name and an item name (choose these | |
35 | as befits your application). | |
36 | ||
37 | A client can: | |
38 | ||
39 | - ask the server to execute commands (data) associated with a topic | |
40 | - request data from server by topic and item | |
41 | - poke data into the server | |
42 | - ask the server to start an advice loop on topic/item | |
43 | - ask the server to stop an advice loop | |
44 | ||
45 | A server can: | |
46 | ||
47 | - respond to execute, request, poke and advice start/stop | |
48 | - send advise data to client | |
49 | ||
50 | Note that this limits the server in the ways it can send data to the | |
51 | client, i.e. it can't send unsolicited information. | |
52 | * | |
53 | */ | |
54 | ||
55 | class WXDLLEXPORT wxTCPServer; | |
56 | class WXDLLEXPORT wxTCPClient; | |
57 | ||
58 | class WXDLLEXPORT wxTCPConnection: public wxConnectionBase | |
59 | { | |
60 | DECLARE_DYNAMIC_CLASS(wxTCPConnection) | |
61 | public: | |
62 | wxTCPConnection(char *buffer, int size); | |
63 | wxTCPConnection(); | |
64 | virtual ~wxTCPConnection(); | |
65 | ||
66 | // Calls that CLIENT can make | |
67 | virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); | |
68 | virtual char *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT); | |
69 | virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); | |
70 | virtual bool StartAdvise(const wxString& item); | |
71 | virtual bool StopAdvise(const wxString& item); | |
72 | ||
73 | // Calls that SERVER can make | |
74 | virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); | |
75 | ||
76 | // Calls that both can make | |
77 | virtual bool Disconnect(void); | |
78 | ||
79 | // Default behaviour is to delete connection and return TRUE | |
80 | virtual bool OnDisconnect(void) { delete this; return TRUE; } | |
81 | ||
82 | // To enable the compressor | |
83 | void Compress(bool on); | |
84 | ||
85 | protected: | |
86 | wxSocketBase *m_sock; | |
87 | wxSocketStream *m_sockstrm; | |
88 | wxDataInputStream *m_codeci; | |
89 | wxDataOutputStream *m_codeco; | |
90 | wxString m_topic; | |
91 | ||
92 | friend class wxTCPServer; | |
93 | friend class wxTCPClient; | |
94 | friend void Client_OnRequest(wxSocketBase&, | |
95 | wxSocketNotify, char *); | |
96 | friend void Server_OnRequest(wxSocketServer&, | |
97 | wxSocketNotify, char *); | |
98 | ||
99 | private: | |
100 | // | |
101 | // We're hiding an Execute method in ConnectionBase | |
102 | //s | |
103 | virtual bool Execute(const wxString& str) | |
104 | { return Execute(str, -1, wxIPC_TEXT); } | |
105 | }; | |
106 | ||
107 | class wxTCPServer: public wxServerBase | |
108 | { | |
109 | DECLARE_DYNAMIC_CLASS(wxTCPServer) | |
110 | ||
111 | public: | |
112 | wxTCPConnection *topLevelConnection; | |
113 | ||
114 | wxTCPServer(); | |
115 | virtual ~wxTCPServer(); | |
116 | ||
117 | // Returns FALSE if can't create server (e.g. port number is already in use) | |
118 | virtual bool Create(const wxString& server_name); | |
119 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); | |
120 | }; | |
121 | ||
122 | class wxTCPClient: public wxClientBase | |
123 | { | |
124 | DECLARE_DYNAMIC_CLASS(wxTCPClient) | |
125 | ||
126 | public: | |
127 | wxTCPClient(); | |
128 | virtual ~wxTCPClient(); | |
129 | ||
130 | virtual bool ValidHost(const wxString& host); | |
131 | // Call this to make a connection. | |
132 | // Returns NULL if cannot. | |
133 | virtual wxConnectionBase *MakeConnection(const wxString& host, | |
134 | const wxString& server, | |
135 | const wxString& topic); | |
136 | ||
137 | // Tailor this to return own connection. | |
138 | virtual wxConnectionBase *OnMakeConnection(); | |
139 | }; | |
140 | ||
141 | #endif // wxUSE_SOCKETS | |
142 | ||
143 | #endif // ipcsock.h |