dde.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dde.h
  3. // Purpose: interface of wxDDEConnection
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDDEConnection
  9. A wxDDEConnection object represents the connection between a client and a
  10. server. It can be created by making a connection using a wxDDEClient
  11. object, or by the acceptance of a connection by a wxDDEServer object.
  12. The bulk of a DDE (Dynamic Data Exchange) conversation is controlled by calling
  13. members in a wxDDEConnection object or by overriding its members.
  14. An application should normally derive a new connection class from
  15. wxDDEConnection, in order to override the communication event handlers to
  16. do something interesting.
  17. This DDE-based implementation is available on Windows only, but a
  18. platform-independent, socket-based version of this API is available using
  19. wxTCPConnection.
  20. @library{wxbase}
  21. @category{ipc}
  22. @onlyfor{wxmsw}
  23. @see wxConnectionBase, wxDDEClient, wxDDEServer, @ref overview_ipc
  24. */
  25. class wxDDEConnection : public wxConnectionBase
  26. {
  27. public:
  28. /**
  29. Constructs a connection object. If no user-defined connection object is
  30. to be derived from wxDDEConnection, then the constructor should not be
  31. called directly, since the default connection object will be provided
  32. on requesting (or accepting) a connection. However, if the user defines
  33. his or her own derived connection object, the
  34. wxDDEServer::OnAcceptConnection() and/or
  35. wxDDEClient::OnMakeConnection() members should be replaced by functions
  36. which construct the new connection object.
  37. A default buffer will be associated with this connection.
  38. */
  39. wxDDEConnection();
  40. /**
  41. Constructs a connection object. If no user-defined connection object is
  42. to be derived from wxDDEConnection, then the constructor should not be
  43. called directly, since the default connection object will be provided
  44. on requesting (or accepting) a connection. However, if the user defines
  45. his or her own derived connection object, the
  46. wxDDEServer::OnAcceptConnection() and/or
  47. wxDDEClient::OnMakeConnection() members should be replaced by functions
  48. which construct the new connection object.
  49. @param buffer
  50. Buffer for this connection object to use in transactions.
  51. @param size
  52. Size of the buffer given.
  53. */
  54. wxDDEConnection(void* buffer, size_t size);
  55. //@{
  56. /**
  57. Called by the server application to advise the client of a change in
  58. the data associated with the given item. Causes the client connection's
  59. OnAdvise() member to be called.
  60. @return @true if successful.
  61. */
  62. bool Advise(const wxString& item, const void* data, size_t size,
  63. wxIPCFormat format = wxIPC_PRIVATE);
  64. bool Advise(const wxString& item, const char* data);
  65. bool Advise(const wxString& item, const wchar_t* data);
  66. bool Advise(const wxString& item, const wxString data);
  67. //@}
  68. /**
  69. Called by the client or server application to disconnect from the other
  70. program; it causes the OnDisconnect() message to be sent to the
  71. corresponding connection object in the other program. The default
  72. behaviour of OnDisconnect() is to delete the connection, but the
  73. calling application must explicitly delete its side of the connection
  74. having called Disconnect().
  75. @return @true if successful.
  76. */
  77. bool Disconnect();
  78. //@{
  79. /**
  80. Called by the client application to execute a command on the server.
  81. Can also be used to transfer arbitrary data to the server (similar to
  82. Poke() in that respect). Causes the server connection's OnExecute()
  83. member to be called.
  84. @return @true if successful.
  85. */
  86. bool Execute(const void* data, size_t size,
  87. wxIPCFormat format = wxIPC_PRIVATE);
  88. bool Execute(const char* data);
  89. bool Execute(const wchar_t* data);
  90. bool Execute(const wxString data);
  91. //@}
  92. /**
  93. Message sent to the client application when the server notifies it of a
  94. change in the data associated with the given item.
  95. */
  96. virtual bool OnAdvise(const wxString& topic, const wxString& item,
  97. const void* data, size_t size, wxIPCFormat format);
  98. /**
  99. Message sent to the client or server application when the other
  100. application notifies it to delete the connection. Default behaviour is
  101. to delete the connection object.
  102. */
  103. virtual bool OnDisconnect();
  104. /**
  105. Message sent to the server application when the client notifies it to
  106. execute the given data. Note that there is no item associated with
  107. this message.
  108. */
  109. virtual bool OnExecute(const wxString& topic, const void* data,
  110. size_t size, wxIPCFormat format);
  111. /**
  112. Message sent to the server application when the client notifies it to
  113. accept the given data.
  114. */
  115. virtual bool OnPoke(const wxString& topic, const wxString& item,
  116. const void* data, size_t size, wxIPCFormat format);
  117. /**
  118. Message sent to the server application when the client calls Request().
  119. The server should respond by returning a character string from
  120. OnRequest(), or @NULL to indicate no data.
  121. */
  122. virtual const void* OnRequest(const wxString& topic,
  123. const wxString& item, size_t* size,
  124. wxIPCFormat format);
  125. /**
  126. Message sent to the server application by the client, when the client
  127. wishes to start an "advise loop" for the given topic and item. The
  128. server can refuse to participate by returning @false.
  129. */
  130. virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
  131. /**
  132. Message sent to the server application by the client, when the client
  133. wishes to stop an "advise loop" for the given topic and item. The
  134. server can refuse to stop the advise loop by returning @false, although
  135. this doesn't have much meaning in practice.
  136. */
  137. virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
  138. //@{
  139. /**
  140. Called by the client application to poke data into the server. Can be
  141. used to transfer arbitrary data to the server. Causes the server
  142. connection's OnPoke() member to be called.
  143. @return @true if successful.
  144. */
  145. bool Poke(const wxString& item, const void* data, size_t size,
  146. wxIPCFormat format = wxIPC_PRIVATE);
  147. bool Poke(const wxString& item, const char* data);
  148. bool Poke(const wxString& item, const wchar_t* data);
  149. bool Poke(const wxString& item, const wxString data);
  150. //@}
  151. /**
  152. Called by the client application to request data from the server.
  153. Causes the server connection's OnRequest() member to be called.
  154. @return A character string (actually a pointer to the connection's
  155. buffer) if successful, @NULL otherwise.
  156. */
  157. const void* Request(const wxString& item, size_t* size,
  158. wxIPCFormat format = wxIPC_TEXT);
  159. /**
  160. Called by the client application to ask if an advise loop can be
  161. started with the server. Causes the server connection's OnStartAdvise()
  162. member to be called.
  163. @return @true if the server okays it, @false otherwise.
  164. */
  165. bool StartAdvise(const wxString& item);
  166. /**
  167. Called by the client application to ask if an advise loop can be
  168. stopped. Causes the server connection's OnStopAdvise() member to be
  169. called.
  170. @return @true if the server okays it, @false otherwise.
  171. */
  172. bool StopAdvise(const wxString& item);
  173. };
  174. /**
  175. @class wxDDEClient
  176. A wxDDEClient object represents the client part of a client-server DDE
  177. (Dynamic Data Exchange) conversation.
  178. To create a client which can communicate with a suitable server, you need
  179. to derive a class from wxDDEConnection and another from wxDDEClient. The
  180. custom wxDDEConnection class will intercept communications in a
  181. "conversation" with a server, and the custom wxDDEServer is required so
  182. that a user-overridden OnMakeConnection() member can return a
  183. wxDDEConnection of the required class, when a connection is made.
  184. This DDE-based implementation is available on Windows only, but a
  185. platform-independent, socket-based version of this API is available using
  186. wxTCPClient.
  187. @library{wxbase}
  188. @category{ipc}
  189. @onlyfor{wxmsw}
  190. @see wxDDEServer, wxDDEConnection, @ref overview_ipc
  191. */
  192. class wxDDEClient : public wxObject
  193. {
  194. public:
  195. /**
  196. Constructs a client object.
  197. */
  198. wxDDEClient();
  199. /**
  200. Tries to make a connection with a server specified by the host (machine
  201. name under UNIX, ignored under Windows), service name (must contain an
  202. integer port number under UNIX), and topic string. If the server allows
  203. a connection, a wxDDEConnection object will be returned.
  204. The type of wxDDEConnection returned can be altered by overriding the
  205. OnMakeConnection() member to return your own derived connection object.
  206. */
  207. wxConnectionBase* MakeConnection(const wxString& host,
  208. const wxString& service,
  209. const wxString& topic);
  210. /**
  211. The type of wxDDEConnection returned from a MakeConnection() call can
  212. be altered by deriving the OnMakeConnection() member to return your own
  213. derived connection object. By default, a wxDDEConnection object is
  214. returned.
  215. The advantage of deriving your own connection class is that it will
  216. enable you to intercept messages initiated by the server, such as
  217. wxDDEConnection::OnAdvise(). You may also want to store
  218. application-specific data in instances of the new class.
  219. */
  220. wxConnectionBase* OnMakeConnection();
  221. /**
  222. Returns @true if this is a valid host name, @false otherwise. This
  223. always returns @true under MS Windows.
  224. */
  225. bool ValidHost(const wxString& host);
  226. };
  227. /**
  228. @class wxDDEServer
  229. A wxDDEServer object represents the server part of a client-server DDE
  230. (Dynamic Data Exchange) conversation.
  231. This DDE-based implementation is available on Windows only, but a
  232. platform-independent, socket-based version of this API is available using
  233. wxTCPServer.
  234. @library{wxbase}
  235. @category{ipc}
  236. @onlyfor{wxmsw}
  237. @see wxDDEClient, wxDDEConnection, @ref overview_ipc
  238. */
  239. class wxDDEServer
  240. {
  241. public:
  242. /**
  243. Constructs a server object.
  244. */
  245. wxDDEServer();
  246. /**
  247. Registers the server using the given service name. Under UNIX, the
  248. string must contain an integer id which is used as an Internet port
  249. number. @false is returned if the call failed (for example, if the port
  250. number is already in use).
  251. */
  252. bool Create(const wxString& service);
  253. /**
  254. When a client calls wxDDEClient::MakeConnection(), the server receives
  255. the message and this member is called. The application should derive a
  256. member to intercept this message and return a connection object of
  257. either the standard wxDDEConnection type, or of a user-derived type.
  258. If the @a topic is "STDIO", the application may wish to refuse the
  259. connection. Under UNIX, when a server is created the
  260. OnAcceptConnection() message is always sent for standard input and
  261. output, but in the context of DDE messages it doesn't make a lot of
  262. sense.
  263. */
  264. virtual wxConnectionBase* OnAcceptConnection(const wxString& topic);
  265. };
  266. // ============================================================================
  267. // Global functions/macros
  268. // ============================================================================
  269. /** @addtogroup group_funcmacro_misc */
  270. //@{
  271. /**
  272. Called when wxWidgets exits, to clean up the DDE system. This no longer
  273. needs to be called by the application.
  274. @see wxDDEInitialize()
  275. @header{wx/dde.h}
  276. */
  277. void wxDDECleanUp();
  278. /**
  279. Initializes the DDE system. May be called multiple times without harm.
  280. This no longer needs to be called by the application: it will be called by
  281. wxWidgets if necessary.
  282. @see wxDDEServer, wxDDEClient, wxDDEConnection, wxDDECleanUp()
  283. @header{wx/dde.h}
  284. */
  285. void wxDDEInitialize();
  286. //@}