home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_ipc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  5.7 KB  |  209 lines

  1. /*
  2.  * File:     wx_ipc.h
  3.  * Purpose:  Interprocess communication implementation. Uses DDE under
  4.  *           Windows, sockets to implement DDE subset under UNIX
  5.  *
  6.  *                       wxWindows 1.40
  7.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  8.  *                   The University of Edinburgh
  9.  *
  10.  *                     Author: Julian Smart
  11.  *                       Date: 18-4-93
  12.  *
  13.  * Permission to use, copy, modify, and distribute this software and its
  14.  * documentation for any purpose is hereby granted without fee, provided
  15.  * that the above copyright notice, author statement and this permission
  16.  * notice appear in all copies of this software and related documentation.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  19.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  20.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  21.  *
  22.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  23.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  24.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  25.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  26.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  27.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  */
  29.  
  30. #ifndef wx_ipch
  31. #define wx_ipch
  32.  
  33. #include "common.h"
  34. #include "wx_frame.h"
  35. #include "wx_utils.h"
  36.  
  37. #ifdef wx_msw
  38. #include <ddeml.h>
  39. #endif
  40.  
  41. // Message codes
  42. #define wxEXECUTE        1
  43. #define wxREQUEST        2
  44. #define wxPOKE           3
  45. #define wxADVISE_START   4
  46. #define wxADVISE_REQUEST 5
  47. #define wxADVISE         6
  48. #define wxADVISE_STOP    7
  49. #define wxREQUEST_REPLY  8
  50. #define wxFAIL           9
  51. #define wxCONNECT        10
  52. #define wxDISCONNECT     11
  53.  
  54. // Error codes
  55. #define wxGENERAL          2
  56. #define wxBAD_SERVICE_NAME 3
  57.  
  58. // Clipboard formats - only ASCII text so far
  59. #ifdef wx_msw
  60. #define wxCF_TEXT CF_TEXT
  61. #endif
  62.  
  63. #ifdef wx_x
  64. #define wxCF_TEXT 1
  65. #endif
  66.  
  67. /*
  68.  * Mini-DDE implementation
  69.  
  70.    Most transactions involve a topic name and an item name (choose these
  71.    as befits your application).
  72.  
  73.    A client can:
  74.  
  75.    - ask the server to execute commands (data) associated with a topic
  76.    - request data from server by topic and item
  77.    - poke data into the server
  78.    - ask the server to start an advice loop on topic/item
  79.    - ask the server to stop an advice loop
  80.  
  81.    A server can:
  82.  
  83.    - respond to execute, request, poke and advice start/stop
  84.    - send advise data to client
  85.  
  86.    Note that this limits the server in the ways it can send data to the
  87.    client, i.e. it can't send unsolicited information.
  88.  *
  89.  */
  90.  
  91. // Always call before starting IPC
  92. void wxIPCInitialize(void);
  93.  
  94. class wxIPCObject;
  95.  
  96. class wxServer;
  97. class wxClient;
  98. class wxConnection: public wxObject
  99. {
  100.  public:
  101.   char *buf_ptr;
  102.   char *topic_name;
  103.   int buf_size;
  104.   wxServer *server;
  105.   wxClient *client;
  106. #ifdef wx_motif
  107.   unsigned long xtInputId;
  108. #endif
  109. #ifdef wx_x
  110.   int input_fd;
  111.   int output_fd;
  112. #endif
  113. #ifdef wx_msw
  114.   HCONV hConv;
  115.   char *sending_data;
  116.   int data_size;
  117.   int data_type;
  118. #endif
  119.   wxConnection(char *buffer, int size);
  120.   wxConnection(void);
  121.   ~wxConnection(void);
  122.  
  123.   // Callbacks to SERVER - override at will
  124.   virtual Bool OnExecute(char *topic, char *data, int size, int format);
  125.   virtual char *OnRequest(char *topic, char *item, int *size, int format);
  126.   virtual Bool OnPoke(char *topic, char *item, char *data, int size, int format);
  127.   virtual Bool OnStartAdvise(char *topic, char *item);
  128.   virtual Bool OnStopAdvise(char *topic, char *item);
  129.  
  130.   // Callbacks to CLIENT - override at will
  131.   virtual Bool OnAdvise(char *topic, char *item, char *data, int size, int format);
  132.  
  133.   // Callbacks to BOTH
  134.  
  135.   // Default behaviour is to delete connection and return TRUE
  136.   virtual Bool OnDisconnect(void);
  137.  
  138.   // Calls that CLIENT can make
  139.   virtual Bool Execute(char *data, int size = -1, int format = wxCF_TEXT);
  140.   virtual char *Request(char *item, int *size = NULL, int format = wxCF_TEXT);
  141.   virtual Bool Poke(char *item, char *data, int size = -1, int format = wxCF_TEXT);
  142.   virtual Bool StartAdvise(char *item);
  143.   virtual Bool StopAdvise(char *item);
  144.  
  145.   // Calls that SERVER can make
  146.   virtual Bool Advise(char *item, char *data, int size = -1, int format = wxCF_TEXT);
  147.  
  148.   // Calls that both can make
  149.   Bool Disconnect(void);
  150.   void Notify(Bool notify);  // Internal use only
  151. };
  152.  
  153. class wxIPCObject: public wxObject
  154. {
  155.  public:
  156.   int lastError;
  157.   char *service_name; // Server only
  158.   wxList connections;
  159.   wxIPCObject(void);
  160.   ~wxIPCObject(void);
  161.  
  162. #ifdef wx_msw
  163.   // Find/delete wxConnection corresponding to the HCONV
  164.   wxConnection *FindConnection(HCONV conv);
  165.   Bool DeleteConnection(HCONV conv);
  166. #endif
  167. };
  168.  
  169. class wxServer: public wxIPCObject
  170. {
  171.  public:
  172.  
  173. #ifdef wx_x
  174.   int server_socket;
  175. #endif
  176.   wxServer(void);
  177.   ~wxServer(void);
  178.   Bool Create(char *server_name); // Returns FALSE if can't create server (e.g. port
  179.                                   // number is already in use)
  180.   virtual wxConnection *OnAcceptConnection(char *topic);
  181. };
  182.  
  183. class wxClient: public wxIPCObject
  184. {
  185.  public:
  186. #ifdef wx_x
  187.   int client_socket;
  188. #endif
  189.   wxClient(void);
  190.   ~wxClient(void);
  191.   Bool ValidHost(char *host);
  192.   virtual wxConnection *MakeConnection(char *host, char *server, char *topic);
  193.                                                 // Call this to make a connection.
  194.                                                 // Returns NULL if cannot.
  195.   virtual wxConnection *OnMakeConnection(void); // Tailor this to return own connection.
  196. };
  197.  
  198. class wxChild: public wxObject
  199. {
  200.  public:
  201.   int the_pid;
  202.   wxChild(void);
  203.   Bool Create(char *command, char *argv[]);
  204.   virtual wxConnection *OnSpawn(int pid);
  205.   virtual void OnDeath(void);
  206. };
  207.  
  208. #endif // wx_ipc.h
  209.