]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sckipc.h | |
3 | // Purpose: Interprocess communication | |
4 | // Author: Julian Smart/Guilhem Lavaux (big rewrite) | |
5 | // Modified by: Guilhem Lavaux 1997 | |
6 | // Created: 1993 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1993 Julian Smart | |
9 | // (c) 1997, 1998 Guilhem Lavaux | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | #ifndef _WX_SCKIPC_H | |
13 | #define _WX_SCKIPC_H | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/setup.h" | |
21 | #include "wx/ipcbase.h" | |
22 | #include "wx/socket.h" | |
23 | #include "wx/sckstrm.h" | |
24 | #include "wx/datstrm.h" | |
25 | ||
26 | /* | |
27 | * Mini-DDE implementation | |
28 | ||
29 | Most transactions involve a topic name and an item name (choose these | |
30 | as befits your application). | |
31 | ||
32 | A client can: | |
33 | ||
34 | - ask the server to execute commands (data) associated with a topic | |
35 | - request data from server by topic and item | |
36 | - poke data into the server | |
37 | - ask the server to start an advice loop on topic/item | |
38 | - ask the server to stop an advice loop | |
39 | ||
40 | A server can: | |
41 | ||
42 | - respond to execute, request, poke and advice start/stop | |
43 | - send advise data to client | |
44 | ||
45 | Note that this limits the server in the ways it can send data to the | |
46 | client, i.e. it can't send unsolicited information. | |
47 | * | |
48 | */ | |
49 | ||
50 | class wxTCPServer; | |
51 | class wxTCPClient; | |
52 | class wxTCPConnection: public wxConnectionBase | |
53 | { | |
54 | DECLARE_DYNAMIC_CLASS(wxTCPConnection) | |
55 | ||
56 | protected: | |
57 | wxSocketBase *m_sock; | |
58 | wxSocketStream *m_sockstrm; | |
59 | wxDataStream *m_codec; | |
60 | wxString m_topic; | |
61 | ||
62 | friend class wxTCPServer; | |
63 | friend class wxTCPClient; | |
64 | friend void Client_OnRequest(wxSocketBase&, | |
65 | wxSocketBase::wxRequestEvent, char *); | |
66 | friend void Server_OnRequest(wxSocketServer&, | |
67 | wxSocketBase::wxRequestEvent, char *); | |
68 | public: | |
69 | ||
70 | wxTCPConnection(char *buffer, int size); | |
71 | wxTCPConnection(); | |
72 | virtual ~wxTCPConnection(); | |
73 | ||
74 | // Calls that CLIENT can make | |
75 | bool Execute(char *data, int size = -1, | |
76 | wxDataFormat format = wxDF_TEXT); | |
77 | char *Request(const wxString& item, int *size = NULL, | |
78 | wxDataFormat format = wxDF_TEXT); | |
79 | bool Poke(const wxString& item, char *data, int size = -1, | |
80 | wxDataFormat format = wxDF_TEXT); | |
81 | bool StartAdvise(const wxString& item); | |
82 | bool StopAdvise(const wxString& item); | |
83 | ||
84 | // Calls that SERVER can make | |
85 | bool Advise(const wxString& item, char *data, int size = -1, | |
86 | wxDataFormat format = wxDF_TEXT); | |
87 | ||
88 | // Calls that both can make | |
89 | bool Disconnect(); | |
90 | ||
91 | // Called when we lost the peer. | |
92 | bool OnDisconnect() { return TRUE; } | |
93 | ||
94 | // To enable the compressor | |
95 | void Compress(bool on); | |
96 | }; | |
97 | ||
98 | class wxTCPServer: public wxServerBase | |
99 | { | |
100 | DECLARE_DYNAMIC_CLASS(wxTCPServer) | |
101 | ||
102 | public: | |
103 | wxTCPConnection *topLevelConnection; | |
104 | ||
105 | wxTCPServer(); | |
106 | virtual ~wxTCPServer(); | |
107 | ||
108 | // Returns FALSE if can't create server (e.g. port number is already in use) | |
109 | virtual bool Create(const wxString& server_name); | |
110 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); | |
111 | }; | |
112 | ||
113 | class wxTCPClient: public wxClientBase | |
114 | { | |
115 | DECLARE_DYNAMIC_CLASS(wxTCPClient) | |
116 | ||
117 | public: | |
118 | wxTCPClient(); | |
119 | virtual ~wxTCPClient(); | |
120 | ||
121 | virtual bool ValidHost(const wxString& host); | |
122 | // Call this to make a connection. | |
123 | // Returns NULL if cannot. | |
124 | virtual wxConnectionBase *MakeConnection(const wxString& host, | |
125 | const wxString& server, | |
126 | const wxString& topic); | |
127 | ||
128 | // Tailor this to return own connection. | |
129 | virtual wxConnectionBase *OnMakeConnection(); | |
130 | }; | |
131 | ||
132 | #endif // ipcsock.h |